Chrome 用户脚本
我在 Chrome 中遇到用户脚本问题。我已经在 Greasemonkey 中使用这个扩展的一个版本很长时间了,但我不知道如何在 Chrome 中解析 NodeList。这是 Greasemonkey 中的代码(请注意,该网站上的代码非常糟糕,因此占了我的大部分代码:
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 不支持“foreach”功能。因此,我能够将第一行修改为:
response.forEach(function(table, index, array) {
但每个的嵌套是我无法工作的部分。“pre”变量是一个 NodeList,我无法在其上使用 object.forEach 方法
。有人对我如何完成这项工作有任何建议吗?请注意,我正在做的任何事情都没有 ID 标签,这将使我的工作变得轻松(headdesk)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代替:
使用:
Instead of:
Use: