Greasy Fork

Greasy Fork is available in English.

知乎工具箱

知乎工具箱,各种奇奇怪怪的小功能~

当前为 2021-06-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         知乎工具箱
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  知乎工具箱,各种奇奇怪怪的小功能~
// @author       kuubee
// @match        https://*.zhihu.com/*
// @icon         https://www.google.com/s2/favicons?domain=mozilla.org
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    window.onload = () => {
        ZhihuUtils.aJumpOptimization();
    }
})();

class ZhihuUtils {
    // a 标签跳转优化
    static aJumpOptimization() {
        window.addEventListener('click', (e) => {
            if (e.target.tagName !== 'A') return;
            const href = e.target.href;
            const matchList = href.match(/https:\/\/link\.zhihu\.com\/\?target=(.*)/);
            if (!matchList[0]) return;
            if (!matchList[1]) return;
            const targetHref = decodeURIComponent(matchList[1]);
            e.preventDefault();
            window.open(targetHref);
        })
    }
}