Whitelist YouTube channels in uBlock Origin
当前为
// ==UserScript==
// @name Whitelist YouTube channels ads
// @namespace https://github.com/gorhill/uBlock
// @version 1.7
// @description Whitelist YouTube channels in uBlock Origin
// @author Thomas Couchoud (raksrinana)
// @match https://*.youtube.com/*
// @grant none
// @license http://creativecommons.org/licenses/by-sa/4.0/
// @supportURL https://github.com/gorhill/uBlock/issues
// ==/UserScript==
// based on https://greasyfork.org/en/scripts/22308-youtube-whitelist-channels-in-ublock-origin
var exposeUserInURL = function() {
'use strict';
var link = document.querySelector('#upload-info ytd-channel-name yt-formatted-string.ytd-channel-name a.yt-simple-endpoint.yt-formatted-string');
if ( link === null ) {
return;
}
var linkHref = link.getAttribute('href');
var linkmatch = linkHref.match(/\/(user|channel)\/(.+)/);
if (linkmatch === null)
return;
var channelId = linkmatch[2];
var newArg = channelId !== '' ? 'user=' + encodeURIComponent(channelId) : '';
var matches = location.search.match(/(?:[?&])(user=(?:[^&]+|$))/);
var oldArg = matches !== null ? matches[1] : '';
if ( newArg === oldArg ) {
return;
}
var href = location.href;
if ( oldArg === '' ) {
location.replace(href + (location.search === '' ? '?' : '&') + newArg);
return;
}
location.replace(href.replace(oldArg, newArg));
};
setTimeout(exposeUserInURL, 25);
// DOM modifications
var mutationHandlerTimer = null;
var mutationHandlerAsync = function() {
'use strict';
mutationHandlerTimer = null;
exposeUserInURL();
};
var mutationHandler = function(mutations) {
'use strict';
if ( mutationHandlerTimer !== null ) {
return;
}
for ( var i = 0; i < mutations.length; i++ ) {
if ( mutations[i].addedNodes ) {
mutationHandlerTimer = setTimeout(mutationHandlerAsync, 25);
break;
}
}
};
var observer = new MutationObserver(mutationHandler);
observer.observe(document.body, { childList: true, subtree: true });