Greasy Fork

Greasy Fork is available in English.

知乎 - 屏蔽关键词

在发现页面屏蔽标题带有被屏蔽话题的条目。

当前为 2018-04-23 提交的版本,查看 最新版本

// ==UserScript==
// fork from http://greasyfork.icu/zh-CN/scripts/23197-知乎-隐藏你屏蔽的人补完
// @name        知乎 - 屏蔽关键词
// @namespace   HideBlockedKeywords@Zhihu
// @description 在发现页面屏蔽标题带有被屏蔽话题的条目。
// @include     http://www.zhihu.com/
// @include     http://www.zhihu.com/*
// @include     https://www.zhihu.com/
// @include     https://www.zhihu.com/*
// @version     1.0
// @require     http://greasyfork.icu/scripts/23268-waitforkeyelements/code/waitForKeyElements.js?version=147835
// @grant       none
// ==/UserScript==


//当你在“发现”栏目里面闲逛,难免会被一些本该屏蔽的问题脏了眼。这个脚本帮你解决这个问题。
//感谢“隐藏你屏蔽的人”、“隐藏你屏蔽的人补完”脚本作者,这个脚本是以之为基础修改的。

//初次运行会跳转屏蔽界面,以你屏蔽的话题作为屏蔽关键词。
//如果有新增屏蔽话题,可以用 localStorage.removeItem("WordList") 重置之前缓存的屏蔽词目列表。



function PickingWords()
{
  var $wordlist = $('.zm-tag-editor .zm-tag-editor-labels a.zm-item-tag');
  var keyword = new Array($wordlist.length);
  for (i = 0; i < $wordlist.length; i++)
  {
    keyword[i] = $wordlist[i].innerHTML.replace(/((.*))/,"").replace(/(\(.*\))/,"");
  }
  localStorage.WordList = keyword;
}

$(function () {
  if (window.location.href == 'https://www.zhihu.com/settings/filter')
  {
    PickingWords();
  }
  if (localStorage.WordList == undefined)
  {
    if (window.location.href != 'https://www.zhihu.com/settings/filter')
    {
      if (confirm('将要跳转到 https://www.zhihu.com/settings/filter 获取屏蔽列表'))
      {
        window.location.href = 'https://www.zhihu.com/settings/filter';
      }
    }
  }
});

function replaceContentWithText(node, text) {
    node.children().hide();
    var spanNode = document.createElement('span');
    spanNode.append( document.createTextNode(text) );
    spanNode.style.color = "#999";
    node.append(spanNode);
}

function queryWithXPath(path,node){
    resultNode=null;
    try{
        queryResult = document.evaluate(path,node);
        resultNode = queryResult.iterateNext();
    }
    catch(e){
        console.log("error: "+e);
    }
    return resultNode;
}

function checkAndBlock(title,blockMsg,jNode) {

	localStorage.WordList.split(',').some(function (e) {
		if( title.match(e) ) {
			replaceContentWithText(jNode,blockMsg+':'+e);
	    	return true;
		}
	});
}


//屏蔽发现条目
function processExplore (jNode) {
    iNode=jNode[0];
    aNode = queryWithXPath(".//a[contains(@class,'question_link')]",iNode);
    if(aNode)
    	//alert(aNode.innerHTML);
        checkAndBlock(aNode.innerHTML,'这里有一条已被block的条目',jNode);
}

waitForKeyElements ("div.explore-feed", processExplore);