Greasy Fork

Greasy Fork is available in English.

让我直接跳转好吗

网页中的外链直接跳出去而不再被拦一道

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         让我直接跳转好吗
// @namespace    http://greasyfork.icu/zh-CN/users/177458-bd777
// @version      0.4
// @description  网页中的外链直接跳出去而不再被拦一道
// @author       windeng
// @match        *://*.zhihu.com/*
// @match        *://c.pc.qq.com/*
// @match        *://*.jianshu.com/*
// @grant        none
// ==/UserScript==

function gaoZhihu() {
  if (!window.location.href.match('zhihu.com')) return

  let run = () => {
    let cnt = 0
    let aList = document.querySelectorAll('a')
    for (let a of aList) {
      const href = a.getAttribute('href')
      const matches = href.match(/link\.zhihu\.com\/?\?target=(.*)/)
      // console.log('?', href, matches)
      if (matches) {
        const url = decodeURIComponent(matches[1])
        a.setAttribute('href', url)
        // console.log(`${href} => ${url}`)
        ++cnt
      }
    }
    return cnt > 0
  }

  run()

  let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver

  let observer = new MutationObserver(function (mutations) {
    run()
  })

  observer.observe(document.body, {
    childList: true,
    subtree: true
  })
}

function gaoQQ() {
  if (!window.location.href.match('c.pc.qq.com')) return

  const matches = window.location.search.match(/pfurl=([^&$]*)/)
  if (matches) {
    let url = decodeURIComponent(matches[1])
    console.log('QQ url', url)
    if (!url.startsWith('http') && !url.startsWith('//')) url = '//' + url
    window.location.href = url
  }
}

function gaoJianshu() {
  if (!window.location.href.match('jianshu.com')) return

  let run = () => {
    let cnt = 0
    let aList = document.querySelectorAll('a')
    for (let a of aList) {
      const href = a.getAttribute('href')
      const matches = href.match(/links.jianshu.com\/go\?to=([^&$]*)/)
      // console.log('?', href, matches)
      if (matches) {
        const url = decodeURIComponent(matches[1])
        a.setAttribute('href', url)
        // console.log(`${href} => ${url}`)
        ++cnt
      }
    }
    return cnt > 0
  }

  run()

  let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver

  let observer = new MutationObserver(function (mutations) {
    run()
  })

  observer.observe(document.body, {
    childList: true,
    subtree: true
  })
}

(function () {
  'use strict';

  // Your code here...
  gaoZhihu()
  gaoQQ()
  gaoJianshu()
})();