Skip to content

Commit 509e8da

Browse files
committed
恢复 [移除登录弹窗] 功能
1 parent aa02efe commit 509e8da

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// @name:zh-CN 知乎增强
44
// @name:zh-TW 知乎增強
55
// @name:ru Улучшение Zhihu
6-
// @version 2.3.15
6+
// @version 2.3.16
77
// @author X.I.U
88
// @description A more personalized Zhihu experience~
9-
// @description:zh-CN 屏蔽指定类别(视频、盐选、文章、想法、关注[赞同了XX/关注了XX]等等)、屏蔽用户、屏蔽关键词、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、区分问题文章、移除高亮链接、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、直达问题按钮、默认站外直链...
10-
// @description:zh-TW 屏蔽指定類別(視頻、鹽選、文章、想法、關注[贊同了XX/關注了XX]等等)、屏蔽用戶、屏蔽關鍵詞、默認收起回答、快捷收起回答/評論、快捷回到頂部、區分問題文章、移除高亮鏈接、默認高清原圖(無水印)、默認站外直鏈...
9+
// @description:zh-CN 移除登录弹窗、屏蔽指定类别(视频、盐选、文章、想法、关注[赞同/关注了XX])、屏蔽用户、屏蔽关键词、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、区分问题文章、移除高亮链接、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、直达问题按钮、默认站外直链...
10+
// @description:zh-TW 移除登錄彈窗、屏蔽指定類別(視頻、鹽選、文章、想法、關注[贊同/關注了XX])、屏蔽用戶、屏蔽關鍵詞、默認收起回答、快捷收起回答/評論、快捷回到頂部、區分問題文章、移除高亮鏈接、默認高清原圖(無水印)、默認站外直鏈...
1111
// @description:ru Более персонализированный опыт пользования сайтом Zhihu~
1212
// @match *://www.zhihu.com/*
1313
// @match *://zhuanlan.zhihu.com/*
@@ -1184,6 +1184,38 @@ function questionRichTextMore() {
11841184
if (button) button.click()
11851185
}
11861186

1187+
// 移除登录弹窗
1188+
function removeLogin() {
1189+
const removeLoginModal = (mutationsList, observer) => {
1190+
for (const mutation of mutationsList) {
1191+
for (const target of mutation.addedNodes) {
1192+
if (target.nodeType != 1) return
1193+
if (target.querySelector('.signFlowModal')) {
1194+
let button = target.querySelector('.Button.Modal-closeButton.Button--plain');
1195+
if (button) button.click();
1196+
} else if (getXpath('//button[text()="立即登录/注册"]',target)) {
1197+
target.remove();
1198+
}
1199+
}
1200+
}
1201+
};
1202+
1203+
// 未登录时才会监听并移除登录弹窗
1204+
if(location.hostname === 'zhuanlan.zhihu.com') { // 如果是文章页
1205+
if (!document.querySelector('.ColumnPageHeader-profile>.AppHeader-menu')) { // 未登录
1206+
const observer = new MutationObserver(removeLoginModal);
1207+
observer.observe(document, { childList: true, subtree: true });
1208+
if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面
1209+
}
1210+
} else { // 不是文章页
1211+
if (!document.querySelector('.AppHeader-profile>.AppHeader-menu')) { // 未登录
1212+
const observer = new MutationObserver(removeLoginModal);
1213+
observer.observe(document, { childList: true, subtree: true });
1214+
document.lastElementChild.appendChild(document.createElement('style')).textContent = '.Question-mainColumnLogin, button.AppHeader-login {display: none !important;}'; // 屏蔽问题页中间的登录提示
1215+
if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面
1216+
}
1217+
}
1218+
}
11871219

11881220
// 净化标题消息
11891221
function cleanTitles() {
@@ -1491,6 +1523,7 @@ function blockHotOther() {
14911523
}
14921524
})
14931525

1526+
removeLogin(); // 移除登录弹窗,Violentmonkey 不能延迟执行这个
14941527
cleanTitles(); // 净化标题消息,不能延迟执行
14951528
// Violentmonkey 比 Tampermonkey 加载更早,会导致一些元素还没加载,因此需要延迟一会儿
14961529
// Tampermonkey 4.18.0 版本可能需要延迟一会执行

0 commit comments

Comments
 (0)