如果 result.responseText.match 不存在
我对javascript不太了解,但我发现了我正在尝试编辑的greasemonekey脚本。
var rating = document.links;
for (i = 0; i < rating.length; i++) {
if (rating[i].href.indexOf("/shows/") != -1){
GM_xmlhttpRequest({
method: 'get',
url: rating[i].href,
onload: function (i) {return function(result) {
rate = result.responseText.match(/<span class="rating">(.*)<\/span>/);
result = rate[1].substring(0,3);
rat = document.createElement("div");
rat.className = 'rate';
rat.innerHTML = result;
rating[i].parentNode.insertBefore(rat, rating[i].nextSibling);
}}(i)
});
}
}
因此它会搜索页面上的所有链接,如果链接包含 /shows/ 它会搜索值:
<span class="rating"><\span>
如果找到它会在我创建的 div 中显示结果。到目前为止,一切都很好!
但其中一些链接确实有
在这些链接上我喜欢说“未找到”但我不知道如何到 :(
i don't know mutch about javascript but i found this greasemonekey script that i'm trying to edit.
var rating = document.links;
for (i = 0; i < rating.length; i++) {
if (rating[i].href.indexOf("/shows/") != -1){
GM_xmlhttpRequest({
method: 'get',
url: rating[i].href,
onload: function (i) {return function(result) {
rate = result.responseText.match(/<span class="rating">(.*)<\/span>/);
result = rate[1].substring(0,3);
rat = document.createElement("div");
rat.className = 'rate';
rat.innerHTML = result;
rating[i].parentNode.insertBefore(rat, rating[i].nextSibling);
}}(i)
});
}
}
So it search all the links on the page and if the link contains /shows/ it search for the value:
<span class="rating"><\span>
if its found it shows the result in the div i created. so far so good!
But some of those links doenst have <span class="rating"><\span>
On those links i like it to say "not found" But i can't figured it out how to :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)