YouTube - whitelist channels in uBlock Origin

To whitelist YouTube channels in uBlock Origin

目前為 2015-10-20 提交的版本,檢視 最新版本

// ==UserScript==
// @name         YouTube - whitelist channels in uBlock Origin
// @namespace    https://github.com/gorhill/uBlock
// @version      1.1
// @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);
    if ( location.search === '' ) {
        location.replace(location.href + '?' + arg);
        return;
    }
    if ( location.href.indexOf(arg) === -1 ) {
        location.replace(location.href + '&' + arg);
        return;
    }
};

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 });

QingJ © 2025

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