-1

How do I change the var values in the code. I have already tried but with no success

<script type="text/javascript" charset="utf-8">
var i9 = '071c57';
var plusActive = false;
</script>

to this

<script type="text/javascript" charset="utf-8">
var i9 = '071c57';
var plusActive = true;
</script>

I tried using the following code but was unsuccessful

// ==UserScript==
// @name          PLUS 
// @namespace     http://userstyles.org
// @description   PLUS 
// @author        md
// @homepage      http://userstyles.org/styles/43691
// @include       http://azet.sk/*
// @include       https://azet.sk/*
// @include       http://-azet.sk/*
// @include       https://-azet.sk/*
// @include       http://*.azet.sk/*
// @include       https://*.azet.sk/*
// @include       http://*-azet.sk/*
// @include       https://*-azet.sk/*
// ==/UserScript==

myInfo
{
"plusActive":true;
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • You don't need brackets in your code posting. – matthewbauer Jun 27 '13 at 23:46
  • possible duplicate of [Javascript variable scope in a JS URI, or how to write page-scope objects?](http://stackoverflow.com/questions/13617768/javascript-variable-scope-in-a-js-uri-or-how-to-write-page-scope-objects) and a few others like: http://stackoverflow.com/questions/5722075/how-can-i-change-a-javascript-variable-using-greasemonkey . – Brock Adams Jun 28 '13 at 00:05

2 Answers2

0

If I understand you correctly, this should be an easy fix.

You can simply overwrite the variable:

So replace

myInfo
{
"plusActive":true;
}

with

plusActive = true;

You shouldn't need to run any sort of a function, assuming the variable in question is not read until the page is loaded (which is far from certain).

matthewbauer
  • 4,314
  • 1
  • 17
  • 22
0

Since plusActive is global to the target-page scope (which is not the script scope)...

For Firefox only, this will work:

// ==UserScript==
// @name          PLUS 
// @namespace     http://userstyles.org
// @description   PLUS 
// @author        md
// @homepage      http://userstyles.org/styles/43691
// @include       http://azet.sk/*
// @include       https://azet.sk/*
// @include       http://-azet.sk/*
// @include       https://-azet.sk/*
// @include       http://*.azet.sk/*
// @include       https://*.azet.sk/*
// @include       http://*-azet.sk/*
// @include       https://*-azet.sk/*
// @grant         none
// ==/UserScript==

window.plusActive = true;

Where the @grant none is very important to ensure always expected operation, for this script.


For a cross-browser approach, use script injection:

// ==UserScript==
// @name          PLUS 
// @namespace     http://userstyles.org
// @description   PLUS 
// @author        md
// @homepage      http://userstyles.org/styles/43691
// @include       http://azet.sk/*
// @include       https://azet.sk/*
// @include       http://-azet.sk/*
// @include       https://-azet.sk/*
// @include       http://*.azet.sk/*
// @include       https://*.azet.sk/*
// @include       http://*-azet.sk/*
// @include       https://*-azet.sk/*
// @grant         GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

addJS_Node ('plusActive = true;');

function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
    var D                                   = document;
    var scriptNode                          = D.createElement ('script');
    if (runOnLoad) {
        scriptNode.addEventListener ("load", runOnLoad, false);
    }
    scriptNode.type                         = "text/javascript";
    if (text)       scriptNode.textContent  = text;
    if (s_URL)      scriptNode.src          = s_URL;
    if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';

    var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    targ.appendChild (scriptNode);
}
Brock Adams
  • 90,639
  • 22
  • 233
  • 295