-1

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]);
        }
    }
}
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197

2 Answers2

0

document.evaluate is not supported on IE. No idea what the script does, so it might be easier to install a real browser for your folks.

Maybe jQuery could help you.

Community
  • 1
  • 1
asgoth
  • 35,552
  • 12
  • 89
  • 98
  • Ok, makes sense. The point of the script was to search web pages for certain text and replaces it displaying what you specify. I'll search around I guess to find an IE solution that achieves this, they really don't want to switch browsers. – user1930301 Dec 26 '12 at 17:27
0

Userscript support for Internet Explorer is spotty and rapidly becoming obsolete. That said, some people have reported some success getting IE7Pro to work with IE9.

But IE javascript and javascript for Chrome, Firefox, etc. can be quite different.
There is a whole section, on porting userscripts to IE, in iescripts.org's tutorial (see section 5 especially).

Read that tutorial and make an honest attempt to port the code, following the guidelines listed.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295