Senpa.io v1

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

当前为 2024-06-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Senpa.io v1
// @namespace    http://tampermonkey.net/
// @version      1.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 });

})();