Puujee0238 / Mongolian Movie site's skipper

// ==UserScript==
// @name         Mongolian Movie site's skipper
// @author       HAWK
// @namespace    HAWK
// @version      0.5
// @author       You
// @license      MIT
// @description  Skip ads and redirects on Mongolian movie sites
// @match        https://fishlovingworld.com/
// @match        https://fishlovingworld.com/*
// @match        https://hdplayer.icu/index.php?*
// @match        https://mobile720.info/?page_id=*
// @match        https://koreanbeauty.club/
// @match        https://koreanbeauty.club/*
// @match        https://mglguide.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const regex = /http:\/\/hdplayer\.icu\/index\.php\?id=\d+&key=[a-f0-9]+/i;
    let attempts = 0;
    const maxAttempts = 3;
    const delay = 3000; // 3 seconds in milliseconds
    const gizleSites = ['mobile720.info'];
    const host = window.location.hostname;

    function findAndAlertMatch() {
        const html = document.documentElement.innerHTML;
        const match = html.match(regex);
        if (match) {
            //alert(`Match found: ${match[0]}`);
            window.open(match[0])
        } else if (attempts < maxAttempts) {
            attempts++;
            setTimeout(findAndAlertMatch, delay);
        }
    }

    // Observe changes to the document's HTML
    const observer = new MutationObserver(() => {
        observer.disconnect(); // Stop observing
        findAndAlertMatch();
    });

    // Observe the <html> element for additions

    if (host == 'fishlovingworld.com') {
        observer.observe(document.documentElement, { childList: true, subtree: true });
    }

    window.addEventListener('DOMContentLoaded', function () {
        console.log('DOMContentLoaded', new Date().toLocaleTimeString());
        if (gizleSites.includes(host)) {
            try{
                gizle();
            } catch(e) {
            }
            try{
                Shiljih();
            } catch(e) {
            }

        }
    });

    window.addEventListener('load', function () {
        handleLoadEvents();
    }, false);

    function handleLoadEvents() {
        console.log('load', new Date().toLocaleTimeString());
        if (gizleSites.includes(host)) {
            tryRedirect("#noads > a");
            tryRedirect("#noads > center > a");
        }
        if (host === 'koreanbeauty.club') {
            removeAds('.module_single_ads');
            createButton('#ads', Shiljih);
        }
        if (host === 'mglguide.com') {
            tryClick('#wpsafe-link > a');
        }
        if (host === 'hdplayer.icu') {
            setTimeout(() => {
                tryRemove('html > iframe');
            }, 3000);
            tryClick('.haah');
        }
    }

    function tryRedirect(selector) {
        try {
            window.location = document.querySelector(selector)['href'];
        } catch (error) {}
    }

    function tryClick(selector) {
        try {
            document.querySelector(selector).click();
        } catch (error) {}
    }

    function tryRemove(selector) {
        try {
            document.querySelector(selector).remove();
        } catch (error) {}
    }

    function removeAds(selector) {
        setTimeout(() => {
            try {
                document.querySelector(selector).classList.remove('module_single_ads');
            } catch (error) {}
        }, 3000);
    }

    function createButton(adsSelector, action) {
        try {
            const adsDiv = document.querySelector(adsSelector);
            const button = document.createElement("button");
            button.textContent = "CLICK ME";
            adsDiv.parentNode.insertBefore(button, adsDiv);
            button.addEventListener("click", action);
        } catch (error) {}
    }

})();