I am trying to change a variable on a page using usercript. I know there is a variable in the source code
var smilies = false;
In theory, I would have to change it like this:
unsafeWindow.smilies = true;
But that will not work. When I try to warn or register a variable on the console without hijacking, I get that it is undefined.
alert(unsafeWindow.smilies); // undefined !!!
EDIT: I use Chrome if it changes anything ...
http://code.google.com/chrome/extensions/content_scripts.html says:
Content scripts are executed in a special environment called Isolated World. They have access to the DOM of the page to which they are entered, but not to any JavaScript variables or functions created by this page. It looks at each script content as if there was no other JavaScript running on the page on which it is running.
This is about Chrome extensions, but I think this is also a story with Usercripts too?
Thanks, Rob W. Therefore, a working code for people who need it:
var scriptText = "smilies = true;"; var rwscript = document.createElement("script"); rwscript.type = "text/javascript"; rwscript.textContent = scriptText; document.documentElement.appendChild(rwscript); rwscript.parentNode.removeChild(rwscript);
source share