I'm a student who isn't in the computer sciences or programming but I've been looking for a script for my parents who are foreign and don't understand internet lingo.
I've found the script below on userscripts.org (all credit to the writer) and it works like a charm. However, my parents are too stubborn to switch from IE9 to either Chrome or Firefox so I downloaded IE7Pro and installed the script there.
The problem here is that the userscript installed on IE9 seems to not work at all, and I'm trying to find out why. Are there elementary differences in javascript for Chrome/Firefox vs Internet Explorer?
How can I go about fixing these to make it work in IE? I've only taken an introductory C programming class and have little experience in this field, so it would be great if someone could explain it to me simply.
Here is the code for reference, if anyone can point out where/why it doesn't work, it would be great help. It's not too long and it would save me countless hours of learning something I don't really need to learn. Thank you so much.
var words = {
///////////////////////////////////////////////////////
// Syntax: 'Search word' : 'Replace word',
"your a": "you're a",
"im*o": "in my honest opinion",
///////////////////////////////////////////////////////
"": ""
};
//////////////////////////////////////////////////////////////////////////////
// This is where the real code is
// Don't edit below this
//////////////////////////////////////////////////////////////////////////////
// prepareRegex by JoeSimmons
// Used to take a string and ready it for use in new RegExp()
String.prototype.prepareRegex = function () {
return this.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, "\\$1");
};
// Function to decide whether a parent tag will have its text replaced or not
function isOkTag (tag) {
return (
new RegExp (
"(," + tag + ",) | (," + tag + "$)",
"g"
).test (",pre,blockquote,code,input,button,textarea")
) == false;
}
// Convert the "words" JSON object to an Array
var regexs = new Array(),
replacements = new Array();
for (var word in words) {
if (word != "") {
regexs.push (new RegExp (word.prepareRegex ().replace (/(\\)?\*/g, function (e) {
return ((e !== "\\*") ? "[^ ]*" : "*");
} ), "gi"));
replacements.push (words[word]);
}
}
// Do the replacement
var texts = document.evaluate (
".//text()[normalize-space(.)!='']", document.body, null, 6, null
),
text = "",
len = regexs.length;
for (var i = 0, l = texts.snapshotLength; (this_text = texts.snapshotItem(i)); i++) {
if (isOkTag (this_text.parentNode.tagName) && (text = this_text.textContent) ) {
for (var x = 0; x < len; x++) {
text = this_text.textContent = text.replace(regexs[x], replacements[x]);
}
}
}