Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A more secure alternative to using <code>unsafeWindow</code> is to inject code into the document. The code that you inject will run in the same context as the page code, so it will have direct access to all of the variables there. But it will not have access to variables or functions in other parts of your user script code.</p> <p>Another benefit of injecting code is that a user script written that way will work in Chrome as well as in Firefox. Chrome does not support <code>unsafeWindow</code> at all.</p> <p>My favorite way to inject code is to write a function, then to use this reusable code to get back the source code for the function:</p> <pre><code>// Inject function so that in will run in the same context as other // scripts on the page. function inject(func) { var source = func.toString(); var script = document.createElement('script'); // Put parenthesis after source so that it will be invoked. script.innerHTML = "("+ source +")()"; document.body.appendChild(script); } </code></pre> <p>To toggle <code>btnSubmit</code> you could write a script like this:</p> <pre><code>function enableBtnSubmit() { document.licenseform.btnSubmit.disabled = false; document.licenseform.btnSubmit.value = " 我同意 "; // Or just invoke Timer() } function inject(func) { var source = func.toString(); var script = document.createElement('script'); script.innerHTML = "("+ source +")()"; document.body.appendChild(script); } inject(enableBtnSubmit); </code></pre> <p>Remember that when you use the serialized form of a function in this way normal closure scope will not work. The function that you inject will not have access to variables in your script unless they are defined inside that function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload