Helps whitelist YouTube channels in Adblock Plus
当前为
// ==UserScript==
// @name YouTube - whitelist channels in Adblock Plus
// @namespace http://forums.mozillazine.org/memberlist.php?mode=viewprofile&u=261941
// @author Gingerbread Man
// @description Helps whitelist YouTube channels in Adblock Plus
// @include http://*.youtube.com/*
// @include https://*.youtube.com/*
// @exclude http://*.youtube.com/*&user=*
// @exclude https://*.youtube.com/*&user=*
// @version 1.0
// @grant none
// @license http://creativecommons.org/licenses/by-sa/4.0/
// ==/UserScript==
var loc = window.location.href;
// Channel listings
if (loc.search("/user/") !== -1 || loc.search("/channel/") !== -1) {
var unl = document.getElementsByClassName("branded-page-header-title-link")[0];
if (unl) {
var un = unl.href.slice(unl.href.lastIndexOf("/")+1);
var links = document.evaluate('//a[contains(@href, "/watch?v=")]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for (i = 0, j = links.snapshotLength; i < j; i++) {
var eachlink = links.snapshotItem(i);
eachlink.href = eachlink.href + "&user=" + un;
}
}
}
// Search results
else if (loc.search("/results?") !== -1) {
var videos = document.getElementsByClassName("yt-lockup-video"); // -content
if (videos.length>0) {
for (i = 0, j = videos.length; i < j; i++) {
var links = videos[i].getElementsByTagName("a"); // links[0] & links[1] - video; links[2] - user
var un = links[2].href.slice(links[2].href.lastIndexOf("/")+1);
if (links[0].href.search("/watch?") !== -1 && links[1].href.search("/watch?") !== -1) {
links[0].href = links[0].href + "&user=" + un;
links[1].href = links[1].href + "&user=" + un;
}
}
}
}
// Individual video pages
else if (loc.search("/watch?") !== -1 && loc.search("&user=") == -1) {
var unl = document.evaluate('//div[@id="watch7-content"]//link[contains(@href, "/user/")]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
if (unl) {
var un = unl.href.slice(unl.href.lastIndexOf("/")+1);
window.location.href = window.location.href + "&user=" + un;
}
}