views:

44

answers:

1
+1  Q: 

Chrome Userscripts

I'm having a problem with a Userscript in chrome. I have been using a version of this extension in Greasemonkey for a long time now, but I can't figure out how to parse through a NodeList in Chrome. Here is the code as it is in Greasemonkey (please note that the code on the site is really bad, so that accounts for a lot of my code:

for each (table in response) {
        pre = table.getElementsByTagName('pre');
        for each (tag in pre) {
            if (findNotes.test(tag.textContent)) {
                time = tag.parentNode.parentNode.parentNode.childNodes[0].childNodes[3].childNodes[3].textContent;
                emailexp = new RegExp("*Excluded for anonymity*","g");
                email = emailexp.exec(tag.textContent);
                oldstr = "Note From: " + email;
                newstr = '<p style="font-weight:bold">Note From: ' + email + "\t" + time + "</p>"
                noteStr += tag.textContent.replace(oldstr, newstr);
                noteStr += "\n";
                var nodeToDelete = tag.parentNode.parentNode.parentNode.parentNode;
                nodeToDelete.removeChild(nodeToDelete.childNodes[1]);
            }
        }
    }

The problem I am having is that Chrome does not honor the 'for each' functionality. So, I was able to modify the first line into:

response.forEach(function(table, index, array) {

But the nested for each is the part I can't get to work. The 'pre' variable is a NodeList, which I can not use the object.forEach method on.

Does anybody have any suggestions on how I can make this work? Please note that there are no ID tags on anything I am working on, that would make my job to easy (headdesk).

+1  A: 

Instead of:

for each (tag in pre) {

Use:

for (var i=pre.length, tag; i >= 0; i--) {
  tag=pre.item(i);
Erik Vold