自研 - 多个站点 - 反外站拦截

去除某些网站的外站拦截。目前已适配知乎、Pixiv(予素)、Gitee、天眼查、百度贴吧、插画世界或森空岛。

目前為 2024-06-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name               自研 - 多个站点 - 反外站拦截
// @name:en_US         Self-made - Multi-site - Anti-External Site Interception
// @description        去除某些网站的外站拦截。目前已适配知乎、Pixiv(予素)、Gitee、天眼查、百度贴吧、插画世界或森空岛。
// @description:en_US  Remove external site interception for some websites. Currently compatible with Zhihu, Pixiv, Gitee, TianYanCha, Baidu Tieba, Vlipix, and SKLAND.
// @version            1.0.2
// @author             CPlayerCHN
// @license            MulanPSL-2.0
// @namespace          https://www.gitlink.org.cn/CPlayerCHN
// @match              *://*.zhihu.com/*
// @match              *://www.pixiv.net/*
// @match              *://gitee.com/*
// @match              *://www.tianyancha.com/*
// @match              *://jump2.bdimg.com/safecheck/index
// @match              *://www.vilipix.com/*
// @match              *://www.skland.com/*
// @run-at             document-start
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    // 定义「配置」变量,「解码」「暂停执行」「点击器」函数。

    const config = [
        // {
        //     "name": "站点名",
        //     "matchLink": /匹配链接/,
        //     "target": "目标",
        //     "reproduce": "复现链接"
        // },
        {
            "name": "知乎",
            "matchLink": /^link.zhihu.com/,
            "target": "target",
            "reproduce": "https://www.zhihu.com/question/646179463/answer/3411700328"
        },
        {
            "name": "Pixiv(予素)",
            "matchLink": /^www.pixiv.net\/jump.php/,
            "target": "$withoutParamKey",
            "reproduce": "https://www.pixiv.net/users/10885193 > 查看个人资料"
        },
        {
            "name": "Gitee",
            "matchLink": /^gitee.com\/link/,
            "target": "target",
            "reproduce": "https://gitee.com/rmbgame/SteamTools#从移动端-steam-app-导入令牌指南"
        },
        {
            "name": "天眼查",
            "matchLink": /^www.tianyancha.com\/security/,
            "target": "target",
            "reproduce": "https://www.tianyancha.com/company/2347945472"
        },
        {
            "name": "百度贴吧",
            "matchLink": /^jump2.bdimg.com\/safecheck\/index/,
            "target": ".warning_info a",
            "reproduce": "https://tieba.baidu.com/p/8459041179 > 5楼 > 彼梦Archi"
        },
        {
            "name": "插画世界",
            "matchLink": /^www.vilipix.com\/jump/,
            "target": "$withoutParamKey",
            "reproduce": "https://www.vilipix.com/illust/108871691"
        },
        {
            "name": "森空岛",
            "matchLink": /^www.skland.com\/third-link/,
            "target": "target",
            "reproduce": "https://www.skland.com/ > 工具箱 > 塞壬唱片"
        }
    ];

    function decode(data) {

        // 判断状况并解码。
        if(/^http(s)/.test(data)) {

            return decodeURIComponent(data);

        }else {

            return atob(data);

        }

    };

    function sleep(ms) {

        return new Promise(resolve => setTimeout(resolve, ms));

    }

    async function clicker(elm) {

        // 定义「按钮元素」变量
        const btn = document.querySelector(elm);

        // 如果「按钮元素」存在就点击,不存在就等待 .1 秒后再次判断
        if(btn) {

            btn.click();

        }else {

            await sleep(100);
            clicker(elm);

        }

    };


    // 遍历「配置」
    config.forEach((data) => {

        // 当链接匹配,就判断目标执行方法并执行对应操作。
        if(data.matchLink.test(location.href.replace(/http(s):\/\//, ""))) {

            // 定义「目标」变量
            const target = data.target;

            // 内容中有 .、# 或 ] 结尾的判断为元素点击;其他字符串判断为链接参数;函数判断为自定义参数
            if(typeof target === "string" && /\.|#|\]/.test(target)) {

                clicker(target);

            }else if(typeof target === "string" && location.search !== "" && target === "$withoutParamKey") {

                // 停止网页继续加载
                window.stop();

                // 访问页面
                window.open(decode(location.search.substring(1)), "_self");

            }else if(typeof target === "string" && location.search !== "") {

                // 停止网页继续加载
                window.stop();

                // 定义「网页参数」变量
                const params = new URLSearchParams(location.search.substring(1));

                // 访问页面
                window.open(decode(params.get(target)), "_self");

            }else if(typeof target === "function") {

                target();

            }

        }

    });

    // 定义「侦测器」变量
    const observer = new MutationObserver(() => {

        // 遍历所有未被修改的链接元素
        document.querySelectorAll('a:not(.removeIntercepted)').forEach((link) => {

            // 遍历「配置」
            config.forEach((data) => {

                // 定义「目标」变量
                const target = data.target;

                // 如果链接匹配、「目标」是字符串、「目标」不是 CSS 选择器、「目标」不是特殊执行方式且链接网页参数不是空的就
                // $withoutParamKey 之后再写
                if(data.matchLink.test(link.href.replace(/https?:\/\//, "")) && typeof target === "string" && !/\.|#|\]/.test(target)  && target !== "$withoutParamKey" && new URL(link.href).search !== "") {

                    // 定义「网页参数」变量
                    const params = new URLSearchParams(new URL(link.href).search.substring(1));

                    // 修改链接地址并添加「removeIntercepted」类,防止重复检测
                    link.href = decode(params.get(target));
                    link.classList.add("removeIntercepted");

                }

            });

        });

    });

    // 当页面加载了 Body 元素,就配置「侦测器」侦测目标节点
    document.addEventListener('DOMContentLoaded', () => {
        observer.observe(document.body, {
            "subtree": true,
            "childList": true
        });
    });

})();

QingJ © 2025

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