Remove Blur Class Fixed

移除包含 'blur-' 前缀的类名,针对 Nexus Mods 网站

目前为 2024-10-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Remove Blur Class Fixed
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024.10.3
  5. // @description 移除包含 'blur-' 前缀的类名,针对 Nexus Mods 网站
  6. // @author You
  7. // @match https://www.nexusmods.com/*
  8. // @grant none
  9. // @run-at document-end
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. // 移除元素中所有以 'blur-' 开头的类,若是 BUTTON 则移除元素
  17. function cleanElement(element) {
  18. if (element.tagName === "BUTTON") {
  19. element.remove();
  20. return;
  21. }
  22. const classesToRemove = [...element.classList].filter(cls => cls.startsWith("blur-"));
  23. classesToRemove.forEach(cls => element.classList.remove(cls));
  24. }
  25.  
  26. // 处理现有元素
  27. function processElements() {
  28. document.querySelectorAll("[class*='blur-']").forEach(cleanElement);
  29. }
  30.  
  31. // 设置 MutationObserver 以监测 DOM 变化和类名变化
  32. function setupObserver() {
  33. const observer = new MutationObserver(mutations => {
  34. mutations.forEach(mutation => {
  35. if (mutation.type === 'childList') {
  36. mutation.addedNodes.forEach(node => {
  37. if (node.nodeType === Node.ELEMENT_NODE) {
  38. cleanElement(node);
  39. node.querySelectorAll("[class*='blur-']").forEach(cleanElement);
  40. }
  41. });
  42. } else if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
  43. const target = mutation.target;
  44. if (target.classList.contains('blur-') || [...target.classList].some(cls => cls.startsWith('blur-'))) {
  45. cleanElement(target);
  46. }
  47. }
  48. });
  49. });
  50.  
  51. observer.observe(document.body, {
  52. childList: true,
  53. subtree: true,
  54. attributes: true,
  55. attributeFilter: ['class']
  56. });
  57. }
  58.  
  59. // 初始化
  60. function init() {
  61. processElements();
  62. setupObserver();
  63. }
  64.  
  65. // 等待 DOM 完全加载后初始化
  66. if (document.readyState === "loading") {
  67. document.addEventListener("DOMContentLoaded", init);
  68. } else {
  69. init();
  70. }
  71. })();