Greasy Fork

Greasy Fork is available in English.

知乎屏蔽弹出登录框,不影响正常使用,比如手动点击登录,回答,关注,收藏等

不影响所有手动点击,真正随心所欲;屏蔽后自动停止监听,不浪费一丝系统资源。

当前为 2020-10-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         知乎屏蔽弹出登录框,不影响正常使用,比如手动点击登录,回答,关注,收藏等
// @namespace    http://tampermonkey.net/?zhihu-no-modal
// @version      0.1.4
// @description  不影响所有手动点击,真正随心所欲;屏蔽后自动停止监听,不浪费一丝系统资源。
// @author       Wilson
// @icon         https://static.zhihu.com/static/favicon.ico
// @match        *://www.zhihu.com/question/*
// ==/UserScript==

(function() {
    'use strict';

    //maxShow可以设置允许弹出几次,目前发现知乎有三种情况:不弹窗;弹窗1次;弹窗2次,保险起见这里按2次算吧
    var maxShow = 2;

    //监听弹窗出现
    var hideLogin = true, hideCount=0, removeEventTimer = 0;
    var DOMNodeInsertedEvent = function(e){
        if(!hideLogin || e.target.nodeType !== 1) return;
        var signFlowModal = e.target.getElementsByClassName('signFlowModal');
        if(signFlowModal.length!==0){
            for(var i in signFlowModal) if(signFlowModal[i] && signFlowModal[i].previousElementSibling) signFlowModal[i].previousElementSibling.click();
            hideCount++;

            //超过弹出限制取消监听事件,以节省资源
            if(hideCount >= maxShow){
                if(removeEventTimer) clearTimeout(removeEventTimer);
                removeEventTimer = setTimeout(function(){
                    document.body.removeEventListener('DOMNodeInserted', DOMNodeInsertedEvent, false);
                    document.body.removeEventListener('click', DOMClickEvent, false);
                }, 60000);
            }
        }
    }
    document.body.addEventListener('DOMNodeInserted', DOMNodeInsertedEvent, false);

    //监听手动点击事件
    var DOMClickEvent = function(){
        hideLogin = false;
        setTimeout(function(){ hideLogin = true; }, 100);
    }
    document.body.addEventListener('click', DOMClickEvent, false);

})();