From 509e8da03d073cfd4c7d9285054e0802ed499111 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Tue, 29 Jul 2025 12:19:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8D=20[=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=BC=B9=E7=AA=97]=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Enhanced.user.js | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Zhihu-Enhanced.user.js b/Zhihu-Enhanced.user.js index 3b034e6..3e9a8ec 100644 --- a/Zhihu-Enhanced.user.js +++ b/Zhihu-Enhanced.user.js @@ -3,11 +3,11 @@ // @name:zh-CN 知乎增强 // @name:zh-TW 知乎增強 // @name:ru Улучшение Zhihu -// @version 2.3.15 +// @version 2.3.16 // @author X.I.U // @description A more personalized Zhihu experience~ -// @description:zh-CN 屏蔽指定类别(视频、盐选、文章、想法、关注[赞同了XX/关注了XX]等等)、屏蔽用户、屏蔽关键词、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、区分问题文章、移除高亮链接、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、直达问题按钮、默认站外直链... -// @description:zh-TW 屏蔽指定類別(視頻、鹽選、文章、想法、關注[贊同了XX/關注了XX]等等)、屏蔽用戶、屏蔽關鍵詞、默認收起回答、快捷收起回答/評論、快捷回到頂部、區分問題文章、移除高亮鏈接、默認高清原圖(無水印)、默認站外直鏈... +// @description:zh-CN 移除登录弹窗、屏蔽指定类别(视频、盐选、文章、想法、关注[赞同/关注了XX]等)、屏蔽用户、屏蔽关键词、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、区分问题文章、移除高亮链接、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、直达问题按钮、默认站外直链... +// @description:zh-TW 移除登錄彈窗、屏蔽指定類別(視頻、鹽選、文章、想法、關注[贊同/關注了XX]等)、屏蔽用戶、屏蔽關鍵詞、默認收起回答、快捷收起回答/評論、快捷回到頂部、區分問題文章、移除高亮鏈接、默認高清原圖(無水印)、默認站外直鏈... // @description:ru Более персонализированный опыт пользования сайтом Zhihu~ // @match *://www.zhihu.com/* // @match *://zhuanlan.zhihu.com/* @@ -1184,6 +1184,38 @@ function questionRichTextMore() { if (button) button.click() } +// 移除登录弹窗 +function removeLogin() { + const removeLoginModal = (mutationsList, observer) => { + for (const mutation of mutationsList) { + for (const target of mutation.addedNodes) { + if (target.nodeType != 1) return + if (target.querySelector('.signFlowModal')) { + let button = target.querySelector('.Button.Modal-closeButton.Button--plain'); + if (button) button.click(); + } else if (getXpath('//button[text()="立即登录/注册"]',target)) { + target.remove(); + } + } + } + }; + + // 未登录时才会监听并移除登录弹窗 + if(location.hostname === 'zhuanlan.zhihu.com') { // 如果是文章页 + if (!document.querySelector('.ColumnPageHeader-profile>.AppHeader-menu')) { // 未登录 + const observer = new MutationObserver(removeLoginModal); + observer.observe(document, { childList: true, subtree: true }); + if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '登录/注册'; // [登录] 按钮跳转至登录页面 + } + } else { // 不是文章页 + if (!document.querySelector('.AppHeader-profile>.AppHeader-menu')) { // 未登录 + const observer = new MutationObserver(removeLoginModal); + observer.observe(document, { childList: true, subtree: true }); + document.lastElementChild.appendChild(document.createElement('style')).textContent = '.Question-mainColumnLogin, button.AppHeader-login {display: none !important;}'; // 屏蔽问题页中间的登录提示 + if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '登录/注册'; // [登录] 按钮跳转至登录页面 + } + } +} // 净化标题消息 function cleanTitles() { @@ -1491,6 +1523,7 @@ function blockHotOther() { } }) + removeLogin(); // 移除登录弹窗,Violentmonkey 不能延迟执行这个 cleanTitles(); // 净化标题消息,不能延迟执行 // Violentmonkey 比 Tampermonkey 加载更早,会导致一些元素还没加载,因此需要延迟一会儿 // Tampermonkey 4.18.0 版本可能需要延迟一会执行