我正在使用油脂猴子脚本,即Youtube Already:
该脚本旨在突出显示已访问的链接。关键因素是要去除使a:visited无效的url参数。
i.e.: http://www.youtube.com/watch?v=aKWPht3fU-o !=
http://www.youtube.com/watch?v=aKWPht3fU-o&featured=fvw
重要的部分是:
var cleanlink, dirtylink, i, x, aXpath;
aXpath = new Array(7);
aXpath[0] = '//a[contains(@href, "feature=related")]';
aXpath[1] = '//a[contains(@href, "feature=relmfu")]';
aXpath[2] = '//a[contains(@href, "feature=g-")]';
aXpath[3] = '//a[contains(@href, "feature=b-")]'; // &feature=b- all browse
aXpath[4] = '//a[contains(@href, "/user/")]';
aXpath[5] = '//a[contains(@href, "/videos")]'; // search
aXpath[6] = '//a[contains(@href, "&list")]'; // playlists
for(x in aXpath) {
dirtylink = document.evaluate(aXpath[x], document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (i = 0; i < dirtylink.snapshotLength; i++) {
cleanlink = dirtylink.snapshotItem(i);
switch (x){
case 6:
cleanlink.href = cleanlink.href.replace(/\&feature(.*)/,"").replace(/\&index(.*)/,"");
break;
case 4:
case 5:
cleanlink.href = cleanlink.href.replace(/\?(.*)/,"");
break;
default :
cleanlink.href = cleanlink.href.replace(/\&(.*)/,"");
}
}
}
问题在于此代码将仅检查标准HTML youtube页面中的链接。随AJAX添加的链接(通常在youtube频道上)将不规范。
即使使用注入了AJAX的链接,该方法也可以运行此用户脚本吗?
最佳答案
除非您要为“规范化器”运行超时,否则没有直接的方法
setInterval(function() {
//> code here
},1000);