FUXX V2EX || V2EX REDIRECT

Modify all V2EX links to use global.v2ex.co

  1. // ==UserScript==
  2. // @name FUXX V2EX || V2EX REDIRECT
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Modify all V2EX links to use global.v2ex.co
  6. // @author systemoutprintlnhelloworld
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-end
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const DEBUG_MODE = true;
  17.  
  18. // 检查并修改链接
  19. function modifyLinks() {
  20. // 获取所有链接
  21. let links = document.querySelectorAll('a[href*="v2ex.com"]');
  22.  
  23. // 遍历所有链接
  24. links.forEach(function(link) {
  25. // 如果链接包含 .v2ex.com 或 v2ex.com,则替换为 global.v2ex.co
  26. if (/v2ex\.com/.test(link.href)) {
  27. let newHref = link.href.replace(/:\/\/(.*\.)?v2ex\.com/, '://global.v2ex.co');
  28. if (DEBUG_MODE) {
  29. console.log(`Modifying link: ${link.href} to ${newHref}`);
  30. }
  31. link.href = newHref;
  32. }
  33. });
  34. }
  35.  
  36. // 初始修改
  37. modifyLinks();
  38.  
  39. // 监听DOM变化,动态修改新增的链接
  40. let observer = new MutationObserver(function(mutations) {
  41. mutations.forEach(function(mutation) {
  42. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  43. modifyLinks();
  44. }
  45. });
  46. });
  47.  
  48. observer.observe(document.body, { childList: true, subtree: true });
  49. })();

QingJ © 2025

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