Open the F**king URL Right Now

自动跳转某些网站不希望用户直达的外链

目前为 2025-03-28 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Open the F**king URL Right Now
  3. // @description 自动跳转某些网站不希望用户直达的外链
  4. // @author OldPanda
  5. // @match http*://c.pc.qq.com/*
  6. // @match http*://iphone.myzaker.com/zaker/link.php?*
  7. // @match http*://link.zhihu.com/?*
  8. // @match http*://t.cn/*
  9. // @match http*://www.360doc.cn/outlink.html?url=*
  10. // @match http://redir.yy.duowan.com/warning.php?url=*
  11. // @match http://www.360doc.com/content/*
  12. // @match https://afdian.com/link?target=*
  13. // @match https://afdian.net/link?target=*
  14. // @match https://ask.latexstudio.net/go/index?url=*
  15. // @match https://bbs.acgrip.com/*
  16. // @match https://bbs.nga.cn/read.php?*
  17. // @match https://blog.51cto.com/transfer?*
  18. // @match https://blzxteam.com/gowild.htm?url=*
  19. // @match https://cloud.tencent.com/developer/tools/blog-entry?target=*
  20. // @match https://developers.weixin.qq.com/community/middlepage/href?href=*
  21. // @match https://developer.aliyun.com/redirect?target=*
  22. // @match https://docs.qq.com/scenario/link.html?u=*
  23. // @match https://docs.qq.com/scenario/link.html?url=*
  24. // @match https://game.bilibili.com/linkfilter/?url=*
  25. // @match https://gitee.com/link?target=*
  26. // @match https://hd.nowcoder.com/link.html?target=*
  27. // @match https://hellogithub.com/periodical/statistics/click?target=*
  28. // @match https://jump2.bdimg.com/safecheck/index?url=*
  29. // @match https://leetcode.cn/link/?target=*
  30. // @match https://link.csdn.net/?*target=*
  31. // @match https://link.juejin.cn/?target=*
  32. // @match https://link.ld246.com/forward?goto=*
  33. // @match https://link.logonews.cn/?*
  34. // @match https://link.uisdc.com/?redirect=*
  35. // @match https://mail.qq.com/cgi-bin/readtemplate*
  36. // @match https://mp.weixin.qq.com/s/*
  37. // @match https://mp.weixin.qq.com/s?*
  38. // @match https://nga.178.com/read.php?*
  39. // @match https://ref.gamer.com.tw/redir.php/url=*
  40. // @match https://ref.gamer.com.tw/redir.php?url=*
  41. // @match https://shimo.im/outlink/black?url=*
  42. // @match https://shimo.im/outlink/gray?url=*
  43. // @match https://sspai.com/link?target=*
  44. // @match https://steamcommunity.com/linkfilter/?url=*
  45. // @match https://steamcommunity.com/linkfilter/?u=*
  46. // @match https://support.qq.com/product/*/link-jump?jump=*
  47. // @match https://support.qq.com/products/*/link-jump?jump=*
  48. // @match https://t.me/iv?url=*
  49. // @match https://tieba.baidu.com/mo/q/checkurl?url=*
  50. // @match https://txc.qq.com/product/*/link-jump?jump=*
  51. // @match https://txc.qq.com/products/*/link-jump?jump=*
  52. // @match https://weibo.cn/sinaurl?*
  53. // @match https://weixin110.qq.com/cgi-bin/mmspamsupport-bin/newredirectconfirmcgi*
  54. // @match https://wx.mail.qq.com/xmspamcheck/xmsafejump?*
  55. // @match https://www.bookmarkearth.com/view/*
  56. // @match https://www.chinaz.com/go.shtml?url=*
  57. // @match https://www.coolapk.com/link?url=*
  58. // @match https://www.curseforge.com/linkout?remoteUrl=*
  59. // @match https://www.douban.com/link2/?url=*
  60. // @match https://www.gcores.com/link?target=*
  61. // @match https://www.google.com/url?q=*
  62. // @match https://www.instagram.com/linkshim/?u=*
  63. // @match https://www.jianshu.com/go-wild?*
  64. // @match https://www.kookapp.cn/go-wild.html?url=*
  65. // @match https://www.linkedin.com/safety/go?url=*
  66. // @match https://www.luogu.com.cn/discuss/*
  67. // @match https://www.luogu.com.cn/paste/*
  68. // @match https://www.luogu.com.cn/article/*
  69. // @match https://www.nodeseek.com/jump?to=*
  70. // @match https://www.oschina.net/action/GoToLink?url=*
  71. // @match https://www.pixiv.net/jump.php?*
  72. // @match https://www.qcc.com/web/transfer-link?link=*
  73. // @match https://www.tianyancha.com/security?target=*
  74. // @match https://www.yuque.com/r/goto?url=*
  75. // @match https://*.infoq.cn/link?target=*
  76. // @match https://www.baike.com/redirect_link?url=*
  77. // @match https://www.youtube.com/redirect?*
  78. // @exclude https://mp.weixin.qq.com/cgi-bin/*
  79. // @version 1.14.3
  80. // @run-at document-idle
  81. // @namespace https://old-panda.com/
  82. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js
  83. // @license GPLv3 License
  84. // ==/UserScript==
  85.  
  86. const $ = jQuery.noConflict(true);
  87.  
  88. /**
  89. * @enum {string}
  90. * @name fuckers
  91. * @description all link pattern needed deal with
  92. */
  93. const fuckers = {
  94. acgrip: { match: 'https://bbs.acgrip.com/', redirect: removeFwinDialog },
  95. afdian: { match: 'https://afdian.net/link?target=', redirect: "target" },
  96. afdian2: { match: 'https://afdian.com/link?target=', redirect: "target" },
  97. baike: { match: 'https://www.baike.com/redirect_link?url=', redirect: "url" },
  98. blzxteam: { match: 'https://blzxteam.com/gowild.htm?url=', redirect: function () { const url = $("div._2VEbEOHfDtVWiQAJxSIrVi_0").first().attr("title"); window.location.href = url } },
  99. bookmarkearth: { match: 'https://www.bookmarkearth.com/view/', redirect: function () { window.location.replace(document.querySelector("p.link").innerHTML) } },
  100. chinaz: { match: 'https://www.chinaz.com/go.shtml?url=', redirect: "url" },
  101. coolapk: { match: 'https://www.coolapk.com/link?url=', redirect: "url" },
  102. csdn: { match: 'https://link.csdn.net/?*target=', redirect: "target" },
  103. cto51: { match: 'https://blog.51cto.com/transfer?', redirect: function () { window.location.href = window.location.href.replace("https://blog.51cto.com/transfer?", "") } },
  104. curseforge: { match: 'https://www.curseforge.com/linkout?remoteUrl=', redirect: function () { redirect(decodeURIComponent(curURL), 'remoteUrl') } },
  105. dilian: { match: 'https://link.ld246.com/forward?goto=', redirect: "goto" },
  106. developeraliyun: { match: 'https://developer.aliyun.com/redirect?target=', redirect: "target" },
  107. doc360_2: { match: 'http://www.360doc.cn/outlink.html?url=', redirect: "url" },
  108. doc360: { match: 'http://www.360doc.com/content/', redirect: function () { $("#articlecontent table tbody tr td#artContent").find("a").off("click") } },
  109. douban: { match: 'https://www.douban.com/link2/?url=', redirect: "url" },
  110. gamebilibili: { match: 'https://game.bilibili.com/linkfilter/?url=', redirect: "url" },
  111. gamertw: { match: 'https://ref.gamer.com.tw/redir.php/?url=', redirect: "url" },
  112. gamertw_2: { match: 'https://ref.gamer.com.tw/redir.php?url=', redirect: "url" },
  113. gcores: { match: 'https://www.gcores.com/link?target=', redirect: "target" },
  114. gitee: { match: 'https://gitee.com/link?target=', redirect: "target" },
  115. google: { match: 'https://www.google.com/url?q=', redirect: "q" },
  116. hellogithub: { match: 'https://hellogithub.com/periodical/statistics/click?target=', redirect: "target" },
  117. infoq: { match: 'https://(xie.infoq.cn/link|www.infoq.cn/link)?target=', redirect: "target", enableRegex: true },
  118. instagram: { match: 'https://www.instagram.com/linkshim/?u=', redirect: "url" },
  119. jianshu: { match: 'https://www.jianshu.com/go-wild?', redirect: "url" },
  120. juejin: { match: 'https://link.juejin.cn/?target=', redirect: "target" },
  121. kook: { match: 'https://www.kookapp.cn/go-wild.html?url=', redirect: "url" },
  122. latexstudio: { match: 'https://ask.latexstudio.net/go/index?url=', redirect: "url" },
  123. leetcode: { match: 'https://leetcode.cn/link/?target', redirect: "target" },
  124. linkedin: { match: 'https://www.linkedin.com/safety/go?url=', redirect: "url" },
  125. logonews: { match: 'https://link.logonews.cn/?', redirect: "url" },
  126. luogu: { match: 'https://www.luogu.com.cn/paste/', redirect: function () { if (document.getElementById("url")) { window.location.href = $("#url").text() } } },
  127. luogu_2: { match: 'https://www.luogu.com.cn/discuss/', redirect: function () { if (document.getElementById("url")) { window.location.href = $("#url").text() } } },
  128. luogu_3: { match: 'https://www.luogu.com.cn/article/', redirect: function () { if (document.getElementById("url")) { window.location.href = $("#url").text() } } },
  129. nga: { match: 'https://nga.178.com/read.php?', redirect: function () { $("#m_posts #m_posts_c a").prop("onclick", null).off("click") } },
  130. nga2: { match: 'https://bbs.nga.cn/read.php?', redirect: function () { $("#m_posts #m_posts_c a").prop("onclick", null).off("click") } },
  131. nodeseek: { match: 'https://www.nodeseek.com/jump?to=', redirect: "to" },
  132. nowcoder: { match: 'https://hd.nowcoder.com/link.html?target=', redirect: "target" },
  133. oschina: { match: 'https://www.oschina.net/action/GoToLink?url=', redirect: "url" },
  134. pixiv: { match: 'https://www.pixiv.net/jump.php?', redirect: function () { window.location.href = decodeURIComponent(curURL.match(/jump.php\?[url=]*(.*)/)[1].replace(/=$/, '')) } },
  135. qcc: { match: 'https://www.qcc.com/web/transfer-link?link=', redirect: "link" },
  136. qq: { match: 'https://c.pc.qq.com/(middleb|middlect|middlem|index).html', redirect: "pfurl", enableRegex: true },
  137. qq2: { match: 'https://c.pc.qq.com/(ios|pc|android).html', redirect: "url", enableRegex: true },
  138. qqdocs: { match: 'https://docs.qq.com/scenario/link.html?url=', redirect: "url" },
  139. qqmail: { match: 'https://mail.qq.com/cgi-bin/readtemplate', redirect: "gourl" },
  140. qqmailwx: { match: 'https://wx.mail.qq.com/xmspamcheck/xmsafejump', redirect: "url" },
  141. shimo: { match: 'https://shimo.im/outlink/black', redirect: "url" },
  142. shimo_2: { match: 'https://shimo.im/outlink/gray', redirect: "url" },
  143. sspai: { match: 'https://sspai.com/link?target=', redirect: "target" },
  144. steam: { match: 'https://steamcommunity.com/linkfilter/?url=', redirect: "url" },
  145. steam2: { match: 'https://steamcommunity.com/linkfilter/?u=', redirect: "u" },
  146. telegram: { match: 'https://t.me/iv?url=', redirect: "url" },
  147. tencentclouddev: { match: 'https://cloud.tencent.com/developer/tools/blog-entry?target=', redirect: "target" },
  148. tianyancha: { match: 'https://www.tianyancha.com/security?target=', redirect: "target" },
  149. tieba: { match: 'https://jump2.bdimg.com/safecheck/index?url=', redirect: function () { window.location.replace(document.getElementsByClassName('btn')[0].getAttribute('href')) } },
  150. tieba_2: { match: 'https://tieba.baidu.com/mo/q/checkurl?url=', redirect: "url" },
  151. txc: { match: 'https://(txc|support).qq.com/products?/(\\d+)/link-jump', enableRegex: true, redirect: 'jump' },
  152. uisdc: { match: 'https://link.uisdc.com/?redirect=', redirect: "redirect" },
  153. wechat1: { match: 'https://mp.weixin.qq.com/s/', redirect: enableURLs },
  154. wechat2: { match: 'https://weixin110.qq.com/cgi-bin/mmspamsupport-bin/newredirectconfirmcgi', redirect: function () { window.location.replace($(".weui-msg__desc").first().text()) } },
  155. wechat3: { match: 'https://mp.weixin.qq.com/s?', redirect: function () { let elem = $("#js_access_msg"); if (elem !== undefined && elem.attr("href") !== undefined) { window.location.replace(elem.attr("href")); } } },
  156. // https://t.cn/RgAKoPE
  157. // https://weibo.cn/sinaurl?luicode=10000011&lfid=230259&u=http%3A%2F%2Ft.cn%2FA6qHeVlf
  158. // https://weibo.cn/sinaurl?toasturl=https%3A%2F%2Ftime.geekbang.org%2F
  159. // https://weibo.cn/sinaurl?u=https%3A%2F%2Fwww.freebsd.org%2F
  160. weibo_1: {
  161. match: 'https://t.cn/', redirect: function () {
  162. const link = $(".wrap .link").first().text() || document.querySelector('.open-url').children[0].href;
  163. const url = new URL(link);
  164. url.searchParams.delete("continueFlag");
  165. window.location.replace(url.toString());
  166. }
  167. }, // 微博网页版
  168. weibo_2: { match: 'https://weibo.cn/sinaurl?u', redirect: "u" },
  169. weibo_3: { match: 'https://weibo.cn/sinaurl?toasturl', redirect: "toasturl" },
  170. weibo_4: {
  171. match: 'https://weibo.cn/sinaurl?', redirect: function () {
  172. const url = new URL(link);
  173. url.searchParams.delete("continueFlag");
  174. window.location.replace(url.toString());
  175. }
  176. },
  177. weixindev: { match: 'https://developers.weixin.qq.com/community/middlepage/href?href=', redirect: "href" },
  178. yuque: { match: 'https://www.yuque.com/r/goto?url=', redirect: "url" },
  179. youtube: { match: 'https://www.youtube.com/redirect?', redirect: "q" },
  180. yy: { match: 'http://redir.yy.duowan.com/warning.php?url=', redirect: "url" },
  181. zaker: { match: 'http://iphone.myzaker.com/zaker/link.php?', redirect: function () { redirect(curURL, "url", true) } },
  182. // https://link.zhihu.com/?target=https%3A%2F%2Ftime.geekbang.org%2F
  183. // https://link.zhihu.com/?utm_oi=35221042888704&target=https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/import
  184. zhihu: { match: 'https://link.zhihu.com/?', redirect: "target" },
  185. }
  186.  
  187. const curURL = window.location.href;
  188. const urlPattern = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g;
  189.  
  190. /**
  191. * Return URL without "http://" or "https://" at the beginning
  192. * @param {String} str
  193. */
  194. function removeProtocol(str) {
  195. return str.replace(/^https?\??:\/\//gm, '');
  196. }
  197.  
  198. function rstrip(str, regex) {
  199. let i = str.length - 1;
  200. while (i >= 0) {
  201. if (!str[i].match(regex)) {
  202. break;
  203. }
  204. i--;
  205. }
  206. return str.substring(0, i + 1);
  207. }
  208.  
  209. /**
  210. * Split concatenated URL string into separate URLs.
  211. * @param {String} str
  212. */
  213. function splitMultiURLs(str) {
  214. //TODO: add comments
  215. let results = new Array();
  216. let entry = "";
  217. while (str.length > 0) {
  218. if (str.indexOf("http:") === -1 && str.indexOf("https:") === -1) {
  219. entry += str;
  220. str = "";
  221. results.push(rstrip(entry, /[@:%_\+~#?&=,$^\*]/g));
  222. break;
  223. }
  224.  
  225. if (str.startsWith("http:")) {
  226. entry += "http:";
  227. str = str.substring("http:".length);
  228. } else if (str.startsWith("https:")) {
  229. entry += "https:";
  230. str = str.substring("https:".length);
  231. } else {
  232. return results;
  233. }
  234.  
  235. let nextIndex = Math.min(
  236. str.indexOf("https:") === -1 ? Number.MAX_SAFE_INTEGER : str.indexOf("https:"),
  237. str.indexOf("http:") === -1 ? Number.MAX_SAFE_INTEGER : str.indexOf("http:")
  238. );
  239. if (nextIndex > 0) {
  240. entry += str.substring(0, nextIndex);
  241. str = str.substring(nextIndex);
  242. }
  243. results.push(rstrip(entry, /[@:%_\+~#?&=,$^\*]/g));
  244. entry = "";
  245. }
  246. return results;
  247. }
  248.  
  249. /**
  250. * Replace url with clickable `<a>` tag in html content.
  251. * @param {String} url
  252. */
  253. function replaceSingleURL(url) {
  254. $("#js_content").html((_, html) => {
  255. return html.replaceAll(url, `<a target="_blank" rel="noopener noreferrer" href="${url}">${url}</a>`);
  256. });
  257. }
  258.  
  259. /**
  260. * Make urls clickable again on Weixin Media Platform.
  261. */
  262. function enableURLs() {
  263. let existingLinks = new Set();
  264. $("a").each(function () {
  265. existingLinks.add(this.href);
  266. });
  267.  
  268. $("#js_content > section").each(function (_, obj) {
  269. // Don't do anything on code blocks
  270. let className = $(obj).attr('class');
  271. if (className != undefined && className.indexOf("code-snippet__js") != -1) {
  272. return;
  273. }
  274. let content = $(obj).text();
  275. let urls = content.matchAll(urlPattern);
  276. let replaced = new Set();
  277. for (let value of urls) {
  278. let urlStr = $.trim(value[0]);
  279. for (let url of splitMultiURLs(urlStr)) {
  280. if (!url || replaced.has(url) || url.includes("localhost") || url.includes("127.0.0.1") || existingLinks.has(url)) {
  281. continue;
  282. }
  283. if (url.endsWith(".") && url[url.length - 2].match(/\d/g)) {
  284. url = url.substring(0, url.length - 2);
  285. }
  286. replaceSingleURL(url);
  287. replaced.add(url);
  288. }
  289. }
  290. });
  291.  
  292. // Replace loading image with actual one
  293. $("img").each(function (_, obj) {
  294. if ($(obj)[0].currentSrc === "data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==") {
  295. $(obj).attr("src", $(obj)[0].dataset.src);
  296. } else {
  297. $(obj).attr("src", $(obj).attr("data-src"));
  298. $(obj).attr("style", "width: 100% !important; height: auto !important; display: initial; visibility: visible !important;");
  299. }
  300. });
  301. $("span.js_img_placeholder").remove();
  302. }
  303.  
  304. /**
  305. * Remove the fwin_dialog when clicking external links on Anime Subtitle Club
  306. */
  307. function removeFwinDialog() {
  308. $("a").each((_, elem) => {
  309. if (elem.href && elem.href.startsWith("http") && !elem.href.includes(window.location.host)) {
  310. elem.addEventListener("click", (_) => {
  311. window.open(elem.href, "_blank");
  312. hideMenu('fwin_dialog', 'dialog');
  313. })
  314. }
  315. })
  316. }
  317.  
  318. function redirect(fakeURLStr, trueURLParam, enableBase64 = false) {
  319. let fakeURL = new URL(fakeURLStr);
  320. let trueURL = fakeURL.searchParams.get(trueURLParam);
  321. if (trueURL.startsWith(fuckers.wechat1.match)) {
  322. // there could be multiple `&`s in url of a wechat link, so all of them
  323. // have to be included in the trueURL.
  324. trueURL = fakeURL.search.split(`${trueURLParam}=`).pop();
  325. } else {
  326. if (enableBase64) trueURL = window.atob(trueURL);
  327. if (trueURL.indexOf("http://") !== 0 && trueURL.indexOf("https://") !== 0) {
  328. trueURL = "https://" + trueURL;
  329. }
  330. }
  331. trueURL = decodeURIComponent(trueURL)
  332. window.location.replace(trueURL);
  333. }
  334.  
  335. /**
  336. * @function
  337. * @name match
  338. * @param {...string} pattern
  339. * @param {...boolean} enableRegex
  340. * @param {...boolean} checkProtocol
  341. * @description check if current URL matchs given patterns
  342. */
  343. function match(pattern, enableRegex = false, checkProtocol = false) {
  344. var curURLProto;
  345. if (checkProtocol) { curURLProto = curURL; }
  346. else {
  347. curURLProto = removeProtocol(curURL);
  348. pattern = removeProtocol(pattern);
  349. }
  350. if (enableRegex) {
  351. return curURLProto.search(pattern) > -1
  352. }
  353. else {
  354. return curURLProto.indexOf(pattern) === 0//Not Sure
  355. }
  356. }
  357.  
  358. (function () {
  359. 'use strict';
  360.  
  361. $(document).ready(function () {
  362. for (var i in fuckers) {
  363. if (match(fuckers[i].match, fuckers[i].enableRegex, fuckers[i].checkProtocol)) {
  364. switch (typeof (fuckers[i].redirect)) {
  365. case 'string':
  366. redirect(curURL, fuckers[i].redirect); break;
  367. case 'function':
  368. fuckers[i].redirect(); break;
  369. default:
  370. console.log(i + " redirect rule error!"); break;
  371. }
  372. }
  373. }
  374. });
  375.  
  376. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址