|
3 | 3 | // @name:zh-CN 知乎增强 |
4 | 4 | // @name:zh-TW 知乎增強 |
5 | 5 | // @name:en Zhihu enhancement |
6 | | -// @version 2.0.8 |
| 6 | +// @version 2.0.9 |
7 | 7 | // @author X.I.U |
8 | 8 | // @description 移除登录弹窗、屏蔽首页视频、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、屏蔽用户、屏蔽关键词、移除高亮链接、屏蔽盐选内容、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链 |
9 | 9 | // @description:zh-TW 移除登錄彈窗、屏蔽首頁視頻、默認收起回答、快捷收起回答/評論、快捷回到頂部、屏蔽用戶、屏蔽關鍵詞、移除高亮鏈接、屏蔽鹽選內容、淨化搜索熱門、淨化標題消息、置頂顯示時間、完整問題時間、區分問題文章、默認高清原圖、默認站外直鏈... |
@@ -1118,25 +1118,28 @@ function removeLogin() { |
1118 | 1118 | if (target.querySelector('.signFlowModal')) { |
1119 | 1119 | let button = target.querySelector('.Button.Modal-closeButton.Button--plain'); |
1120 | 1120 | if (button) button.click(); |
| 1121 | + } else if (getXpath('//button[text()="立即登录/注册"]',target)) { |
| 1122 | + target.remove(); |
1121 | 1123 | } |
1122 | 1124 | } |
1123 | 1125 | } |
1124 | 1126 | }; |
1125 | 1127 |
|
1126 | 1128 | // 未登录时才会监听并移除登录弹窗 |
1127 | 1129 | if(location.hostname === 'zhuanlan.zhihu.com') { // 如果是文章页 |
1128 | | - if (!document.querySelector('button.ColumnPageHeader-MenuToggler')) { // 未登录 |
| 1130 | + if (!document.querySelector('.ColumnPageHeader-profile>.AppHeader-menu')) { // 未登录 |
1129 | 1131 | const observer = new MutationObserver(removeLoginModal); |
1130 | 1132 | observer.observe(document, { childList: true, subtree: true }); |
| 1133 | + getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面 |
1131 | 1134 | } else { |
1132 | 1135 | cleanTitles(); // 净化标题消息 |
1133 | 1136 | } |
1134 | 1137 | } else { // 不是文章页 |
1135 | | - if (document.querySelector('button.AppHeader-login')) { // 未登录 |
| 1138 | + if (!document.querySelector('.AppHeader-profile>.AppHeader-menu')) { // 未登录 |
1136 | 1139 | const observer = new MutationObserver(removeLoginModal); |
1137 | 1140 | observer.observe(document, { childList: true, subtree: true }); |
1138 | 1141 | document.lastElementChild.appendChild(document.createElement('style')).textContent = '.Question-mainColumnLogin, button.AppHeader-login {display: none !important;}'; // 屏蔽问题页中间的登录提示 |
1139 | | - document.querySelector('button.AppHeader-login').insertAdjacentHTML('afterend', '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录</a>'); // [登录] 按钮跳转至登录页面 |
| 1142 | + getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面 |
1140 | 1143 | } else { |
1141 | 1144 | cleanTitles(); // 净化标题消息 |
1142 | 1145 | } |
@@ -1247,6 +1250,18 @@ function addUrlChangeEvent() { |
1247 | 1250 | } |
1248 | 1251 |
|
1249 | 1252 |
|
| 1253 | +function getXpath(xpath, contextNode, doc = document) { |
| 1254 | + contextNode = contextNode || doc; |
| 1255 | + try { |
| 1256 | + const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); |
| 1257 | + // 应该总是返回一个元素节点 |
| 1258 | + return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue; |
| 1259 | + } catch (err) { |
| 1260 | + throw new Error(`无效 Xpath: ${xpath}`); |
| 1261 | + } |
| 1262 | +} |
| 1263 | + |
| 1264 | + |
1250 | 1265 | // 显示问题作者 |
1251 | 1266 | function question_author() { |
1252 | 1267 | if (document.querySelector('.BrandQuestionSymbol, .QuestionAuthor')) return |
|
0 commit comments