非官方页面自动跳转

当前页面非官方页面自动跳转

// ==UserScript==
// @name         非官方页面自动跳转
// @version      1.0.0
// @description  当前页面非官方页面自动跳转
// @author       Haibara.Ai
// @namespace    https://greasyfork.org/users/1055254
// @match        *://c.pc.qq.com/*
// @match        *://link.zhihu.com/*
// @match        *://link.juejin.cn/*
// @match        *://www.jianshu.com/go-wild?*
// @grant        none
// ==/UserScript==

function urlParam(name)
{
    var reg = new RegExp("[\?&]?"+ name +"=([^&]*)");
    var result = window.location.search.substr().match(reg);
    if (result != null) return unescape(result[1]); return null;
}

(function() {
    'use strict';
    var url = null;
    switch (window.location.host) {
        case "c.pc.qq.com":
            url = urlParam('pfurl');
            if (url == null) {
                url = urlParam('url');
            }
            break;
        case "link.zhihu.com":
            url = urlParam('target');
            break;
        case "link.juejin.cn":
            url = urlParam('target');
            break;
        case "www.jianshu.com":
            url = urlParam('url');
            break;
        default:
            url = null;
    }
    if (url != null) window.location.href = url;
})();