// ==UserScript== // @name OuterChainJump // @namespace cityTS // @version 0.1 // @description 自动跳转外链 // @author cityTS // @match *://link.zhihu.com/?target=* // @match *://link.juejin.cn/?target=* // @match *://www.jianshu.com/go-wild?ac=2&url=* // @match *://c.pc.qq.com/middlem.html?pfurl=* // @match *://gitee.com/link?target=* // @match *://link.csdn.net/?target=* // @icon https://img.picgo.net/2023/03/10/R-Ccac3d9a7c5c66076.png // @grant none // @license MIT // @downloadURL none // ==/UserScript== // 各大网站跳转页面中url的跳转参数名 const siteJumpParamMap = new Map([ ['zhihu','target'], ['csdn','target'], ['juejin','target'], ['gitee','target'], ['jianshu','url'], ['qq','pfurl'], ]); // 获取网站名称 @example: getSiteName('www.baidu.com'); // 'baidu' const getSiteName = hostname => hostname.match(/([^\.]+)\.[^\.]+$/)[1]; (function() { 'use strict'; // 清空页面原有内容,防闪烁(非必须) window.document.documentElement.innerHTML='' // 获取URL中的请求参数 const params = new URLSearchParams(location.search.substring(1)); // 获取网站名称,用于查找对应的跳转参数名 const siteName = getSiteName(location.hostname); // 获取该网站的的跳转URL的参数名,进而获取目标URL const targetURL = params.get(siteJumpParamMap.get(siteName)); // 利用replace()方法进行跳转,保证无用的跳转页面不会产生在历史记录中 location.replace(targetURL); })();