Greasy Fork

Greasy Fork is available in English.

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

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

目前为 2020-10-23 提交的版本。查看 最新版本

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

(function() {
    'use strict';

    //maxShow可以设置允许弹出几次,目前发现仅弹出1次,如果发现有2次弹出的情况,这里的maxShow设置为2即可
    var hideLogin = true, hideCount=0, maxShow = 1;
    //监听弹窗出现
    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){
            document.body.removeEventListener('DOMNodeInserted', DOMNodeInsertedEvent, false);
            document.body.removeEventListener('click', DOMClickEvent, false);
        }
    }
    document.body.addEventListener('DOMNodeInserted', DOMNodeInsertedEvent, false);
    //监听手动点击事件
    var DOMClickEvent = function(){
        hideLogin = false;
        setTimeout(function(){hideLogin = true;}, 100);
    }
    document.body.addEventListener('click', DOMClickEvent, false);

})();