1

My Greasemonkey script works exactly as I want it to by but it somehow blocks javascripts from the website itself. They just don't work anymore.

I use the very useful waitForKeyElements() to start some actions after a certain container has been loaded.

What is disturbing the other scripts?

// @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant           none
// ==/UserScript==

var newText = 'changed';

// changes after loading .containerid
waitForKeyElements (
    "#containerid", renameTop
);

function renameTop() {
    var searchlinkTop = document.getElementById('containerid'); 
        searchlinkTop.innerHTML = newText;  
}

// some normal changes

function waitForKeyElements (
// ... the script's content
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
A2i_
  • 398
  • 3
  • 13

1 Answers1

1

See "jQuery in Greasemonkey 1.0 conflicts...".
The problem is the @grant none. This is a very poorly though-out "feature" of Greasemonkey that guarantees that you will have conflicts and errors. You're just lucky that this time it was so obvious and immediate.

Change @grant none to @grant GM_addStyle. This will restore the sandbox and remove the conflict.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Wow, thank you! It worked for this script. – A2i_ Feb 10 '14 at 13:44
  • Wow, thank you! It worked perfectly for my little script. But I've another bigger script that also suffers from this problem for months. Of course I just tried your advice there too, but it breaks the whole script...? Are there any exceptions to this approach? The bigger script uses e.g. // @require http://github.com/sizzlemctwizzle/GM_config/raw/master/gm_config.js GM_xmlhttpRequest({method: "GET", url: 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', onload: ...;}}); GM_registerMenuCommand(...); window.addEventListener ("load",Gm_main,false); $('div.twitter').remove(); – A2i_ Feb 10 '14 at 13:54
  • That second script uses several `GM_` functions. You need to add a `@grant` directive for each `GM_` function. Other than that, open a new question for the second script (after check-marking this answer as the answer). – Brock Adams Feb 10 '14 at 20:03
  • Thank you! A added all grants to the second script but it still didn't work. Turned out it only didn't work when I tried to modify the content of the postloaded container. No idea why, but I workarounded it... – A2i_ Feb 17 '14 at 14:10