Greasy Fork

Greasy Fork is available in English.

IDontNeedRedirect

去除常见网站的对域外链接的重定向

当前为 2020-12-23 提交的版本,查看 最新版本

// ==UserScript==
// @name        IDontNeedRedirect
// @namespace   IDontNeedRedirect
// @match       https://mail.qq.com/cgi-bin/frame_html*
// @match       https://www.zhihu.com/*
// @version     1.0.0
// @author      Dreace
// @license     GPL-3.0
// @description 去除常见网站的对域外链接的重定向
// @grant       unsafeWindow
// ==/UserScript==

"use strict";
var handlers = {};

handlers["https://mail.qq.com/cgi-bin/frame_html"] = function () {
  unsafeWindow._openExtLink = function () {
    return true;
  };
};

handlers["https://www.zhihu.com"] = function () {
  setInterval(function () {
    document.querySelectorAll(".external").forEach(function (aTag) {
      try {
        aTag.href = decodeURIComponent(
          aTag.href.match(/link.zhihu.com\/\?target=(.*)/)[1]
        );
        aTag.className = "";
      } catch (error) {
        log(error);
      }
    });
  }),
    5000;
};

for (var url in handlers) {
  if (location.href.match(url)) {
    log(url + " detected");
    handlers[url]();
    log(url + " done");
  }
}

function log(content) {
  console.log("[IDontNeedRedirect] " + content);
}