将代码注入包含youtube的活动窗口时,应将其重定向到g.co但是它没有这样做。我认为这是因为for
循环有一些错误,但我不确定。
var current_title = document.title.toLowerCase();
var blacklisted = ["youtube","vimeo"].map(v => v.toLowerCase());
var isurlnotok = false;
var websiteisnotok = false;
var item_url;
for (var i =0; i <= blacklisted.length || isurlnotok || websiteisnotok; i++) {
item_url = blacklisted[i];
isurlnotok = current_url.includes(item_url);
websiteisnotok = current_title.includes(item_url);
}
if (isurlnotok || websiteisnotok){
window.location = "https://g.co";
}
console.log("url: "+current_url+"\ntitle: "+current_title+"\nisurlnotok:"+isurlnotok+"\niswebsitenotok:"+websiteisnotok);
这没有意义:blacklisted.length || isurlnotok|| websiteisnotok
为什么会有一个或(||),然后尝试在下一行访问列入黑名单的[i]?
您可能的意思是:
for (var i =0;i<=blacklisted.length;i++){
item_url=blacklisted[i];
if(!isurlnotok)
isurlnotok=current_url.includes(item_url);
if(!websiteisnotok)
websiteisnotok=current_title.includes(item_url);
}
if (isurlnotok|| websiteisnotok){window.location = "https://g.co";}