分页: 1 / 1

geeksforgeeks网站禁用登录弹窗以及恢复滚动条js脚本

发表于 : 2023年 5月 30日 19:55
BobMaster
打开tampermonkey新建一个脚本,添加如下内容
在原版基础上增加了恢复滚动条的一条js指令。

代码: 全选

// ==UserScript==
// @name         GeeksForGeeks - Disable Login Popup and enable scrolling
// @namespace   https://github.com/DenverCoder1
// @namespace    https://github.com/hibobmaster
// @version      1.1
// @description  Disable Login Modal and enable scrolling on GeeksForGeeks.org
// @author       Jonah Lawrence, hibobmaster
// @match        https://www.geeksforgeeks.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    var VERSION = "1.1";

    window.addEventListener(
        "load",
        function () {
            console.info("'GeeksForGeeks - Disable Login Popup' Version " + VERSION + " started");

            // disable smartLogin function
            window.smartLogin = function () {
                console.info("'GeeksForGeeks - Disable Login Popup' Blocked 'smartLogin' function");
            };

            // make GeeksForGeeks not know how many times the user has visited the site
            localStorage.removeItem("gfgViewCount");

            // Hide login modal div with CSS in case it still appears
            document.head.insertAdjacentHTML(
                "beforeend",
                "<style>.login-modal-div, .spinner-loading-overlay { display: none !important; }</style>"
            );

            // Enable scrolling
            document.body.style.overflow = "visible";

            // When attempting to scroll, stop the scroll from being locked if gfg has locked the scroll
            window.addEventListener(
                "scroll",
                function () {
                    if (window.onscroll) {
                        window.onscroll = null;
                        document.body.style.position = "relative";
                        document.body.style.overflow = "unset";
                        console.info("'GeeksForGeeks - Disable Login Popup' Unlocked scroll");
                    }
                },
                { passive: true }
            );
        },
        false
    );
})();