Open the F**king URL Right Now

自动跳转某些网站不希望用户直达的外链

当前为 2020-10-21 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           Open the F**king URL Right Now
// @description    自动跳转某些网站不希望用户直达的外链
// @author         OldPanda
// @match          http://t.cn/*
// @match          https://www.jianshu.com/go-wild?*
// @match          https://link.zhihu.com/?target=*
// @match          http://link.zhihu.com/?target=*
// @match          https://www.douban.com/link2/?url=*
// @match          https://link.ld246.com/forward?goto=*
// @match          https://mp.weixin.qq.com/*
// @version        0.4.1
// @run-at         document-idle
// @namespace      https://old-panda.com/
// @require        https://code.jquery.com/jquery-3.5.1.min.js
// @license        GPL License
// ==/UserScript==

(function() {
    'use strict';

    /**
     * Make urls clickable again on Weixin Media Platform.
     */
    function enableURLs() {
        let content = $("#js_content").text();
        let urls = content.matchAll(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g);
        let replaced = new Set();
        for (let value of urls) {
            let url = $.trim(value[0]);
            if (!url || replaced.has(url) || url.includes("localhost") || url.includes("127.0.0.1")) {
                continue;
            }
            $("#js_content").html((_, html) => {
                return html.replace(url, `<a target="_blank" rel="noopener noreferrer" href="${url}">${url}</a>`);
            });
            replaced.add(url);
        }
    }

    $(document).ready(function () {
        if (window.location.href.includes("http://t.cn/")) {
            if ($(".wrap .desc").first().text() === "如需浏览,请长按网址复制后使用浏览器访问") {
                window.location.replace($(".wrap .link").first().text());
            }
        } else if (window.location.href.includes("https://www.jianshu.com/go-wild?")) {
            let fakeUrl = new URL(window.location.href);
            let trueUrl = fakeUrl.searchParams.get("url");
            window.location.replace(trueUrl);
        } else if (window.location.href.includes("https://link.zhihu.com/?target=") || window.location.href.includes("http://link.zhihu.com/?target=")) {
            window.location.replace($(".content .link").first().text());
        } else if (window.location.href.includes("https://www.douban.com/link2/?url=")) {
            let fakeUrl = new URL(window.location.href);
            let trueUrl = fakeUrl.searchParams.get("url");
            window.location.replace(trueUrl);
        } else if (window.location.href.includes("https://link.ld246.com/forward?goto=")) {
            let fakeUrl = new URL(window.location.href);
            let trueUrl = fakeUrl.searchParams.get("goto");
            window.location.replace(trueUrl);
        } else if (window.location.href.includes("https://mp.weixin.qq.com/")) {
            enableURLs();
        }
    });
})();