Forum Moderators: open
<div class="it1"><img src="http://www.example.com/image 1.png">
<div class="it2">init~/c1/1gfh6/sdaimage2.png </div>
// ==UserScript==
// @name Hello World
// @namespace [oreilly.com...]
// @description example script to alert "Hello world!" on every page
// @include http://example.com/*
// ==/UserScript==
//get all images
var allImgs, thisImg;
var allImgs = document.evaluate('//img[@src]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
//step through each image
//-------------------------------------------------------------------------------------------
for (var i=1;i <allImgs.snapshotLength;i++) {
var thisImg = allImgs.snapshotItem(i);
var src = thisImg.src;
var srcMatch = src.match('^http://www.example.com/image 1.png');
if (srcMatch != null) {
thisImg.src = 'http://example.com/2009/10/had_frame.png'
}
}
[edited by: Fotiman at 6:50 pm (utc) on Feb 16, 2010]
[edit reason] Examplified URLs [/edit]
if (src == 'http://www.example.com/image 1.pnp') {
thisImg.src = 'http://example.com/2009/10/had_frame.png';
}
[edited by: Fotiman at 6:51 pm (utc) on Feb 16, 2010]
[edit reason] Examplified URLs [/edit]
I do this:
var myArray = [];
Then while inside the loop:
myArray[i] = 'http://example.com:81' + mySplitResult;
And after the loop:
alert(myArray[0]);
Result = Undefined
// ==UserScript==
// @name Hello World
// @namespace http://www.oreilly.com/catalog/greasemonkeyhacks/
// @description example script to alert "Hello world!" on every page
// @include http://example.com/*
// ==/UserScript==
//get all DIVs of the snap_preview class
var myArray = [];
var thisDiv, msg = '';
var allDivs = document.evaluate("//div[@class='it1']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var textNodes = document.evaluate("//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i=0; i<textNodes.snapshotLength; i++) {
var node = textNodes.snapshotItem(i);
var src = node.data;
var srcMatch = src.match('^init'); //Search for init
if (srcMatch != null) {
// Remove Init~
var myOldString = node.data;
var myNewString = myOldString.replace("init~", '');
// Split by ~ & keep only URL
var mySplitResult = myNewString.split("~");
mySplitResult = mySplitResult[0]
//Put URL into an array
myArray[i] = 'http://example.com:81' + mySplitResult;
msg = msg + 'http://example.com:81' + mySplitResult + "\n";
}
}
alert(msg);
alert(myArray); // Show the array containig all URLS
alert(myArray[0]);
[edited by: Fotiman at 6:53 pm (utc) on Feb 16, 2010]
[edit reason] Examplified URLs [/edit]
var textNodes = document.evaluate("//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);