1
我使用的Greasemonkey腳本,即與YouTube已有:http://userscripts.org/scripts/review/47198的GreaseMonkey腳本,而不是解析鏈接添加到DOM
這個腳本旨在強調已經訪問過的鏈接。關鍵的因素是去除使參數無效的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(/\&(.*)/,"");
}
}
}
問題是taht這個代碼將只檢查在標準的HTML頁面的YouTube鏈接。添加了AJAX的鏈接(主要在YouTube頻道上)不會被標準化。
即使使用AJAX注入的鏈接,是否有任何方法來運行這個腳本?
不是最好的解決辦法......但如果它的工作原理,爲什麼不...... – dynamic
似乎ISN」 t工作:( – dynamic
Acutally它的工作,你犯了一個錯誤... setTimeout,而不是setInterval:D – dynamic