Search code examples
javascriptvariablesfirefoxgreasemonkey

Changing a javascript variable with greasemonkey at running time


i have a page that has a .js script inside, in the page its

    <script>
        Client.includeJS(
            'js/scratchticket.js'
        );
    </script>

in this scratchticket.js

is following code

 $(document).ready(function() {
        ...
        var xxx = 100;    
        ...
  });

so i testet various codes in greasemonkey, but i cannot edit this variable that is it e.g. 200

i testet to block the scratchticket.js with adblock an paste the whole code into greasemonke script and change the var but it is not working, i dont know why the page says loading... at the time when it should do the code.

any idea how to change the variable in a other way?


Solution

  • The problem is actually that @Quasimodo's clone answer above is absolutely wrong about when it executes, and it is the opposite.

    To quote the wiki he cites:

    document-end is the standard behavior that Greasemonkey has always had (see DOMContentLoaded). This is the default if no value is provided.

    So, your issue is probably the common one for those starting out with userscripts, in that your script is executing too late (end) and you simply need to add this directive at the top:

    // @run-at        document-start
    

    Try that and see if it helps!