Wanta

移除跳转外链提示

目前為 2022-10-17 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Wanta
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.2
  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. // @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
  12. // @grant none
  13. // @license unlicense
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. let debug = false;
  19. // domain: [link_prefix query_parameter main_article_path dynamic_query urldecode]
  20. let fuck = {
  21. 'www.jianshu.com': ['https://links.jianshu.com/go', 'to', 'article', '', true],
  22. 'juejin.cn': ['https://link.juejin.cn', 'target', '#juejin > div.view-container > main > div > div.main-area.article-area > article', ' > .article-content', true],
  23. 'gitee.com': ['https://gitee.com/link', 'target', '#git-readme > div > div.file_content.markdown-body', '', true],
  24. 'zhuanlan.zhihu.com': ['https://link.zhihu.com/', 'target', 'div.Post-RichTextContainer', '', true]
  25. };
  26. let domain = document.domain;
  27. let suffix = fuck[domain][0];
  28. let query_name = fuck[domain][1];
  29. let main_path = fuck[domain][2];
  30. let dynamic = fuck[domain][3];
  31. let urldecode = fuck[domain][4];
  32. let name = 'Wanta';
  33. function getQueryValue(url, query_string) {
  34. let index = url.indexOf('?');
  35. if (index == -1) return null;
  36. let search = url.slice(index + 1);
  37. let queries = search.split('&');
  38. for (let i = 0; i < queries.length; i++) {
  39. let query = queries[i].split('=');
  40. if (query[0] === query_string) return query[1];
  41. }
  42. return null;
  43. }
  44. // function removeSuffix(string, suffix) {
  45. // if (string.startsWith(suffix)) return string.slice(suffix.length);
  46. // else return string;
  47. // }
  48. function purify(link) {
  49. let new_href = getQueryValue(link.href, query_name);
  50. if (urldecode) new_href = decodeURIComponent(new_href);
  51. if (new_href) {
  52. link.href = new_href;
  53. if (debug) console.log(`[${name} DEBUG] ${link.href} -> ${new_href}`);
  54. return true;
  55. }
  56. else {
  57. console.log(`[${name}] Failed to purify below link element:`);
  58. console.log(link);
  59. return false;
  60. }
  61. }
  62. function main() {
  63. let links = document.querySelector(main_path + dynamic).getElementsByTagName('a');
  64. if (debug) console.log(links);
  65. let purified = 0;
  66. for (let i = 0;i < links.length; i++) {
  67. if (links[i].href.startsWith(suffix)) {
  68. if (purify(links[i])) purified++;
  69. } else if (debug) console.log(`[${name} DEBUG] Skipped "${links[i].href}".`);
  70. }
  71. console.log(`[${name}] Purified ${purified} links out of ${links.length} links.`);
  72. }
  73. if (dynamic) {
  74. const node = document.querySelector(main_path);
  75. const config = { attributes: false, childList: true, subtree: true };
  76. const callback = function(mutations, observer) {
  77. let article = node.querySelector(dynamic.slice(3));
  78. if (article) {
  79. main();
  80. observer.disconnect();
  81. }
  82. }
  83. const observer = new MutationObserver(callback);
  84. observer.observe(node, config);
  85. }
  86. else main();
  87. })();

QingJ © 2025

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