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 = / z h i h u _ e _ t i p s /
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 事件
317328function 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