I'm writing a JavaScript for an open source browser available for Android to replace the text in the body tag of the pages loaded into the browser with some different text.
This should be worked in away that once a page get loaded into the browser, this JavaScript executes & the replacements take place & finally the page with replaced text is visible in the browser.
This is the replacing part of the code:
var textnodes, node, i;
textnodes = document.evaluate("//body//text()[not(ancestor::script) and not(ancestor::style)]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
replace();
function replace() {
for (i = 0; i < textnodes.snapshotLength; i++) {
node = textnodes.snapshotItem(i);
text = node.data;
text = text.replace(/\'/g, "♥");
//The rest of the replacements
node.data = text;
}
}
However document.evaluate
seems to be not working. Can anyone help me to correct this code or any suggestions to do this replacing body text task in any other way?
Thanks!