11// ==UserScript==
22// @name 知乎增强
3- // @version 1.6.8
3+ // @version 1.6.9
44// @author X.I.U
55// @description 移除登录弹窗、默认收起回答、一键收起回答、收起当前回答/评论(点击两侧空白处)、快捷回到顶部(右键两侧空白处)、屏蔽用户 (发布的内容)、屏蔽关键词(标题/评论)、屏蔽指定类别(视频/文章等)、屏蔽盐选内容、展开问题描述、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链
66// @match *://www.zhihu.com/*
@@ -403,7 +403,7 @@ function blockUsers(type) {
403403 for ( const keyword of menu_value ( 'menu_customBlockUsers' ) ) { // 遍历用户名黑名单
404404 if ( item . dataset . zop . indexOf ( 'authorName":"' + keyword + '",' ) > - 1 ) { // 找到就删除该信息流
405405 console . log ( item . dataset . zop ) ;
406- item1 . remove ( ) ;
406+ item1 . hidden = true ;
407407 break ;
408408 }
409409 }
@@ -427,7 +427,7 @@ function blockUsers(type) {
427427 for ( const keyword of menu_value ( 'menu_customBlockUsers' ) ) { // 遍历用户名黑名单
428428 if ( item . dataset . zop . indexOf ( 'authorName":"' + keyword + '",' ) > - 1 ) { // 找到就删除该信息流
429429 console . log ( item . dataset . zop ) ;
430- target . remove ( ) ;
430+ target . hidden = true ;
431431 break ;
432432 }
433433 }
@@ -452,7 +452,7 @@ function blockUsers(type) {
452452 menu_value ( 'menu_customBlockUsers' ) . forEach ( function ( item2 ) { // 遍历用户黑名单
453453 if ( item1 . dataset . zop . indexOf ( 'authorName":"' + item2 + '",' ) > - 1 ) { // 找到就删除该回答
454454 console . log ( item1 . dataset . zop )
455- target . remove ( ) ;
455+ target . hidden = true ;
456456 }
457457 } )
458458 }
@@ -471,7 +471,7 @@ function blockUsers(type) {
471471 menu_value ( 'menu_customBlockUsers' ) . forEach ( function ( item2 ) { // 遍历用户黑名单
472472 if ( item1 . dataset . zop . indexOf ( 'authorName":"' + item2 + '",' ) > - 1 ) { // 找到就删除该回答
473473 console . log ( item1 . dataset . zop )
474- item . remove ( ) ;
474+ item . hidden = true ;
475475 }
476476 } )
477477 }
@@ -495,7 +495,7 @@ function blockUsers(type) {
495495 menu_value ( 'menu_customBlockUsers' ) . forEach ( function ( item2 ) { // 遍历用户黑名单
496496 if ( item1 . dataset . zop . indexOf ( 'authorName":"' + item2 + '",' ) > - 1 ) { // 找到就删除该回答
497497 console . log ( item1 . dataset . zop )
498- item . remove ( ) ;
498+ item . hidden = true ;
499499 }
500500 } )
501501 }
@@ -511,7 +511,7 @@ function blockUsers(type) {
511511 for ( const keyword of menu_value ( 'menu_customBlockUsers' ) ) { // 遍历关键词黑名单
512512 if ( item . textContent === keyword ) { // 找到就删除该信息流
513513 console . log ( item . textContent ) ;
514- item1 . remove ( ) ;
514+ item1 . hidden = true ;
515515 break ;
516516 }
517517 }
@@ -535,7 +535,7 @@ function blockUsers(type) {
535535 for ( const keyword of menu_value ( 'menu_customBlockUsers' ) ) { // 遍历用户名黑名单
536536 if ( item . textContent === keyword ) { // 找到就删除该信息流
537537 console . log ( item . textContent ) ;
538- target . remove ( ) ;
538+ target . hidden = true ;
539539 break ;
540540 }
541541 }
@@ -558,15 +558,15 @@ function blockUsers(type) {
558558 menu_value ( 'menu_customBlockUsers' ) . forEach ( function ( item1 ) { // 遍历用户黑名单
559559 if ( item . alt === item1 ) { // 找到就删除该搜索结果
560560 if ( findParentElement ( item , 'NestComment--rootComment' , true ) ) {
561- findParentElement ( item , 'NestComment--rootComment' , true ) . remove ( ) ;
561+ findParentElement ( item , 'NestComment--rootComment' , true ) . hidden = true ; ;
562562 } else if ( findParentElement ( item , 'NestComment--child' , true ) ) {
563- findParentElement ( item , 'NestComment--child' , true ) . remove ( ) ;
563+ findParentElement ( item , 'NestComment--child' , true ) . hidden = true ; ;
564564 } else if ( findParentElement ( item , 'NestComment' , true ) ) {
565- findParentElement ( item , 'NestComment' , true ) . remove ( ) ;
565+ findParentElement ( item , 'NestComment' , true ) . hidden = true ; ;
566566 } else if ( findParentElement ( item , 'CommentItemV2' , true ) ) {
567- findParentElement ( item , 'CommentItemV2' , true ) . remove ( ) ;
567+ findParentElement ( item , 'CommentItemV2' , true ) . hidden = true ; ;
568568 } else if ( findParentElement ( item , 'CommentItemV2 CommentItemV2--highlighted' , true ) ) {
569- findParentElement ( item , 'CommentItemV2 CommentItemV2--highlighted' , true ) . remove ( ) ;
569+ findParentElement ( item , 'CommentItemV2 CommentItemV2--highlighted' , true ) . hidden = true ; ;
570570 }
571571 }
572572 } )
@@ -795,7 +795,7 @@ function blockKeywords(type) {
795795 for ( const keyword of menu_value ( 'menu_customBlockKeywords' ) ) { // 遍历关键词黑名单
796796 if ( item . textContent . toLowerCase ( ) . indexOf ( keyword . toLowerCase ( ) ) > - 1 ) { // 找到就删除该信息流
797797 console . log ( item . textContent ) ;
798- target . remove ( ) ;
798+ target . hidden = true ;
799799 break ;
800800 }
801801 }
@@ -854,7 +854,7 @@ function blockType(type) {
854854 // 一开始加载的信息流 + 添加标签样式
855855 if ( type === 'search' ) {
856856 if ( ! menu_value ( 'menu_blockTypeVideo' ) && ! menu_value ( 'menu_blockTypeArticle' ) && ! menu_value ( 'menu_blockTypeTopic' ) && ! menu_value ( 'menu_blockTypeSearch' ) ) return
857- if ( menu_value ( 'menu_blockTypeSearch' ) && location . pathname === '/search' ) setTimeout ( function ( ) { document . querySelector ( '.RelevantQuery' ) . parentElement . parentElement . remove ( ) ; } , 1000 )
857+ if ( menu_value ( 'menu_blockTypeSearch' ) && location . pathname === '/search' ) setTimeout ( function ( ) { document . querySelector ( '.RelevantQuery' ) . parentElement . parentElement . hidden = true ; ; } , 1000 )
858858 name = 'h2.ContentItem-title a, a.KfeCollection-PcCollegeCard-link, h2.SearchTopicHeader-Title a'
859859 addSetInterval_ ( name ) ;
860860 } else {
@@ -879,27 +879,27 @@ function blockType(type) {
879879 window . addEventListener ( 'locationchange' , function ( ) {
880880 addSetInterval_ ( name ) ;
881881 // 移除相关搜索
882- if ( menu_value ( 'menu_blockTypeSearch' ) && location . pathname === '/search' && location . search . indexOf ( 'type=content' ) > - 1 ) setTimeout ( function ( ) { document . querySelector ( '.RelevantQuery' ) . parentElement . parentElement . remove ( ) ; } , 1500 )
882+ if ( menu_value ( 'menu_blockTypeSearch' ) && location . pathname === '/search' && location . search . indexOf ( 'type=content' ) > - 1 ) setTimeout ( function ( ) { document . querySelector ( '.RelevantQuery' ) . parentElement . parentElement . hidden = true ; } , 1500 )
883883 } )
884884
885885 function blockType_ ( titleA ) {
886886 if ( ! titleA ) return // 判断是否为真
887887 if ( location . pathname === '/search' ) { // 搜索页
888888 if ( location . search . indexOf ( 'type=content' ) === - 1 ) return // 仅限搜索页的 [综合]
889889 if ( titleA . href . indexOf ( '/zvideo/' ) > - 1 ) { // 如果是视频
890- if ( menu_value ( 'menu_blockTypeVideo' ) ) findParentElement ( titleA , 'Card' ) . remove ( ) ;
890+ if ( menu_value ( 'menu_blockTypeVideo' ) ) findParentElement ( titleA , 'Card' ) . hidden = true ;
891891 } else if ( titleA . href . indexOf ( 'zhuanlan.zhihu.com' ) > - 1 ) { // 如果是文章
892- if ( menu_value ( 'menu_blockTypeArticle' ) ) findParentElement ( titleA , 'Card SearchResult-Card' ) . remove ( ) ;
892+ if ( menu_value ( 'menu_blockTypeArticle' ) ) findParentElement ( titleA , 'Card SearchResult-Card' ) . hidden = true ;
893893 } else if ( titleA . href . indexOf ( '/topic/' ) > - 1 ) { // 如果是话题
894- if ( menu_value ( 'menu_blockTypeTopic' ) ) findParentElement ( titleA , 'Card SearchResult-Card' ) . remove ( ) ;
894+ if ( menu_value ( 'menu_blockTypeTopic' ) ) findParentElement ( titleA , 'Card SearchResult-Card' ) . hidden = true ;
895895 } else if ( titleA . href . indexOf ( '/market/' ) > - 1 ) { // 如果是杂志文章等乱七八糟的
896- if ( menu_value ( 'menu_blockTypeArticle' ) ) findParentElement ( titleA , 'Card SearchResult-Card' ) . remove ( ) ;
896+ if ( menu_value ( 'menu_blockTypeArticle' ) ) findParentElement ( titleA , 'Card SearchResult-Card' ) . hidden = true ;
897897 }
898898 } else { // 首页
899899 if ( titleA . href . indexOf ( '/zvideo/' ) > - 1 ) { // 如果是视频
900- if ( menu_value ( 'menu_blockTypeVideo' ) ) findParentElement ( titleA , 'Card TopstoryItem TopstoryItem--old TopstoryItem-isRecommend' ) . remove ( ) ;
900+ if ( menu_value ( 'menu_blockTypeVideo' ) ) findParentElement ( titleA , 'Card TopstoryItem TopstoryItem--old TopstoryItem-isRecommend' ) . hidden = true ;
901901 } else if ( titleA . href . indexOf ( 'zhuanlan.zhihu.com' ) > - 1 ) { // 如果是文章
902- if ( menu_value ( 'menu_blockTypeArticle' ) ) findParentElement ( titleA , 'Card TopstoryItem TopstoryItem--old TopstoryItem-isRecommend' ) . remove ( ) ;
902+ if ( menu_value ( 'menu_blockTypeArticle' ) ) findParentElement ( titleA , 'Card TopstoryItem TopstoryItem--old TopstoryItem-isRecommend' ) . hidden = true ;
903903 }
904904 }
905905 }
@@ -950,7 +950,7 @@ function blockYanXuan() {
950950 if ( target . nodeType != 1 ) return
951951 if ( target . className === 'List-item' || target . className === 'Card AnswerCard' ) {
952952 if ( target . querySelector ( '.KfeCollection-AnswerTopCard-Container, .KfeCollection-PurchaseBtn' ) ) {
953- target . remove ( ) ;
953+ target . hidden = true ;
954954 }
955955 }
956956 }
@@ -963,7 +963,7 @@ function blockYanXuan() {
963963 if ( target . nodeType != 1 ) return
964964 target . querySelectorAll ( '.List-item, .Card.AnswerCard' ) . forEach ( function ( item ) {
965965 if ( item . querySelector ( '.KfeCollection-AnswerTopCard-Container, .KfeCollection-PurchaseBtn' ) ) {
966- item . remove ( ) ;
966+ item . hidden = true ;
967967 }
968968 } )
969969 }
@@ -981,7 +981,7 @@ function blockYanXuan() {
981981 // 针对的是打开网页后直接加载的前面几个回答(上面哪些是针对动态加载的回答)
982982 document . querySelectorAll ( '.List-item, .Card.AnswerCard' ) . forEach ( function ( item ) {
983983 if ( item . querySelector ( '.KfeCollection-AnswerTopCard-Container, .KfeCollection-PurchaseBtn' ) ) {
984- item . remove ( ) ;
984+ item . hidden = true ;
985985 }
986986 } )
987987}
@@ -1466,10 +1466,10 @@ function questionInvitation(){
14661466 }
14671467
14681468 function start ( ) {
1469- if ( location . hostname != 'zhuanlan.zhihu.com' ) collapsedAnswer ( ) ; // 一键收起回答
1470- if ( location . hostname != 'zhuanlan.zhihu.com' ) questionInvitation ( ) ; //默认折叠邀请
1471- closeFloatingComments ( ) ; // 快捷关闭悬浮评论(监听点击事件,点击网页两侧空白处)
1472- blockKeywords ( 'comment' ) ; // 屏蔽指定关键词(评论)
1469+ // if (location.hostname != 'zhuanlan.zhihu.com') collapsedAnswer(); // 一键收起回答
1470+ // if (location.hostname != 'zhuanlan.zhihu.com') questionInvitation(); //默认折叠邀请
1471+ // closeFloatingComments(); // 快捷关闭悬浮评论(监听点击事件,点击网页两侧空白处)
1472+ // blockKeywords('comment'); // 屏蔽指定关键词(评论)
14731473 if ( location . pathname . indexOf ( 'question' ) > - 1 ) { // 回答页 //
14741474 if ( location . pathname . indexOf ( 'waiting' ) == - 1 ) {
14751475 collapsedNowAnswer ( '.QuestionPage' ) ; // 收起当前回答 + 快捷返回顶部
0 commit comments