YouTube - whitelist channels in Adblock Plus

Helps whitelist YouTube channels in Adblock Plus

目前为 2014-08-17 提交的版本。查看 最新版本

// ==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.1
// @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 list = document.getElementById("channels-browse-content-grid");
var unl = document.getElementsByClassName("branded-page-header-title-link")[0];
var un = unl.href.slice(unl.href.lastIndexOf("/")+1);

var observer = new MutationObserver(function(mutations) {
	if (unl) rewrite();
});

function rewrite() {
	var links = document.evaluate('//a[contains(@href, "/watch?v=")][not(contains(@href, "&user="))]',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;
	}
}

if (unl) rewrite();
if (list) observer.observe(list, { childList: true, subtree:true });

}

// Search results
else if (loc.search("/results?") !== -1) {
	var videos = document.getElementsByClassName("yt-lockup-video");
	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;
	}
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址