Open the F**king URL Right Now

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

目前為 2021-06-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Open the F**king URL Right Now
  3. // @description 自动跳转某些网站不希望用户直达的外链
  4. // @author OldPanda
  5. // @match http://t.cn/*
  6. // @match https://weibo.cn/sinaurl?*
  7. // @match https://www.jianshu.com/go-wild?*
  8. // @match https://link.zhihu.com/?*
  9. // @match http://link.zhihu.com/?*
  10. // @match https://www.douban.com/link2/?url=*
  11. // @match https://link.ld246.com/forward?goto=*
  12. // @match https://mp.weixin.qq.com/*
  13. // @match http://redir.yy.duowan.com/warning.php?url=*
  14. // @match https://weixin110.qq.com/cgi-bin/mmspamsupport-bin/newredirectconfirmcgi*
  15. // @match https://link.csdn.net/?target=*
  16. // @match https://steamcommunity.com/linkfilter/?url=*
  17. // @match https://game.bilibili.com/linkfilter/?url=*
  18. // @match https://www.oschina.net/action/GoToLink?url=*
  19. // @match https://developers.weixin.qq.com/community/middlepage/href?href=*
  20. // @match https://docs.qq.com/scenario/link.html?url=*
  21. // @match https://www.pixiv.net/jump.php?url=*
  22. // @match https://www.chinaz.com/go.shtml?url=*
  23. // @match http://www.360doc.com/content/*
  24. // @match https://nga.178.com/read.php?*
  25. // @match https://bbs.nga.cn/read.php?*
  26. // @match http*://c.pc.qq.com/*
  27. // @version 0.9.1
  28. // @run-at document-idle
  29. // @namespace https://old-panda.com/
  30. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  31. // @license GPLv3 License
  32. // ==/UserScript==
  33.  
  34. const $ = jQuery.noConflict(true);
  35. (function () {
  36. 'use strict';
  37.  
  38. const curURL = window.location.href
  39.  
  40. function rstrip(str, regex) {
  41. let i = str.length - 1;
  42. while (i >= 0) {
  43. if (!str[i].match(regex)) {
  44. break;
  45. }
  46. i--;
  47. }
  48. return str.substring(0, i + 1);
  49. }
  50.  
  51. /**
  52. * Split concatenated URL string into separate URLs.
  53. * @param {String} str
  54. */
  55. function splitMultiURLs(str) {
  56. let results = new Array();
  57. let entry = "";
  58. while (str.length > 0) {
  59. if (str.indexOf("http:") === -1 && str.indexOf("https:") === -1) {
  60. entry += str;
  61. str = "";
  62. results.push(rstrip(entry, /[@:%_\+~#?&=,$^\*]/g));
  63. break;
  64. }
  65.  
  66. if (str.startsWith("http:")) {
  67. entry += "http:";
  68. str = str.substring("http:".length);
  69. } else if (str.startsWith("https:")) {
  70. entry += "https:";
  71. str = str.substring("https:".length);
  72. } else {
  73. return results;
  74. }
  75.  
  76. let nextIndex = Math.min(
  77. str.indexOf("https:") === -1 ? Number.MAX_SAFE_INTEGER : str.indexOf("https:"),
  78. str.indexOf("http:") === -1 ? Number.MAX_SAFE_INTEGER : str.indexOf("http:")
  79. );
  80. if (nextIndex > 0) {
  81. entry += str.substring(0, nextIndex);
  82. str = str.substring(nextIndex);
  83. }
  84. results.push(rstrip(entry, /[@:%_\+~#?&=,$^\*]/g));
  85. entry = "";
  86. }
  87. return results;
  88. }
  89.  
  90. /**
  91. * Replace url with clickable `<a>` tag in html content.
  92. * @param {String} url
  93. */
  94. function replaceSingleURL(url) {
  95. $("#js_content").html((_, html) => {
  96. return html.replace(url, `<a target="_blank" rel="noopener noreferrer" href="${url}">${url}</a>`);
  97. });
  98. }
  99.  
  100. /**
  101. * Make urls clickable again on Weixin Media Platform.
  102. */
  103. function enableURLs() {
  104. let existingLinks = new Set();
  105. $("a").each(function () {
  106. existingLinks.add(this.href);
  107. });
  108.  
  109. let content = $("#js_content").text();
  110. let urls = content.matchAll(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
  111. let replaced = new Set();
  112. for (let value of urls) {
  113. let urlStr = $.trim(value[0]);
  114. for (let url of splitMultiURLs(urlStr)) {
  115. if (!url || replaced.has(url) || url.includes("localhost") || url.includes("127.0.0.1") || existingLinks.has(url)) {
  116. continue;
  117. }
  118. if (url.endsWith(".") && url[url.length - 2].match(/\d/g)) {
  119. url = url.substring(0, url.length - 2);
  120. }
  121. replaceSingleURL(url);
  122. replaced.add(url);
  123. }
  124. }
  125. }
  126.  
  127. function redirect(fakeURLStr, trueURLParam) {
  128. let fakeURL = new URL(fakeURLStr);
  129. let trueURL = fakeURL.searchParams.get(trueURLParam);
  130. window.location.replace(trueURL);
  131. }
  132.  
  133. /**
  134. * @function
  135. * @name match
  136. * @param {...string} patterns
  137. * @description check if current URL matchs given patterns
  138. */
  139. const match = (...patterns) => patterns.some(p => curURL.includes(p))
  140.  
  141. /**
  142. * @function
  143. * @name matchRegex
  144. * @param {...string} patterns regex patterns
  145. * @description check if current URL matchs given regex patterns
  146. */
  147. const matchRegex = (...patterns) => patterns.some(p => curURL.search(p) > -1)
  148.  
  149. /**
  150. * @enum {string}
  151. * @name fuckers
  152. * @description all link pattern needed deal with
  153. */
  154. const fuckers = {
  155. weibo: 'http://t.cn/', // 微博网页版
  156. weibo2: 'https://weibo.cn/sinaurl?',
  157. // http://t.cn/RgAKoPE
  158. // https://weibo.cn/sinaurl?u=https%3A%2F%2Fwww.freebsd.org%2F
  159. // https://weibo.cn/sinaurl?toasturl=https%3A%2F%2Ftime.geekbang.org%2F
  160. // https://weibo.cn/sinaurl?luicode=10000011&lfid=230259&u=http%3A%2F%2Ft.cn%2FA6qHeVlf
  161. jianshu: 'https://www.jianshu.com/go-wild?',
  162. zhihu: 'https://link.zhihu.com/?',
  163. zhihu2: 'http://link.zhihu.com/?',
  164. // https://link.zhihu.com/?target=https%3A%2F%2Ftime.geekbang.org%2F
  165. // https://link.zhihu.com/?target=https%3A%2F%2Fwww.freebsd.org%2F
  166. // https://link.zhihu.com/?utm_oi=35221042888704&target=https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/import
  167. douban: 'https://www.douban.com/link2/?url=',
  168. dilian: 'https://link.ld246.com/forward?goto=',
  169. theWorst: 'https://mp.weixin.qq.com/',
  170. theWorst2: 'https://weixin110.qq.com/cgi-bin/mmspamsupport-bin/newredirectconfirmcgi',
  171. yy: 'http://redir.yy.duowan.com/warning.php?url=',
  172. csdn: 'https://link.csdn.net/?target=',
  173. steam: 'https://steamcommunity.com/linkfilter/?url=',
  174. gamebilibili: 'game.bilibili.com/linkfilter/?url=',
  175. oschina: 'https://www.oschina.net/action/GoToLink?url=',
  176. weixindev: 'https://developers.weixin.qq.com/community/middlepage/href?href=',
  177. qqdocs: 'https://docs.qq.com/scenario/link.html?url=',
  178. pixiv: 'https://www.pixiv.net/jump.php?url=',
  179. chinaz: 'https://www.chinaz.com/go.shtml?url=',
  180. doc360: 'http://www.360doc.com/content/',
  181. nga: 'https://nga.178.com/read.php?',
  182. nga2: 'https://bbs.nga.cn/read.php?',
  183. qq: 'https?\://c.pc.qq.com/(middlem|index).html'
  184. }
  185.  
  186. $(document).ready(function () {
  187. if (match(fuckers.weibo, fuckers.weibo2)) {
  188. const link = $(".wrap .link").first().text() || document.querySelector('.open-url').children[0].href
  189. window.location.replace(link);
  190. }
  191. if (match(fuckers.jianshu)) {
  192. redirect(curURL, "url");
  193. }
  194. if (match(fuckers.zhihu, fuckers.zhihu2)) {
  195. redirect(curURL, "target");
  196. }
  197. if (match(fuckers.douban)) {
  198. redirect(curURL, "url");
  199. }
  200. if (match(fuckers.dilian)) {
  201. redirect(curURL, "goto");
  202. }
  203. if (match(fuckers.theWorst)) {
  204. enableURLs();
  205. }
  206. if (match(fuckers.yy)) {
  207. redirect(curURL, "url");
  208. }
  209. if (match(fuckers.theWorst2)) {
  210. window.location.replace($(".weui-msg__desc").first().text());
  211. }
  212. if (match(fuckers.csdn)) {
  213. redirect(curURL, "target");
  214. }
  215. if (match(fuckers.steam)) {
  216. redirect(curURL, "url");
  217. }
  218. if (match(fuckers.gamebilibili)) {
  219. redirect(curURL, "url");
  220. }
  221. if (match(fuckers.oschina)) {
  222. redirect(curURL, "url");
  223. }
  224. if (match(fuckers.weixindev)) {
  225. redirect(curURL, "href");
  226. }
  227. if (match(fuckers.qqdocs)) {
  228. redirect(curURL, "url");
  229. }
  230. if (match(fuckers.pixiv)) {
  231. redirect(curURL, "url");
  232. }
  233. if (match(fuckers.chinaz)) {
  234. redirect(curURL, "url");
  235. }
  236. if (match(fuckers.doc360)) {
  237. $("#articlecontent table tbody tr td#artContent").find("a").off("click");
  238. }
  239. if (match(fuckers.nga, fuckers.nga2)) {
  240. $("#m_posts #m_posts_c a").prop("onclick", null).off("click");
  241. }
  242. if (matchRegex(fuckers.qq)){
  243. redirect(curURL, "pfurl");
  244. }
  245. });
  246.  
  247. })();

QingJ © 2025

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