1

我正在使用一个油脂猴脚本,即 Youtube 已经:http ://userscripts.org/scripts/review/47198

该脚本旨在突出显示已访问的链接。关键因素是去除使 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 注入的链接,是否有任何方法可以运行此用户脚本?

4

1 回答 1

1

除非你想为你的“规范化器”运行超时,否则没有直接的方法

setInterval(function() {
    //> code here
},1000);
于 2012-12-12T00:04:57.617 回答