The code is:
(function(window, undefined ) { var w; if (typeof unsafeWindow != undefined){ w = unsafeWindow } else { w = window; } if (w.self != w.top){ return; } if (/https?:\/\/(www\.)?linux.org.ru/.test(w.location.href)){ //Содержание } })(window); It is necessary to install the functions that will be run from html, which will be added by the script, as well as from each other.
If you push these functions into the content or you specify it on the main level in the script, the browser (I check it in the chrome only) doesn’t see them at startup.
Naturally, I usually write:
function foo (a, b) { //Содержание } How to set functions in userscripts?
upd. Decision:
function contentEval(source) { source = '(' + source + ')();' var script = document.createElement('script'); script.setAttribute("type", "application/javascript"); script.textContent = source; document.body.appendChild(script); document.body.removeChild(script); } contentEval (function() { window.function1 = function(a,b){ //... }; window.function2 = function(c,d){ //... }; });