A-A+
油猴脚本 自动关闭知乎登陆窗口(登录弹窗)
通过模拟点击关闭按钮的JS代码如下:
// ==UserScript==
// @name 知乎自动关闭登录窗
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 尝试精确地关闭知乎登录窗口
// @AuThor icescat
// @match *://*.zhihu.com/*
// @grant none
// @run-at document-body
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 直接尝试点击关闭按钮
const tryClickCloseButton = () => {
const closeButton = document.querySelector('.Modal-closeButton');
if (closeButton) {
closeButton.click();
}
};
// 使用MutationObserver实时关闭后续出现的登录窗
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length) {
tryClickCloseButton(); // 如果出现新元素,尝试点击关闭按钮
}
});
});
const config = {
childList: true,
subtree: true
};
// 在文档加载后立即执行关闭操作,并开始监控DOM变化
document.addEventListener('DOMContentLoaded', () => {
tryClickCloseButton();
observer.observe(document.body, config);
});
})();
通过屏蔽CSS的油猴脚本 自动关闭知乎登陆窗口代码如下:
// ==UserScript==
// @name 知乎自动关闭登录窗
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 尝试精确地关闭知乎登录窗口
// @AuThor icescat
// @match *://*.zhihu.com/*
// @grant GM_addStyle
// @run-at document-start
// ==/UserScript==
GM_addStyle(`
/* 屏蔽登录弹窗 */
.Modal-wrapper.undefined.Modal-enter-done{
display: none !important;
}
/* 屏蔽右下角登录提示 */
.css-1wq6v87{
display: none !important;
}
/* 解锁滚动条 */
html{
overflow: unset !important;
}
/* 避免闪烁 */
.Modal-backdrop{
background-color: unset !important;
}
`)
文章来源:https://www.52pojie.cn/thread-1893982-1-1.html
布施恩德可便相知重
微信扫一扫打赏
支付宝扫一扫打赏