Auto Redirect

网站外部链接自动跳转 | 知乎 | 简书 | Steam

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Auto Redirect
// @namespace    [email protected]
// @description  网站外部链接自动跳转 | 知乎 | 简书 | Steam
// @version      1.0.2
// @homepage     https://greasyfork.org/scripts/426352
// @author       Coder Zhao
// @match        https://link.zhihu.com/*
// @match        https://www.jianshu.com/go-wild*
// @match        https://steamcommunity.com/linkfilter*
// @grant        none
// ==/UserScript==

(function() {
  "use strict";

  /**
   * @key paramkey - 查询字串 location.search 中指定的 key
   * @key hostname - 主机名称 location.hostname 的值
   * @key testlink - 测试链接 可省略
   */
  const list = [
    {
      "paramkey": "target",
      "hostname": "link.zhihu.com",
      "testlink": "https://link.zhihu.com/?target=https://github.com/coderzhaoziwei",
    },
    {
      "paramkey": "url",
      "hostname": "www.jianshu.com",
      "testlink": "https://www.jianshu.com/go-wild?ac=2&url=https://github.com/coderzhaoziwei",
    },
    {
      "paramkey": "url",
      "hostname": "steamcommunity.com",
      "testlink": "https://steamcommunity.com/linkfilter/?url=https://github.com/coderzhaoziwei",
    },
  ];

  list.find(data => {
    if (location.hostname === data.hostname) {
      const params = new URLSearchParams(location.search);
      const key = data.paramkey;

      if (params.has(key)) {
        location.replace(params.get(key));
      }

      return params.has(key);
    }
  });

})();