x

    YouTube-sino.png

    // ==UserScript==
    // @name         YouTube新标签打开
    // @namespace    https://vivix.vip/
    // @version      1.2
    // @description  跳过logo导航等常见非正文区域,兼容多数网站,方便扩展支持更多网站
    // @author       飞丶宇
    // @match        *://*/*
    // @grant        none
    // ==/UserScript==
    
    (function() {
        'use strict';
    
        // 支持匹配的网站列表,修改此数组添加支持的域名(可部分匹配)
        const sites = [
            'youtube.com',
            // 'example.com', // 可自行添加更多支持网站
        ];
    
        function isSiteSupported() {
            return sites.some(site => {
                if(site.startsWith('/')) {
                    const re = new RegExp(site.slice(1, -1));
                    return re.test(window.location.hostname);
                } else {
                    return window.location.hostname.includes(site);
                }
            });
        }
    
        if(!isSiteSupported()) return;
    
        const excludeSelectors = [
            'header a',
            'nav a',
            'footer a',
            '.sidebar a',
            '#logo a',
            '.logo a',
            '[role="banner"] a',
            '[role="navigation"] a',
            '[role="contentinfo"] a',
            '[role="complementary"] a',
            '.ads a',
            '.advertisement a',
            '[aria-hidden="true"] a',
            '.hidden a',
            '.sr-only a',
            '.modal a',
            '.popup a',
            '.overlay a'
        ];
    
        function isExcludedLink(el) {
            return excludeSelectors.some(sel => {
                try {
                    const nodes = document.querySelectorAll(sel);
                    for(const node of nodes) {
                        if(node.contains(el)) return true;
                    }
                } catch (e) {}
                return false;
            });
        }
    
        document.body.addEventListener('click', function(e) {
            let el = e.target;
    
            while(el && el.tagName !== 'A') {
                el = el.parentElement;
            }
            if(!el) return;
    
            if(!el.href) return;
    
            if(isExcludedLink(el)) return;
    
            e.preventDefault();
            e.stopImmediatePropagation();
    
            window.open(el.href, '_blank');
    
        }, true);
    })();

    复制脚本到 脚本猫 或 篡改猴、新建脚本即可。


    篡改猴 - Microsoft Edge Addons

    脚本猫 - Microsoft Edge Addons

    打赏 支付宝打赏 微信打赏