views:

31

answers:

0

Each time I click a link if this is loaded into my Greasemonkey script the page grows on links that would be in the same domain with the greasemonkey target instead of the page navigating to the link target.

var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

This is happening in Firefox 3.5.6, on page http://apps.facebook.com/castle%5Fage/index.php with GreaseMonkey 0.8.20091209.4

the entire script I'm trying to run is very simple:

var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

 //Check if jQuery's loaded
function GM_wait() {
  if (typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait, 200); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();

 // All your GM code must be inside this function
function letsJQuery() {

var exp = $('a[href="http://apps.facebook.com/castle_age/quests.php"] strong');
var expText = exp.text();
var index=expText.indexOf("/");
var currentExperience=parseInt(expText.substring(0,index));
var levelUpExp=parseInt( expText.substring(index+1));
exp.text(exp.text() + " -" + (levelUpExp - currentExperience));
//document.getElementsByTagName('head')[0].removeChild(GM_JQ); // didn't help

}