To whitelist YouTube channels in uBlock Origin
目前為
// ==UserScript==
// @name YouTube - whitelist channels in uBlock Origin
// @namespace https://github.com/gorhill/uBlock
// @version 1.2
// @description To whitelist YouTube channels in uBlock Origin
// @author Raymond Hill (gorhill)
// @match https://*.youtube.com/*
// @grant none
// @license http://creativecommons.org/licenses/by-sa/4.0/
// @supportURL https://github.com/gorhill/uBlock/issues
// ==/UserScript==
// First page load
//
var exposeUserInURL = function() {
'use strict';
var link = document.querySelector('link[href*="/user/"]');
if ( link === null ) {
return;
}
var pos = link.href.lastIndexOf('/');
if ( pos === -1 ) {
return;
}
var arg = 'user=' + link.href.slice(pos + 1);
var query = location.search;
if ( query.indexOf(arg) !== -1 ) {
return;
}
var href = location.href;
if ( query === '' ) {
location.replace(href + '?' + arg);
return;
}
// https://github.com/gorhill/uBlock/issues/1071
// Remove already existing `user` parameter.
pos = query.indexOf('user=');
if ( pos !== -1 ) {
location.search = query.replace(/user=[^&]*/, '') + arg;
return;
}
location.replace(href + '&' + arg);
};
exposeUserInURL();
// 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, 1);
break;
}
}
};
var observer = new MutationObserver(mutationHandler);
observer.observe(document.body, { childList: true, subtree: true });