Remove Popup Ads on mp4upload.com & aniwave.to

Remove all popup ads on both mp4upload.com and aniwave.to, including within media players

目前為 2024-04-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Remove Popup Ads on mp4upload.com & aniwave.to
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Remove all popup ads on both mp4upload.com and aniwave.to, including within media players
// @author       Goku
// @match        https://www.mp4upload.com/*
// @match        https://aniwave.to/*
// @grant        GM_config
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    // Function to remove popup ads indefinitely
    function removePopupAds() {
        // Remove popups every second from the whole page
        setInterval(function() {
            removePopups(document.body);
        }, 1000); // Check every 1 second

        // Remove popups every second from the player wrapper on aniwave.to
        if (window.location.hostname === 'aniwave.to') {
            var playerWrapper = document.getElementById('player-wrapper');
            if (playerWrapper) {
                setInterval(function() {
                    removePopups(playerWrapper);
                }, 1000); // Check every 1 second
            }
        }
    }

    // Function to remove popups within a specific container
    function removePopups(container) {
        var popupAds = container.querySelectorAll('a[href^="http://"]');
        popupAds.forEach(function(popupAd) {
            popupAd.remove();
        });
    }

    // Function to activate the popup blocker
    function activateBlocker() {
        var global = unsafeWindow; // Reference to page's "window" through GreaseMonkey

        // Helper to create a button with inner text @text executing onclick @clickCallback
        var putButton = function (logDiv, text, clickCallback, inlineStyle) {
            var button = document.createElement("button");
            button.innerHTML = text;
            button.style.cssText = "text-decoration:none; color:black; cursor:pointer; \
                margin: 0 5px; font: 8pt microsoft sans serif; padding: 1px 3px; \
                background-color:rgb(212,208,200); border-width:2px; border-style:outset; \
                border-color:#eee #555 #555 #eee; color:black;" + inlineStyle;
            logDiv.appendChild(button);
            button.addEventListener("click", clickCallback);
        };

        // Storing a reference to real "window.open" method
        var realWindowOpen = global.open;

        // This function will be called each time a script wants to open a new window
        var fakeWindowOpen = function(url) {
            console.log('Popup blocked: ', url);
            return false;
        };

        // Override browser's "window.open" with our own implementation
        global.open = fakeWindowOpen;

        console.log('[Popup Blocker] Activated');
    }

    // Check if the current domain is whitelisted
    function isCurrentDomainWhiteListed() {
        var domains = getDomainsArray(document.domain);
        var whitelisted = domains.some(function(d) {
            return GM_getValue("whitelisted_" + d);
        });
        return whitelisted;
    }

    // Get array of domains for which it would make sense to whitelist them
    function getDomainsArray(documentDomain) {
        var d1 = documentDomain;
        var domainsArr = [];

        var lastDot1 = d1.lastIndexOf('.');
        if (lastDot1 != -1) {
            var lastDot2 = d1.lastIndexOf('.', lastDot1 - 1);
            if (lastDot2 != -1 && lastDot2 != lastDot1) {
                var d2 = d1.substr(lastDot2 + 1);
                domainsArr.push(d2);

                var lastDot3 = d1.lastIndexOf('.', lastDot2 - 1);
                if (lastDot3 != -1 && lastDot3 != lastDot2) {
                    var d3 = d1.substr(lastDot3 + 1);
                    domainsArr.push(d3);
                }
            }
        }

        domainsArr.push(d1);
        return domainsArr;
    }

    // Wait for 1 second before starting to remove popups
    setTimeout(removePopupAds, 1000);

    // Check if the current domain is whitelisted, if not, activate the popup blocker
    var disabled = isCurrentDomainWhiteListed();
    if (!disabled) {
        activateBlocker();
    }
})();