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

分享讨论IT相关的内容
回复
头像
BobMaster
锋芒初露
锋芒初露
帖子: 1186
注册时间: 2020年 12月 7日 08:05
来自: 神秘的东方
我的状态: 🎯
为圈友点赞: 338 次
被赞次数: 177 次
联系:

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

帖子 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
    );
})();
人生如音乐,欢乐且自由
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 1 访客