Fuck Wechat or zhihu

自动重定向被微信/知乎拦截的链接

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Fuck Wechat or zhihu
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  自动重定向被微信/知乎拦截的链接
// @author       [email protected]
// @match        *://weixin110.qq.com/*
// @match        *://link.zhihu.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    //setTimeout(redirect, 1000)
    redirect()

    function getUrl(){
        const targetEl2 = document.querySelector(".weui-msg__desc")
        const targetEl = document.querySelector(".weui-msg .weui-msg__text-area .ui-ellpisis-content p");
        const zhihuLinkEl = document.querySelector(".link")
        const targetText = targetEl?.innerText
        const targetText2 = targetEl2?.innerText
        const zhihuTargetText = zhihuLinkEl?.innerText
        const urlReg = /^(http:|https:)/img;
        if(urlReg.test(targetText)) {
            return targetText
        }else if(urlReg.test(targetText2)) {
            return targetText2
        }else if(urlReg.test(zhihuTargetText)){
            return zhihuTargetText
        }
        return null;
    }

    function redirect() {
        const url = getUrl()
        if(url) { window.location.href = url }
    }
})();