Greasy Fork

Greasy Fork is available in English.

Wanta

移除跳转外链提示

当前为 2023-05-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Wanta
// @namespace    http://tampermonkey.net/
// @version      0.4.2
// @description  移除跳转外链提示
// @author       PRO
// @match        *://www.jianshu.com/p/*
// @match        *://juejin.cn/post/*
// @match        *://gitee.com/*
// @match        *://zhuanlan.zhihu.com/*
// @match        *://*.feishu.cn/*
// @match        *://leetcode.cn/problems/*
// @match        *://www.mcmod.cn/*
// @match        *://play.mcmod.cn/*
// @match        *://www.mcbbs.net/*
// @match        *://www.minecraftforum.net/*
// @match        *://www.curseforge.com/minecraft/mc-mods/*
// @icon         http://greasyfork.icu/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBMWhLQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--2831c7f8ea43fc8b8e3eed3818b98e88bb689285/%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%202022-07-16%20105357.png?locale=zh-CN
// @grant        none
// @license      gpl-3.0
// @require      http://greasyfork.icu/scripts/462234-message/code/Message.js?version=1192786
// ==/UserScript==

(function() {
    'use strict';
    let debug = false;
    // domain: [link_prefix query_parameter main_article_path dynamic_query decode_func always_listen]
    // query_parameter = '': Get the last part of url
    function same(orig) {
        return orig;
    }
    function b64Decode(orig) {
        return decodeURIComponent(atob(orig));
    }
    function mcmod(orig) {
        let parts = orig.split("@");
        return parts.map(b64Decode).join("?");
    }

    let fuck = {
        'www.jianshu.com': ['https://links.jianshu.com/go', 'to', 'article', '', decodeURIComponent, false],
        'juejin.cn': ['https://link.juejin.cn', 'target', '#juejin > div.view-container > main > div > div.main-area.article-area > article', ' > .article-content', decodeURIComponent, false],
        'gitee.com': ['https://gitee.com/link', 'target', '.markdown-body', '', decodeURIComponent, false],
        'zhuanlan.zhihu.com': ['https://link.zhihu.com/', 'target', 'div.Post-RichTextContainer', '', decodeURIComponent, false],
        '.*\.feishu\.cn': ['https://security.feishu.cn/link/safety', 'target', 'div#mainBox', '   div.mindnote-paper', decodeURIComponent, false],
        'leetcode.cn': ['https://leetcode.cn/link/', 'target', '#app', '   div#question-detail-main-tabs', same, true],
        'www.mcmod.cn': ['https://link.mcmod.cn/target/', '', 'body > div.col-lg-12.common-frame > div > div.col-lg-12.center > div.col-lg-12.right', '', mcmod, false],
        'play.mcmod.cn': ['https://link.mcmod.cn/target/', '', 'body > div.col-lg-12.common-frame > div > div.col-lg-12.center', '', mcmod, false],
        'www.mcbbs.net': ['https://www.mcbbs.net/plugin.php', 'target', 'div#ct', '', decodeURIComponent, false],
        'www.minecraftforum.net': ['https://www.minecraftforum.net/linkout', 'remoteUrl', '.listing-container', '', decodeURIComponent, false],
        'www.curseforge.com': ['https://www.curseforge.com/linkout', 'remoteUrl', '.project-page', ' > .tab-content', decodeURIComponent, true]
    };
    let domain = window.location.hostname;
    if (!(domain in fuck)) {
        for (let d in fuck) {
            if (domain.match(d)) {
                domain = d;
                break;
            }
        }
    }
    let suffix = fuck[domain][0];
    let query_name = fuck[domain][1];
    let main_path = fuck[domain][2];
    let dynamic = fuck[domain][3];
    let decode_func = fuck[domain][4];
    let always_listen = fuck[domain][5];
    let name = 'Wanta';
    window.QMSG_GLOBALS = {
        DEFAULTS: {
            showClose:true,
            timeout: 2000
        }
    }
    let toast = (s, error=false) => {
        if (error) {
            Qmsg.error(`[${name}] ${s}`);
            console.error(`[${name}] ${s}`);
        } else {
            Qmsg.success(`[${name}] ${s}`);
            console.log(`[${name}] ${s}`);
        }
    };
    function purify(link) {
        let new_href;
        if (query_name.length == 0) {
            let l = link.href.split('/');
            new_href = l[l.length - 1];
        } else {
            let params = new URL(link.href).searchParams;
            new_href = params.get(query_name);
        }
        new_href = decode_func(new_href);
        if (new_href) {
            if (debug) console.log(`[${name} DEBUG] ${link.href} -> ${new_href}`);
            link.href = new_href;
            return true;
        }
        else {
            toast("⛔ Failed to purify below link element:", true);
            toast(link, true);
            return false;
        }
    }
    function main() {
        let target_node = document.querySelector(main_path + dynamic);
        let links;
        if (target_node) {
            links = target_node.getElementsByTagName('a');
        } else {
            return;
        }
        if (debug) console.log(links);
        let purified = 0;
        for (let i = 0;i < links.length; i++) {
            if (links[i].href.startsWith(suffix)) {
                if (purify(links[i])) purified++;
            } else if (debug) console.log(`[${name} DEBUG] Skipped "${links[i].href}".`);
        }
        if (purified > 0) {
            toast(`🪄 Purified ${purified} links out of ${links.length} links.`);
        } else {
            console.log(`[${name}] No links purified (total ${links.length} links).`);
        }
    }
    if (dynamic) {
        const node = document.querySelector(main_path);
        const config = { attributes: false, childList: true, subtree: true };
        const callback = function(mutations, observer) {
            let article = node.querySelector(dynamic.slice(3));
            if (article) {
                main();
                if (!always_listen)
                observer.disconnect();
            }
        }
        const observer = new MutationObserver(callback);
        observer.observe(node, config);
    }
    else main();
})();