From 4709280af33f5cc33fb873dced86eb5fa541671c Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Thu, 17 Jun 2021 17:00:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20[=E5=B1=8F=E8=94=BD?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=85=B3=E9=94=AE=E8=AF=8D]=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=88=E9=A6=96=E9=A1=B5=E5=92=8C=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=81=97=E6=BC=8F=E9=97=AE=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Enhanced.user.js | 82 +++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/Zhihu-Enhanced.user.js b/Zhihu-Enhanced.user.js index 1aa02f8..2358aee 100644 --- a/Zhihu-Enhanced.user.js +++ b/Zhihu-Enhanced.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 知乎增强 -// @version 1.4.5 +// @version 1.4.6 // @author X.I.U // @description 移除登录弹窗、一键收起回答、收起当前回答/评论(点击两侧空白处)、快捷回到顶部(右键两侧空白处)、屏蔽指定用户、屏蔽指定关键词(标题)、屏蔽盐选内容、置顶显示时间、显示问题时间、区分问题文章、默认高清原图、默认站外直链 // @match *://www.zhihu.com/* @@ -372,6 +372,7 @@ function blockKeywords(type) { if (!menu_value('menu_customBlockKeywords') || menu_value('menu_customBlockKeywords').length < 1) return switch(type) { case 'index': + blockKeywords_index_(); blockKeywords_index(); break; case 'topic': @@ -386,6 +387,38 @@ function blockKeywords(type) { break; } + function blockKeywords_index_() { + let item = document.querySelectorAll('h2.ContentItem-title meta[itemprop="name"]'); // 标题所在元素 + if (item.length > 0) { + item.forEach(function(item2){ + //console.log(item2) + menu_value('menu_customBlockKeywords').forEach(function(item1){ // 遍历关键词黑名单 + if (item2.content.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 + console.log(item2.content); + if (item2.parentNode.parentNode.parentNode.parentNode.parentNode.className === 'Feed') { + item2.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); + } else { + item2.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); + } + } + }) + }) + } + // 如果是文章标题 + item = document.querySelectorAll('.ContentItem.ArticleItem meta[itemprop="headline"]'); // 标题所在元素 + if (item.length > 0) { + item.forEach(function(item2){ + //console.log(item2) + menu_value('menu_customBlockKeywords').forEach(function(item1){ // 遍历关键词黑名单 + if (item2.content.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 + console.log('文章',item2.content); + item2.parentNode.parentNode.parentNode.remove(); + } + }) + }) + } + } + function blockKeywords_index() { let blockKeywords = e => { if (e.target.innerHTML && e.target.getElementsByClassName('ContentItem-title').length > 0) { @@ -395,7 +428,11 @@ function blockKeywords(type) { menu_value('menu_customBlockKeywords').forEach(function(item1){ // 遍历关键词黑名单 if (item.content.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 console.log(item.content); - item.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); + if (item.parentNode.parentNode.parentNode.parentNode.parentNode.className === 'Feed') { + item.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); + } else { + item.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); + } } }) } else { // 如果是文章标题 @@ -428,19 +465,19 @@ function blockKeywords(type) { } }) }) - } else { // 如果是文章标题 - item = document.querySelectorAll('.ContentItem.ArticleItem meta[itemprop="headline"]'); // 标题所在元素 - if (item.length > 0) { - //console.log(item) - item.forEach(function(item2){ - menu_value('menu_customBlockKeywords').forEach(function(item1){ // 遍历关键词黑名单 - if (item2.content.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 - console.log('文章',item2.content); - item2.parentNode.parentNode.remove(); - } - }) + } + // 如果是文章标题 + item = document.querySelectorAll('.ContentItem.ArticleItem meta[itemprop="headline"]'); // 标题所在元素 + if (item.length > 0) { + //console.log(item) + item.forEach(function(item2){ + menu_value('menu_customBlockKeywords').forEach(function(item1){ // 遍历关键词黑名单 + if (item2.content.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 + console.log('文章',item2.content); + item2.parentNode.parentNode.remove(); + } }) - } + }) } } @@ -481,26 +518,15 @@ function blockKeywords(type) { //if (e.target.innerHTML) console.log(e.target.innerHTML) if (e.target.innerHTML && e.target.getElementsByClassName('ContentItem-title').length > 0) { //console.log(e.target.innerHTML) - let item = e.target.querySelector('h2.ContentItem-title meta[itemprop="name"]'); // 标题所在元素 + let item = e.target.querySelector('h2.ContentItem-title a[data-za-detail-view-id]'); // 标题所在元素 if (item) { //console.log(item) menu_value('menu_customBlockKeywords').forEach(function(item1){ // 遍历关键词黑名单 - if (item.content.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 - console.log(item.content); + if (item.innerText.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 + console.log(item.innerText); item.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); } }) - } else { // 如果是文章标题 - item = e.target.querySelector('h2.ContentItem-title a[data-za-detail-view-id]'); // 标题所在元素 - if (item) { - //console.log(item) - menu_value('menu_customBlockKeywords').forEach(function(item1){ // 遍历关键词黑名单 - if (item.innerText.toLowerCase().indexOf(item1.toLowerCase()) > -1) { // 找到就删除该信息流 - console.log('文章',item.content); - item.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); - } - }) - } } } }