NewToki(Manatoki) Ad Blocker

Block ads on NewToki(Manatoki) sites

// ==UserScript==
// @name         NewToki(Manatoki) Ad Blocker
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Block ads on NewToki(Manatoki) sites
// @author       You
// @include      *://*.manatoki*/*
// @include      *://*.newtoki*/*
// @include      *://manatoki*/*
// @include      *://newtoki*/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function removeAds() {
        const adLinks = document.querySelectorAll('a[href*="bbs/linkbn.php"]');
        const count = adLinks.length;

        adLinks.forEach(link => {
            if (link.parentNode) {
                link.parentNode.removeChild(link);
            }
        });
        console.log(count + ' ads removed');
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', removeAds);
    } else {
        removeAds();
    }

    const observer = new MutationObserver(removeAds);

    function startObserver() {
        if (document.body) {
            observer.observe(document.body, { childList: true, subtree: true });
        } else {
            setTimeout(startObserver, 10);
        }
    }

    startObserver();

    // setInterval(removeAds, 1000);
})();