From e5f80935dbd14fb5d7b3e923edc0f47fcab9b450 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Sun, 5 Jun 2022 22:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=AF=B9=E5=8F=B3=E4=B8=8B=E8=A7=92=E6=82=AC=E6=B5=AE=E7=9A=84?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Enhanced.user.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Zhihu-Enhanced.user.js b/Zhihu-Enhanced.user.js index 029aa31..4289e10 100644 --- a/Zhihu-Enhanced.user.js +++ b/Zhihu-Enhanced.user.js @@ -3,7 +3,7 @@ // @name:zh-CN 知乎增强 // @name:zh-TW 知乎增強 // @name:en Zhihu enhancement -// @version 2.0.8 +// @version 2.0.9 // @author X.I.U // @description 移除登录弹窗、屏蔽首页视频、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、屏蔽用户、屏蔽关键词、移除高亮链接、屏蔽盐选内容、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链 // @description:zh-TW 移除登錄彈窗、屏蔽首頁視頻、默認收起回答、快捷收起回答/評論、快捷回到頂部、屏蔽用戶、屏蔽關鍵詞、移除高亮鏈接、屏蔽鹽選內容、淨化搜索熱門、淨化標題消息、置頂顯示時間、完整問題時間、區分問題文章、默認高清原圖、默認站外直鏈... @@ -1118,6 +1118,8 @@ function removeLogin() { 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(); } } } @@ -1125,18 +1127,19 @@ function removeLogin() { // 未登录时才会监听并移除登录弹窗 if(location.hostname === 'zhuanlan.zhihu.com') { // 如果是文章页 - if (!document.querySelector('button.ColumnPageHeader-MenuToggler')) { // 未登录 + if (!document.querySelector('.ColumnPageHeader-profile>.AppHeader-menu')) { // 未登录 const observer = new MutationObserver(removeLoginModal); observer.observe(document, { childList: true, subtree: true }); + getXpath('//button[text()="登录/注册"]').outerHTML = '登录/注册'; // [登录] 按钮跳转至登录页面 } else { cleanTitles(); // 净化标题消息 } } else { // 不是文章页 - if (document.querySelector('button.AppHeader-login')) { // 未登录 + 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;}'; // 屏蔽问题页中间的登录提示 - document.querySelector('button.AppHeader-login').insertAdjacentHTML('afterend', '登录'); // [登录] 按钮跳转至登录页面 + getXpath('//button[text()="登录/注册"]').outerHTML = '登录/注册'; // [登录] 按钮跳转至登录页面 } else { cleanTitles(); // 净化标题消息 } @@ -1247,6 +1250,18 @@ function addUrlChangeEvent() { } +function getXpath(xpath, contextNode, doc = document) { + contextNode = contextNode || doc; + try { + const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); + // 应该总是返回一个元素节点 + return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue; + } catch (err) { + throw new Error(`无效 Xpath: ${xpath}`); + } +} + + // 显示问题作者 function question_author() { if (document.querySelector('.BrandQuestionSymbol, .QuestionAuthor')) return