0

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?

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

Comments

0

You need to provide more information and code in order to get appropriate answers. It is important to know when the userscript runs and if there are any grants.

If you just want to change JS code setting an initial value, consider listening to the beforescriptexecute event. On firing you have first to indentify if the event target is the script you are looking for. Then you can search and replace the desired JavaScript line. You have to cancel the execution of the original script and insert the modified code within a new <script> tag into the DOM, since you cannot manipulate loaded scripts directly.

2 Comments

the code is inside an frame what opens when i click a link.
GM scripts default to @run-at document-start (see official site wiki.greasespot.net/Metadata_block , currently apparently down). This is before any execution of the site, so you can use the described method above. GM also defaults to execute a userscript in frames as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.