Greasy Fork 还支持 简体中文。

block-users

clean the world

  1. // ==UserScript==
  2. // @name block-users
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-10-21
  5. // @description clean the world
  6. // @author misc
  7. // @match https://www.uscardforum.com/*
  8. // @icon https://asset-cdn.uscardforum.com/optimized/1X/05236f295ec6a40bdd5588b3d35a04d01ebfb67e_2_32x32.png
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. const users = [];
  13.  
  14. function getSelector(users) {
  15. return users
  16. .map((user) => {
  17. const post = `[aria-label^="@${user}"]`;
  18. const quote = `aside[data-username="${user}"]`;
  19. const card = `a[data-user-card="${user}"]`;
  20. const gap = `.gap`;
  21. return `${post},${quote},${card}`;
  22. })
  23. .join(',');
  24. }
  25.  
  26. function hideElements(users) {
  27. const selector = getSelector(users);
  28. const els = document.querySelectorAll(selector);
  29. els.forEach((el) => {
  30. el.classList.add('hide');
  31. });
  32. }
  33.  
  34. function hideReply(users) {
  35. const selector = users.map((user) => `img.avatar[title="${user}"]`).join(',');
  36. const els = document.querySelectorAll(selector);
  37. els.forEach((el) => {
  38. el.closest('.reply-to-tab')?.classList.add('hide');
  39. });
  40. }
  41.  
  42. function hideGap() {
  43. const els = document.querySelectorAll('.gap');
  44.  
  45. els.forEach((el) => {
  46. if (el.textContent.includes('隐藏回复')) {
  47. el.classList.add('hide');
  48. }
  49. });
  50. }
  51.  
  52. function debounce(fn) {
  53. let raf;
  54. return function (...args) {
  55. if (raf) {
  56. cancelAnimationFrame(raf);
  57. }
  58.  
  59. raf = requestAnimationFrame(() => {
  60. fn.apply(this, args);
  61. });
  62. };
  63. }
  64.  
  65. function modifyDOM() {
  66. hideElements(users);
  67. hideReply(users);
  68. hideGap();
  69. }
  70.  
  71. (function () {
  72. 'use strict';
  73. const observer = new MutationObserver(debounce(modifyDOM));
  74. observer.observe(document.body, { childList: true, subtree: true });
  75. modifyDOM();
  76. })();
  77.