Greasy Fork

Senpa+

Automatically close the Continue window and remove ads from Senpa.io

目前为 2024-06-24 提交的版本。查看 最新版本

// ==UserScript==
// @name         Senpa+
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Automatically close the Continue window and remove ads from Senpa.io
// @author       ChatGPT
// @match        https://senpa.io/web/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to simulate the pressing of the "Esc" key
    function triggerEscKey() {
        var event = new KeyboardEvent('keydown', {
            bubbles: true,
            cancelable: true,
            keyCode: 27,
            key: 'Escape',
            code: 'Escape'
        });
        document.dispatchEvent(event);
    }

    // Function to detect the respawn window and trigger the "Esc" key
    function checkRespawnWindow() {
        var respawnWindow = document.querySelector('.modal.scale-modal');
        if (respawnWindow && getComputedStyle(respawnWindow).opacity === '1') {
            console.log('Respawn window detected, triggering Esc key...');
            setTimeout(triggerEscKey, 10);
        }
    }

    // Function to remove ads and social sidebar
    function removeAdsAndSocialSidebar() {
        // Remove div with id "bottomAd"
        var bottomAdDiv = document.getElementById("bottomAd");
        if (bottomAdDiv) {
            bottomAdDiv.parentNode.removeChild(bottomAdDiv);
        }

        // Remove divs with class "ads-block-1"
        var adsBlockDivs = document.querySelectorAll(".ads-block-1");
        adsBlockDivs.forEach(function(adsBlockDiv) {
            adsBlockDiv.parentNode.removeChild(adsBlockDiv);
        });

        // Remove divs with class "banner"
        var bannerDivs = document.querySelectorAll(".banner");
        bannerDivs.forEach(function(bannerDiv) {
            bannerDiv.parentNode.removeChild(bannerDiv);
        });

        // Remove divs with class "advertisement-informer-endgame"
        var advertisementInformerEndgameDivs = document.querySelectorAll(".advertisement-informer-endgame");
        advertisementInformerEndgameDivs.forEach(function(advertisementInformerEndgameDiv) {
            advertisementInformerEndgameDiv.parentNode.removeChild(advertisementInformerEndgameDiv);
        });

        // Remove div with id "senpa-io_300x250_3"
        var senpaIoDiv = document.getElementById("senpa-io_300x250_3");
        if (senpaIoDiv) {
            senpaIoDiv.parentNode.removeChild(senpaIoDiv);
        }

        // Remove ul with id "socialsidebar"
        var socialSidebarUl = document.getElementById("socialsidebar");
        if (socialSidebarUl) {
            socialSidebarUl.parentNode.removeChild(socialSidebarUl);
        }
    }

    // Check for the respawn window periodically
    setInterval(checkRespawnWindow, 150);

    // Wait for the DOM to be fully loaded and then remove ads and social sidebar
    window.addEventListener('load', removeAdsAndSocialSidebar);

    // Observe DOM mutations to remove ads and social sidebar dynamically
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes.length) {
                removeAdsAndSocialSidebar();
            }
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });

})();