Facebook
From Mia, 1 Month ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 130
  1. // ==UserScript==
  2. // @name         Enhanced Spore Ad Blocker
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.2
  5. // @description  Enhanced ad blocking for www.spore.com
  6. // @author       You
  7. // @match        http://www.spore.com/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     // Add your ad blocking rules here
  15.     const adSelectors = [
  16.         '#ad-unit-id',
  17.         '.ad-container',
  18.         '[data-ad-slot]'
  19.     ];
  20.  
  21.     // Function to hide ads
  22.     const hideAds = (ads) => {
  23.         ads.forEach(ad => {
  24.             ad.style.display = 'none';
  25.         });
  26.     };
  27.  
  28.     // Get all ads and hide them
  29.     adSelectors.forEach(selector => {
  30.         const ads = document.querySelectorAll(selector);
  31.         hideAds(ads);
  32.     });
  33.  
  34.     // Extra feature: prevent ads from being shown again after hiding them
  35.     const observer = new MutationObserver((mutationsList, observer) => {
  36.         for(const mutation of mutationsList) {
  37.             if(mutation.addedNodes) {
  38.                 for(const node of mutation.addedNodes) {
  39.                     if(node.querySelectorAll) {
  40.                         const ads = node.querySelectorAll(adSelectors.join(', '));
  41.                         hideAds(ads);
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.     });
  47.  
  48.     observer.observe(document.body, { childList: true, subtree: true });
  49.  
  50. })();