Greasy Fork

来自缓存

直接跳转外链

跳过中转页 直接外部链接 支持 知乎 简书

// ==UserScript==
// @name         直接跳转外链
// @namespace    jump_links
// @version      0.1.1
// @description  跳过中转页 直接外部链接 支持 知乎 简书
// @author       MoukJun
// @match        *://*.zhihu.com/*
// @match        *://*.jianshu.com/*
// @mathc        *://*.jianshu.com/*
// @grant GM_openInTab
// @grant GM_addStyle
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// ==/UserScript==

(function() {
  'use strict';
  var host = location.host

  function replaceLink(selector, replaceStr) {
    $(selector).each(function (index, item){
      var href = $(item).attr('href')
      if (href.indexOf(replaceStr) !== -1) {
        href = href.replace(replaceStr, '')
        var realLink = decodeURIComponent(href)
        $(item).attr('href', realLink)
        console.log(realLink)
      }
    })
  }

  var timer = null
  function executeTimer(selector, replaceStr) {
    if (timer) clearTimeout(timer)
    timer = setTimeout(function () {
      replaceLink(selector, replaceStr)
    }, 500)
  }

  function zhihuRun () {
    executeTimer('a.external', 'https://link.zhihu.com/?target=')
    document.onscroll = function () {
      executeTimer('a.external', 'https://link.zhihu.com/?target=')
    }
  }

  function jianshuRun () {
    executeTimer('a', 'https://links.jianshu.com/go?to=')
    document.onscroll = function () {
      executeTimer('a', 'https://links.jianshu.com/go?to=')
    }
  }

  switch (host) {
    case 'www.zhihu.com':
      zhihuRun ()
      break
    case 'www.jianshu.com':
      jianshuRun()
      break
    default:
      break
  }
})();