Greasy Fork 支持简体中文。

Hide Verified X Users with Whitelist

Hide comments and posts from verified (blue check) users on Twitter (x.com) except whitelisted users

  1. // ==UserScript==
  2. // @name Hide Verified X Users with Whitelist
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-10-10
  5. // @description Hide comments and posts from verified (blue check) users on Twitter (x.com) except whitelisted users
  6. // @author You
  7. // @match *://x.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=x.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const whitelist = ["elonmusk"];
  17.  
  18. function hideBlueCheckUsers() {
  19. const posts = document.querySelectorAll('article');
  20. posts.forEach(post => {
  21. const usernameElement = post.querySelector('div[dir="ltr"] a[role="link"]');
  22. const blueCheck = post.querySelector('svg[data-testid="icon-verified"]');
  23.  
  24. if (blueCheck && usernameElement) {
  25. const username = usernameElement.getAttribute('href').replace('/', '').trim();
  26. if (!whitelist.includes(username)) {
  27. post.style.display = 'none';
  28. }
  29. }
  30. });
  31. }
  32.  
  33. function waitForElements() {
  34. const observer = new MutationObserver((mutations, obs) => {
  35. const posts = document.querySelectorAll('article');
  36. if (posts.length > 0) {
  37. hideBlueCheckUsers();
  38. obs.disconnect();
  39. const pageObserver = new MutationObserver(hideBlueCheckUsers);
  40. pageObserver.observe(document.body, { childList: true, subtree: true });
  41. }
  42. });
  43. observer.observe(document.body, { childList: true, subtree: true });
  44. }
  45.  
  46. waitForElements();
  47. })();