Skip to content

Commit a7b76b6

Browse files
committed
优化 仅未登录时监听并移除登陆弹窗;修复 [登录][加入知乎] 按钮无法点击的问题
1 parent 70c1cc3 commit a7b76b6

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 知乎增强
3-
// @version 1.1.7
3+
// @version 1.1.8
44
// @author X.I.U
55
// @description 移除登录弹窗、一键收起回答、置顶显示时间、区分问题文章、默认高清原图、默认折叠邀请
66
// @match *://www.zhihu.com/*
@@ -294,7 +294,7 @@ function addTypeTips() {
294294
patt_tip = /zhihu_e_tips/
295295
var postList = document.querySelectorAll('h2.ContentItem-title a');
296296
postNum = document.querySelectorAll('small.zhihu_e_tips');
297-
console.log(`${postList.length} ${postNum.length}`)
297+
//console.log(`${postList.length} ${postNum.length}`)
298298
if (postList.length > postNum.length){
299299
for(var num = postNum.length;num<postList.length;num++){
300300
if (!patt_tip.test(postList[num].innerHTML)){ // 判断是否已添加
@@ -312,6 +312,17 @@ function addTypeTips() {
312312
}
313313
}
314314

315+
// 知乎免登录,来自:https://greasyfork.org/zh-CN/scripts/417126
316+
function removeLogin() {
317+
let removeLoginModal = e => {
318+
if (e.target.getElementsByClassName('Modal-wrapper').length > 0) {
319+
e.target.getElementsByClassName('Modal-wrapper')[0].remove();
320+
setTimeout(() => {document.documentElement.style.overflowY = 'scroll';}, 0);
321+
}
322+
}
323+
document.addEventListener('DOMNodeInserted', removeLoginModal);
324+
}
325+
315326

316327
// 监听 XMLHttpRequest 事件
317328
function EventXMLHttpRequest() {
@@ -323,16 +334,12 @@ function EventXMLHttpRequest() {
323334
window.XMLHttpRequest.prototype.send = sendReplacement;
324335
}
325336

326-
327337
(function() {
328-
// 知乎免登录,来自:https://greasyfork.org/zh-CN/scripts/417126
329-
let removeLoginModal = e => {
330-
if (e.target.getElementsByClassName('Modal-wrapper').length > 0) {
331-
e.target.getElementsByClassName('Modal-wrapper')[0].remove();
332-
setTimeout(() => {document.documentElement.style.overflowY = 'scroll';}, 0);
333-
}
338+
if (document.querySelector('button.AppHeader-login')){ // 未登录时才会监听并移除登录弹窗
339+
removeLogin();
340+
document.querySelector('button.AppHeader-login').onclick=function(){location.href='https://www.zhihu.com/signin';} // [登录]按钮跳转至登录页面
341+
document.querySelector('.AppHeader-profile button.Button--primary').onclick=function(){location.href='https://www.zhihu.com/signin';} // [加入知乎]按钮跳转至注册页面(实际上是同一个页面)
334342
}
335-
document.addEventListener('DOMNodeInserted', removeLoginModal);
336343

337344

338345
// 默认折叠邀请

0 commit comments

Comments
 (0)