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

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

目前为 2024-06-01 提交的版本。查看 最新版本

// ==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.0
// @author             CPlayerCHN
// @license            MulanPSL-2.0
// @namespace          https://www.gitlink.org.cn/CPlayerCHN
// @match              *://www.zhihu.com/*
// @match              *://zhuanlan.zhihu.com/*
// @match              *://link.zhihu.com/*
// @match              *://www.pixiv.net/*
// @match              *://gitee.com/*
// @match              *://www.tianyancha.com/*
// @match              *://tieba.baidu.com/*
// @match              *://jump2.bdimg.com/safecheck/index*
// @match              *://www.vilipix.com/jump*
// @match              *://www.skland.com/third-link
// @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) {

        // 如果元素存在就点击,不存在就等待 .1 秒后再次判断
        if(document.querySelector(elm)) {

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

            }

        }

    });

})();