Simple Ad Blocker

A simple ad blocker for websites with annoying popups and banners

当前为 2025-05-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Simple Ad Blocker
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description A simple ad blocker for websites with annoying popups and banners
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // List of common ad element classes/IDs to target
  15. const adSelectors = [
  16. '.ad-banner', // Ad banners
  17. '.popup-ad', // Popup ads
  18. '#ad', // Single ad element
  19. '.advertisement'// Generic ad class
  20. ];
  21.  
  22. // Function to hide elements by their selectors
  23. function hideAds() {
  24. adSelectors.forEach(selector => {
  25. const ads = document.querySelectorAll(selector);
  26. ads.forEach(ad => ad.style.display = 'none');
  27. });
  28. }
  29.  
  30. // Run the function to hide ads
  31. hideAds();
  32.  
  33. // Optionally, you can set up an observer to catch dynamically loaded ads
  34. const observer = new MutationObserver(hideAds);
  35. observer.observe(document.body, { childList: true, subtree: true });
  36. })();