dave_is_sexy
12-29-2005, 04:22 AM
I'm trying to write a script for Firefox's Greacemonkey User Javascript extension. I want the script to check a page for the text:
8%><a href="javascript:ViewProfile('SOMETHING1','SOMETHING2',SOMETHING3);">
and replace each instance with
8%><a href="http://www.website.com/SOMETHING2" target=_blank>
Where SOMETHING* are variables which change in each occurance.
The 8% is important as it is the element common to the table column cells I want to alter.
I tried this, it's incomplete but doesn't do anything at all.
(function() {
var scriptBefore = javascript:ViewMode('SOMETHING1','
var scriptAfter = 'http://www.website.com/'
var xpath = "//a[contains(@href, scriptBefore)]";
var res = document.evaluate(xpath, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var i, link;
for (i = 0; link = res.snapshotItem(i); i++) {
link.href = link.href.replace(scriptBefore, scriptAfter);
}
})();
By my understanding that script should've generated the url:
8%><a href="http://www.website.com/SOMETHING2',SOMETHING3);">
And I've gathered that this is helpful for grabbing SOMETHING2 but don't know how it fits in with things:
obj.href.split("'")[2]
obj.href = 'http:.....' + obj.href.split("'")[2]
-----------------------------------------------------------------------
Another solution would be to replace the function ViewMode in the source with the function ViewMode2.
I could then specify function ViewMode2:
function ViewMode2(fUser,tUser,sId)
{
window.open('http://www.website.com/'+tUser,'status=no,scrollbars=yes,resizable=yes');
}
8%><a href="javascript:ViewProfile('SOMETHING1','SOMETHING2',SOMETHING3);">
and replace each instance with
8%><a href="http://www.website.com/SOMETHING2" target=_blank>
Where SOMETHING* are variables which change in each occurance.
The 8% is important as it is the element common to the table column cells I want to alter.
I tried this, it's incomplete but doesn't do anything at all.
(function() {
var scriptBefore = javascript:ViewMode('SOMETHING1','
var scriptAfter = 'http://www.website.com/'
var xpath = "//a[contains(@href, scriptBefore)]";
var res = document.evaluate(xpath, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var i, link;
for (i = 0; link = res.snapshotItem(i); i++) {
link.href = link.href.replace(scriptBefore, scriptAfter);
}
})();
By my understanding that script should've generated the url:
8%><a href="http://www.website.com/SOMETHING2',SOMETHING3);">
And I've gathered that this is helpful for grabbing SOMETHING2 but don't know how it fits in with things:
obj.href.split("'")[2]
obj.href = 'http:.....' + obj.href.split("'")[2]
-----------------------------------------------------------------------
Another solution would be to replace the function ViewMode in the source with the function ViewMode2.
I could then specify function ViewMode2:
function ViewMode2(fUser,tUser,sId)
{
window.open('http://www.website.com/'+tUser,'status=no,scrollbars=yes,resizable=yes');
}