🏠 返回首頁 

Greasy Fork is available in English.

Wanta

移除跳转外链提示


Installer dette script?
Skaberens foreslåede script

Du vil måske også kunne lide 去你妈的秒懂


Installer dette script
  1. // ==UserScript==
  2. // @name Wanta
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6.1
  5. // @description 移除跳转外链提示
  6. // @author PRO
  7. // @match *://www.jianshu.com/p/*
  8. // @match *://juejin.cn/post/*
  9. // @match *://gitee.com/*
  10. // @match *://zhuanlan.zhihu.com/*
  11. // @match *://*.feishu.cn/*
  12. // @match *://leetcode.cn/problems/*
  13. // @match *://weibo.com/*
  14. // @match *://www.mcmod.cn/*
  15. // @match *://play.mcmod.cn/*
  16. // @match *://www.mcbbs.net/*
  17. // @match *://www.minecraftforum.net/*
  18. // @match *://www.curseforge.com/minecraft/mc-mods/*
  19. // @match *://h5.qzone.qq.com/*
  20. // @icon https://greasyfork.org/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBMWhLQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--2831c7f8ea43fc8b8e3eed3818b98e88bb689285/%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%202022-07-16%20105357.png?locale=zh-CN
  21. // @grant none
  22. // @license gpl-3.0
  23. // ==/UserScript==
  24. (function () {
  25. 'use strict';
  26. const error = (...args) => console.error(`[Wanta ERROR]`, ...args);
  27. const debug = (...args) => console.log(`[Wanta DEBUG]`, ...args);
  28. // domain: [link_prefix query_parameter main_article_path decode_func]
  29. // query_parameter = '': Get the last part of url
  30. function same(orig) {
  31. return orig;
  32. }
  33. function b64Decode(orig) {
  34. return decodeURIComponent(atob(orig));
  35. }
  36. function mcmod(orig) {
  37. let parts = orig.split("@");
  38. return parts.map(b64Decode).join("?");
  39. }
  40. const #### = {
  41. 'www.jianshu.com': ['https://links.jianshu.com/go', 'to', 'article', decodeURIComponent],
  42. 'juejin.cn': ['https://link.juejin.cn', 'target', '#juejin > div.view-container > main > div > div.main-area.article-area > article', decodeURIComponent],
  43. 'gitee.com': ['https://gitee.com/link', 'target', '.markdown-body', decodeURIComponent],
  44. 'zhuanlan.zhihu.com': ['https://link.zhihu.com/', 'target', 'div.Post-RichTextContainer', decodeURIComponent],
  45. '.*\.feishu\.cn': ['https://security.feishu.cn/link/safety', 'target', 'div#mainBox', decodeURIComponent],
  46. 'leetcode.cn': ['https://leetcode.cn/link/', 'target', '#__next', same],
  47. 'weibo.com': ['https://weibo.cn/sinaurl?', 'u', '#app div[class^=Main_full]', decodeURIComponent],
  48. 'www.mcmod.cn': ['https://link.mcmod.cn/target/', '', 'body > div.col-lg-12.common-frame > div > div.col-lg-12.center > div.col-lg-12.right', mcmod],
  49. 'play.mcmod.cn': ['https://link.mcmod.cn/target/', '', 'body > div.col-lg-12.common-frame > div > div.col-lg-12.center', mcmod],
  50. 'www.mcbbs.net': ['https://www.mcbbs.net/plugin.php?id=link_redirect', 'target', 'div#ct', decodeURIComponent],
  51. 'www.minecraftforum.net': ['https://www.minecraftforum.net/linkout', 'remoteUrl', '.listing-container', decodeURIComponent],
  52. 'www.curseforge.com': ['https://www.curseforge.com/linkout', 'remoteUrl', '.project-page', decodeURIComponent],
  53. 'h5.qzone.qq.com': ['https://www.urlshare.cn/umirror_url_check', 'url', '#page-detail > .feed-list > .feed.dataItem', decodeURIComponent],
  54. };
  55. let domain = window.location.hostname;
  56. if (!(domain in ####)) {
  57. for (let d in ####) {
  58. if (domain.match(d)) {
  59. domain = d;
  60. break;
  61. }
  62. }
  63. }
  64. const prefix = ####[domain][0];
  65. const queryName = ####[domain][1];
  66. const mainPath = ####[domain][2];
  67. const decodeFunc = ####[domain][3];
  68. const attrFlag = "wanta-purified";
  69. const maxDepth = 5;
  70. function purify(link) {
  71. let new_href;
  72. if (queryName.length == 0) {
  73. let l = link.href.split('/');
  74. new_href = l[l.length - 1];
  75. } else {
  76. const params = new URL(link.href).searchParams;
  77. new_href = params.get(queryName);
  78. }
  79. try {
  80. new_href = decodeFunc(new_href);
  81. } catch (error) {
  82. error(`Failed to purify link "${link.href}".`)
  83. return false;
  84. }
  85. if (new_href) {
  86. debug(`${link.href} -> ${new_href}`);
  87. link.href = new_href;
  88. return true;
  89. } else {
  90. error(`Failed to purify link "${link.href}".`)
  91. return false;
  92. }
  93. }
  94. function handler(e) {
  95. let ele = e.target;
  96. for (let depth = 0; depth < maxDepth; depth++) {
  97. if (ele.hasAttribute(attrFlag)) {
  98. break;
  99. }
  100. if (ele.tagName == 'A') {
  101. debug(`Intercepted link: ${ele.href}`);
  102. if (!ele.href.startsWith(prefix) || purify(ele)) { // Note: If not starts with prefix, `purify` won't be called
  103. e.preventDefault();
  104. e.stopImmediatePropagation();
  105. ele.setAttribute(attrFlag, "success");
  106. ele.dispatchEvent(new MouseEvent(e.type, e));
  107. break;
  108. } else {
  109. ele.setAttribute(attrFlag, "failed");
  110. error(`Failed to purify link: ${ele.href}`);
  111. }
  112. }
  113. ele = ele.parentElement;
  114. }
  115. }
  116. const main_article = document.querySelector(mainPath);
  117. if (main_article) {
  118. main_article.addEventListener('mousedown', handler, true);
  119. main_article.addEventListener('click', handler, true);
  120. } else {
  121. error("Failed to find main article.");
  122. }
  123. })();