[Greasemonkey] Help with Replace

Randy Reed rwreed at linkline.com
Wed Aug 3 17:26:54 EDT 2005


Hi All,
I'm trying to write a script that changes one href to another and I am 
encountering a frustrating error. I use a xpath node to get the href, 
copy it to string and then try to modify it with replace. However, when 
I run it I get the message "thisLink has no properties". When I type the 
same commands in the javascript shell, it works fine. I'm running 0.5 of 
greasemonkey and 1.0.6 of firefox. All help is appreciated, code is below.

Thanks
Randy

// ==UserScript==
// @name ChangeHref
// @description script to reroute downloads through the proper port
// @include https://schoolconnect.*
// ==/UserScript==


function xpath(query) {
     return document.evaluate(query, document, null,
         XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
}

var allLinks;
var newLink;
var thisLink;

allLinks=xpath('//a[@href]')

thisLink=allLinks.iterateNext();
while (thisLink) {
	
	thisLink=allLinks.href;
	GM_log('current link =' + thisLink);
	newLink=thisLink.replace(/^https:/,'http');
	GM_log('new link = '+ newLink);
	thisLink=allLinks.iterateNext();
}


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.9/62 - Release Date: 8/2/2005



More information about the Greasemonkey mailing list