Greasy Fork

解除所谓的安全提示跳转

遇到所谓的“外部链接安全提示”页面直接跳转

// ==UserScript==
// @name         解除所谓的安全提示跳转
// @namespace    https://lab.wsl.moe
// @version      0.1
// @description  遇到所谓的“外部链接安全提示”页面直接跳转
// @author       MisakaMikoto
// @match        https://www.oschina.net/action/GoToLink?*
// @match        https://link.zhihu.com/?*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split('&');
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split('=');
            if (decodeURIComponent(pair[0]) == variable) {
                return decodeURIComponent(pair[1]);
            }
        }
        console.log('Query variable %s not found', variable);
    }

    const website = location.host + location.pathname;
    let targetUrl = '';

    switch (website) {
        case 'www.oschina.net/action/GoToLink':
            targetUrl = getQueryVariable('url');
            break;
        case 'link.zhihu.com/':
            targetUrl = getQueryVariable('target');
            break;
    }

    const link = document.createElement('a');
    link.setAttribute('rel', 'noreferrer noopener nofollow');
    link.href = targetUrl;
    link.click();
})();