Hide Advertisement at X/Twitter site

Hide specific advertisements at X/Twitter site

当前为 2024-03-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide Advertisement at X/Twitter site
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Hide specific advertisements at X/Twitter site
  6. // @author aspen138
  7. // @match *://x.com/*
  8. // @match *://*.x.com/*
  9. // @match *://twitter.com/*
  10. // @match *://*.twitter.com/*
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Function to hide ads
  19. function hideAds() {
  20. // Find all span elements that contain the text "Ad"
  21. document.querySelectorAll('span').forEach(span => {
  22. if (span.textContent.trim() === 'Ad') {
  23. // Find the closest parent article to the span and hide it
  24. let adArticle = span.closest('article');
  25. if (adArticle) {
  26. adArticle.style.display = 'none';
  27. }
  28. }
  29. });
  30. }
  31.  
  32. // Run the hideAds function on page load
  33. window.addEventListener('load', hideAds);
  34.  
  35. // Optionally, to account for dynamic content loading
  36. setInterval(hideAds, 5000); // Check every 5 seconds
  37. })();