block xui auto generate path

防止某些版本的xui在查看path时自动更改path

  1. // ==UserScript==
  2. // @name block xui auto generate path
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 防止某些版本的xui在查看path时自动更改path
  6. // @author LeiFeng
  7. // @match http://*/xui/*
  8. // @match http://*/*/xui/*
  9. // @match https://*/xui/*
  10. // @match https://*/*/xui/*
  11. // @license MIT
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. "use strict";
  18.  
  19. // 在页面解析时立即执行,替换相关代码
  20. const observer = new MutationObserver((mutations) => {
  21. mutations.forEach((mutation) => {
  22. mutation.addedNodes.forEach((node) => {
  23. if (node.nodeType === 1 && node.tagName === "SCRIPT") {
  24. const scriptContent = node.innerHTML;
  25. if (
  26. scriptContent.includes(
  27. "if (this.oldAllSetting.webBasePath === '/')"
  28. )
  29. ) {
  30. // 替换判断条件为false
  31. node.innerHTML = scriptContent.replace(
  32. "if (this.oldAllSetting.webBasePath === '/')",
  33. "if (false)"
  34. );
  35. console.log("判断条件已被替换为false");
  36. }
  37. }
  38. });
  39. });
  40. });
  41.  
  42. // 开始监听整个文档的变化
  43. observer.observe(document.documentElement, {
  44. childList: true,
  45. subtree: true,
  46. });
  47. })();