1

我在Chrome中遇到用戶問題。我一直在Greasemonkey中使用這個擴展的版本很長一段時間,但我無法弄清楚如何通過Chrome中的NodeList解析。下面是代碼,因爲它是在Greasemonkey的(請注意,該網站上的代碼是非常糟糕的,所以佔了很多我的代碼:Chrome用戶腳本

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]); 
      } 
     } 
    } 

我遇到的問題是,Chrome不榮譽。在「每個」功能,所以,我能夠修改第一行到:

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

但嵌套每個是我不能獲得工作的一部分,「預」變量是一個節點列表。 ,我無法使用object.forEach方法。

有沒有人對h有任何建議我可以做這項工作嗎?請注意,我工作的任何東西都沒有ID標籤,這將使我的工作變得簡單(頭戴式耳機)。

回答

3

相反的:

for each (tag in pre) { 

用途:

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