Wanta

移除跳转外链提示

当前为 2023-04-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Wanta
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.3
  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 *://www.mcmod.cn/*
  14. // @match *://play.mcmod.cn/*
  15. // @match *://www.mcbbs.net/*
  16. // @icon https://gf.qytechs.cn/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
  17. // @grant none
  18. // @license unlicense
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23. let debug = false;
  24. // domain: [link_prefix query_parameter main_article_path dynamic_query decode_func always_listen]
  25. // query_parameter = '': Get the last part of url
  26. function same(orig) {
  27. return orig;
  28. }
  29. function b64Decode(orig) {
  30. return decodeURIComponent(atob(orig));
  31. }
  32.  
  33. let fuck = {
  34. 'www.jianshu.com': ['https://links.jianshu.com/go', 'to', 'article', '', decodeURIComponent, false],
  35. 'juejin.cn': ['https://link.juejin.cn', 'target', '#juejin > div.view-container > main > div > div.main-area.article-area > article', ' > .article-content', decodeURIComponent, false],
  36. 'gitee.com': ['https://gitee.com/link', 'target', '.markdown-body', '', decodeURIComponent, false],
  37. 'zhuanlan.zhihu.com': ['https://link.zhihu.com/', 'target', 'div.Post-RichTextContainer', '', decodeURIComponent, false],
  38. '.*\.feishu\.cn': ['https://security.feishu.cn/link/safety', 'target', 'div#mainBox', ' div.mindnote-paper', decodeURIComponent, false],
  39. 'leetcode.cn': ['https://leetcode.cn/link/', 'target', '#app', ' div#question-detail-main-tabs', same, true],
  40. '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', '', b64Decode, false],
  41. 'play.mcmod.cn': ['https://link.mcmod.cn/target/', '', 'body > div.col-lg-12.common-frame > div > div.col-lg-12.center', '', b64Decode, false],
  42. 'www.mcbbs.net': ['https://www.mcbbs.net/plugin.php', 'target', 'div#ct', '', decodeURIComponent, false]
  43. };
  44. let domain = document.domain;
  45. if (!(domain in fuck)) {
  46. for (let d in fuck) {
  47. if (domain.match(d)) {
  48. domain = d;
  49. break;
  50. }
  51. }
  52. }
  53. let suffix = fuck[domain][0];
  54. let query_name = fuck[domain][1];
  55. let main_path = fuck[domain][2];
  56. let dynamic = fuck[domain][3];
  57. let decode_func = fuck[domain][4];
  58. let always_listen = fuck[domain][5];
  59. let name = 'Wanta';
  60.  
  61. function purify(link) {
  62. let new_href;
  63. if (query_name.length == 0) {
  64. let l = link.href.split('/');
  65. new_href = l[l.length - 1];
  66. } else {
  67. let params = new URL(link.href).searchParams;
  68. new_href = params.get(query_name);
  69. }
  70. new_href = decode_func(new_href);
  71. if (new_href) {
  72. if (debug) console.log(`[${name} DEBUG] ${link.href} -> ${new_href}`);
  73. link.href = new_href;
  74. return true;
  75. }
  76. else {
  77. console.log(`[${name}] Failed to purify below link element:`);
  78. console.log(link);
  79. return false;
  80. }
  81. }
  82. function main() {
  83. let target_node = document.querySelector(main_path + dynamic);
  84. let links;
  85. if (target_node) {
  86. links = target_node.getElementsByTagName('a');
  87. } else {
  88. return;
  89. }
  90. if (debug) console.log(links);
  91. let purified = 0;
  92. for (let i = 0;i < links.length; i++) {
  93. if (links[i].href.startsWith(suffix)) {
  94. if (purify(links[i])) purified++;
  95. } else if (debug) console.log(`[${name} DEBUG] Skipped "${links[i].href}".`);
  96. }
  97. console.log(`[${name}] Purified ${purified} links out of ${links.length} links.`);
  98. }
  99. if (dynamic) {
  100. const node = document.querySelector(main_path);
  101. const config = { attributes: false, childList: true, subtree: true };
  102. const callback = function(mutations, observer) {
  103. let article = node.querySelector(dynamic.slice(3));
  104. if (article) {
  105. main();
  106. if (!always_listen)
  107. observer.disconnect();
  108. }
  109. }
  110. const observer = new MutationObserver(callback);
  111. observer.observe(node, config);
  112. }
  113. else main();
  114. })();

QingJ © 2025

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