知乎助手,包含多个功能

新版本修改:默认隐藏,按右下角黑色+号,显示。功能简介:1、暂时屏蔽知乎,可随时开关;2、根据关键词屏蔽回答,比如关键词"如何,看待",就会屏蔽首页推荐里所有包含“如何”或者“看待”关键词的回答;3、右键菜单中添加“在知乎搜索”,选中文字就可右键搜索;4、屏蔽信息流广告;5、屏蔽回答中的购物推荐

目前为 2020-05-09 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 知乎助手,包含多个功能
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.18
  5. // @description 新版本修改:默认隐藏,按右下角黑色+号,显示。功能简介:1、暂时屏蔽知乎,可随时开关;2、根据关键词屏蔽回答,比如关键词"如何,看待",就会屏蔽首页推荐里所有包含“如何”或者“看待”关键词的回答;3、右键菜单中添加“在知乎搜索”,选中文字就可右键搜索;4、屏蔽信息流广告;5、屏蔽回答中的购物推荐
  6. // @author 桃源隐叟
  7. // @match *://www.zhihu.com/*
  8. // @match *://www.zhihu.com
  9. // @grant none
  10. //@require https://code.jquery.com/jquery-2.1.4.min.js
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. /* globals jQuery, $, waitForKeyElements */
  16.  
  17. // Your code here...
  18. var controlPanel=`<p class="toggle-control" style="z-index:201;position:fixed;right:100px;bottom:100px;margin:2px 1px 1px 2px;text-decoration:underline;">
  19. <img src="http://pic.90sjimg.com/design/00/21/84/57/58fd89ee39300.png!/fw/250/quality/90/unsharp/true/compress/true/canvas/250x250/cvscolor/FFFFFFFF" style="width:30px;height:30px;"></p>
  20. <div style="z-index:200;position:fixed;right:100px;bottom:100px;border:1px solid #888;padding:30px;border-radius:5px;background-color:white;display:none" id="control-div">
  21. <h2>设置屏蔽选项</h2>
  22. <br>
  23. <span>屏蔽购物推荐</span><input type="radio" name="recommend" value="on" checked>开<input type="radio" name="recommend" value="off">关<br>
  24. <span>屏蔽信息流广告</span><input type="radio" name="ads" value="on" checked>开<input type="radio" name="ads" value="off">关<br>
  25. <span>屏蔽关键词</span><input type="radio" name="keyword" value="on" checked>开<input type="radio" name="keyword" value="off">关<br>
  26. <input type="text" placeholder="test1,test2" class="blockkeyword"><br>
  27. <span>屏蔽知乎</span><input type="radio" name="zhihu" value="on" >开<input type="radio" name="zhihu" value="off" checked>关<br>
  28. <input type="text" placeholder="好好工作,暂时别看知乎,目前XX还没有完成" class="blocksite"><br>
  29. </div>`
  30.  
  31. document.body.insertAdjacentHTML("afterBegin",controlPanel);
  32.  
  33.  
  34. window.onload=()=>{
  35. initSetting();
  36. loadSetting();
  37. funcBlockAds();
  38. funcBlockByKeyWord();
  39. funcBlockSite();
  40. }
  41.  
  42. document.body.onscroll=function(){
  43. funcBlockRecommend();
  44. funcBlockAds();
  45. funcBlockByKeyWord();
  46. funcBlockSite();
  47. }
  48.  
  49.  
  50. function funcBlockRecommend(){
  51. if($("[name='recommend']:checked")[0].value==="on"){
  52. $(".RichText-MCNLinkCardContainer").css("display","none");
  53. }else{
  54. $(".RichText-MCNLinkCardContainer").css("display","block");
  55. }
  56. }
  57. function funcBlockAds(){
  58. if($("[name='ads']:checked")[0].value==="on")
  59. {
  60. $(".TopstoryItem--advertCard").css("display","none");
  61. }else{
  62. $(".TopstoryItem--advertCard").css("display","none");
  63. }
  64. }
  65.  
  66. function funcBlockByKeyWord(){
  67. var blockKeywords=$(".blockkeyword")[0].value;
  68. if(blockKeywords!=""){
  69. var bkArray=blockKeywords.split(",");
  70. for(let i=0;i<bkArray.length;i++){
  71. if($("[name='keyword']:checked")[0].value==="on"){
  72. $(`.TopstoryItem:contains(${bkArray[i]})`).css("display","none");
  73. }else{
  74. $(`.TopstoryItem:contains(${bkArray[i]})`).css("display","block");
  75. }
  76. }
  77. }
  78.  
  79. }
  80.  
  81. function funcBlockSite(){
  82. if($("[name='zhihu']:checked")[0].value==="on"){
  83. var blockTip=$(".blocksite")[0].value?$(".blocksite")[0].value:$(".blocksite")[0].placeholder;
  84. var blockHtml=`<h1 style="text-align:center;font-size:50px;">${blockTip}</h1>`;
  85. //$("body").css("display","none");
  86.  
  87. //$("body").html(blockHtml);
  88.  
  89. var bodyChildren=$("body").children();
  90. for(let i=0;i<bodyChildren.length;i++){
  91. if(bodyChildren[i].id!="control-div"){
  92. $(bodyChildren[i]).css("display","none")
  93. }
  94. }
  95. //$("#control-div").css("display","block");
  96. $(".toggle-control").css("display","block");
  97. $("body").prepend(blockHtml);
  98. $("#container").css("display","none");
  99. $("iframe").css("display","none");
  100. }else{
  101. //$("body").html("");
  102. }
  103. }
  104.  
  105.  
  106. $("[name='recommend']").on("click",function(){
  107. setCookie('recommend',$("[name='recommend']:checked")[0].value);
  108. });
  109.  
  110. $("[name='ads']").on("click",function(){
  111. setCookie('ads',$("[name='ads']:checked")[0].value);
  112. });
  113.  
  114. $("[name='keyword']").on("click",function(){
  115. setCookie('blockkeywordSwitch',$("[name='keyword']:checked")[0].value);
  116. setCookie('blockkeyword',$(".blockkeyword")[0].value);
  117. });
  118.  
  119. $("[name='zhihu']").on("click",function(){
  120. setCookie('blocksiteswitch',$("[name='zhihu']:checked")[0].value);
  121. setCookie('blocksiteTip',$(".blocksite")[0].value);
  122. });
  123.  
  124. $(".blockkeyword").blur(function(){
  125. setCookie('blockkeyword',$(".blockkeyword")[0].value);
  126. });
  127.  
  128. $(".blocksite").blur(function(){
  129. setCookie('blocksiteTip',$(".blocksite")[0].value);
  130. });
  131.  
  132. $(".toggle-control").click(function(){
  133. $("#control-div").toggle();
  134. });
  135.  
  136.  
  137. function setCookie(name,value)
  138. {
  139. var Days = 30;
  140. var exp = new Date();
  141. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  142. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  143. }
  144.  
  145. function getCookie(name)
  146. {
  147. var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
  148.  
  149. if(arr=document.cookie.match(reg))
  150.  
  151. return unescape(arr[2]);
  152. else
  153. return null;
  154. }
  155.  
  156. function loadSetting(){
  157. if(getCookie("recommend")!=null){
  158. $(`[name='recommend'][value=${getCookie("recommend")}]`)[0].checked=true;
  159. }else{
  160. }
  161.  
  162. if(getCookie("ads")!=null){
  163. $(`[name='ads'][value=${getCookie("ads")}]`)[0].checked=true;
  164. }else{
  165. }
  166.  
  167. if(getCookie("blockkeywordSwitch")!=null){
  168. $(`[name='keyword'][value=${getCookie("blockkeywordSwitch")}]`)[0].checked=true;
  169. $(".blockkeyword")[0].value=getCookie("blockkeyword");
  170. }else{
  171. }
  172.  
  173. if(getCookie("blocksiteswitch")!=null){
  174. $(`[name='zhihu'][value=${getCookie("blocksiteswitch")}]`)[0].checked=true;
  175. $(".blocksite")[0].value=getCookie("blocksiteTip");
  176. }else{
  177. }
  178. }
  179.  
  180. function initSetting(){
  181. if(getCookie("recommend")==null){
  182. setCookie('recommend',$("[name='recommend']:checked")[0].value);
  183. }else{
  184. }
  185.  
  186. if(getCookie("ads")==null){
  187. setCookie('ads',$("[name='ads']:checked")[0].value);
  188. }else{
  189. }
  190.  
  191. if(getCookie("blockkeywordSwitch")==null){
  192. setCookie('blockkeywordSwitch',$("[name='keyword']:checked")[0].value);
  193. setCookie('blockkeyword',$(".blockkeyword")[0].value);
  194. }else{
  195. }
  196.  
  197. if(getCookie("blocksiteswitch")==null){
  198. setCookie('blocksiteswitch',$("[name='zhihu']:checked")[0].value);
  199. setCookie('blocksiteTip',$(".blocksite")[0].value);
  200. }else{
  201. }
  202. }
  203.  
  204. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址