// ==UserScript== // @name 让我直接跳转好吗 // @namespace https://greasyfork.org/zh-CN/users/177458-bd777 // @version 0.2 // @description 网页中的外链直接跳出去而不再被拦一道 // @author windeng // @match *://*.zhihu.com/* // @match *://c.pc.qq.com/* // @match *://*.jianshu.com/* // @grant none // @downloadURL 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) { const url = decodeURIComponent(matches[1]) 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... window.addEventListener('load', () => { gaoZhihu() gaoQQ() gaoJianshu() }) })();