Javascript Chrome用户脚本
我在chrome中的用户脚本有问题。我已经在Greasemonkey中使用这个扩展的一个版本很长时间了,但是我不知道如何通过Chrome中的节点列表进行解析。以下是Greasemonkey中的代码(请注意,该网站上的代码非常糟糕,因此我的代码中有很多是这样的:Javascript Chrome用户脚本,javascript,google-chrome,greasemonkey,google-chrome-extension,Javascript,Google Chrome,Greasemonkey,Google Chrome Extension,我在chrome中的用户脚本有问题。我已经在Greasemonkey中使用这个扩展的一个版本很长时间了,但是我不知道如何通过Chrome中的节点列表进行解析。以下是Greasemonkey中的代码(请注意,该网站上的代码非常糟糕,因此我的代码中有很多是这样的: for each (table in response) { pre = table.getElementsByTagName('pre'); for each (tag in pre) {
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]);
}
}
}
但是嵌套的每个都是我无法使用的部分。“pre”变量是一个节点列表,我不能在其上使用object.forEach方法
有人对我如何完成这项工作有什么建议吗?请注意,我正在做的任何事情都没有ID标签,这将使我的工作变得简单(总部)。而不是:
for each (tag in pre) {
使用:
for each (tag in pre) {
for (var i=pre.length, tag; i >= 0; i--) {
tag=pre.item(i);