知乎助手,独家、原创

功能简介:设置面板默认隐藏,按右下角黑色+号,显示。一,屏蔽时间线中纯视频营销号回答,二屏蔽各类广告。三,根据关键词屏蔽回答

  1. // ==UserScript==
  2. // @name 知乎助手,独家、原创
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.28
  5. // @description 功能简介:设置面板默认隐藏,按右下角黑色+号,显示。一,屏蔽时间线中纯视频营销号回答,二屏蔽各类广告。三,根据关键词屏蔽回答
  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="qKeyword" value="on" checked>开<input type="radio" name="qKeyword" value="off">关<br>
  28. <input type="text" placeholder="知乎盐选" class="questionB"><br>
  29. <span>屏蔽知乎</span><input type="radio" name="zhihu" value="on" >开<input type="radio" name="zhihu" value="off" checked>关<br>
  30. <input type="text" placeholder="好好工作,暂时别看知乎,目前XX还没有完成" class="blocksite"><br>
  31. </div>`
  32.  
  33. document.body.insertAdjacentHTML("afterBegin",controlPanel);
  34.  
  35.  
  36. window.onload=()=>{
  37. initSetting();
  38. loadSetting();
  39. funcBlockAds();
  40. funcBlockByKeyWord();
  41. funcBlockSite();
  42. funcBlockQuestion();
  43. }
  44.  
  45. document.body.onscroll=function(){
  46. funcBlockRecommend();
  47. funcBlockAds();
  48. funcBlockByKeyWord();
  49. funcBlockSite();
  50. funcBlockQuestion();
  51. }
  52.  
  53.  
  54. function funcBlockRecommend(){
  55. if($("[name='recommend']:checked")[0].value==="on"){
  56. $(".RichText-MCNLinkCardContainer").css("display","none");
  57. }else{
  58. $(".RichText-MCNLinkCardContainer").css("display","block");
  59. }
  60. }
  61. function funcBlockAds(){
  62. if($("[name='ads']:checked")[0].value==="on")
  63. {
  64. $(".Card").find(".ZVideoItem").parent().parent().css("display","none");
  65. $(".TopstoryItem--advertCard").css("display","none");
  66. $(".Pc-card").css("display","none");
  67. }else{
  68. $(".Card").find(".ZVideoItem").parent().parent().css("display","block");
  69. $(".TopstoryItem--advertCard").css("display","block");
  70. $(".Pc-card").css("display","block");
  71. }
  72. }
  73.  
  74. function funcBlockByKeyWord(){
  75. var blockKeywords=$(".blockkeyword")[0].value;
  76. if(blockKeywords!=""){
  77. var bkArray=blockKeywords.split(",");
  78. for(let i=0;i<bkArray.length;i++){
  79. if($("[name='keyword']:checked")[0].value==="on"){
  80. $(`.TopstoryItem:contains(${bkArray[i]})`).css("display","none");
  81. }else{
  82. $(`.TopstoryItem:contains(${bkArray[i]})`).css("display","block");
  83. }
  84. }
  85. }
  86.  
  87. }
  88.  
  89. function funcBlockQuestion(){
  90. var questionBs=$(".questionB")[0].value;
  91. if(questionBs!=""){
  92. var qb=questionBs.split(",");
  93. for(let i=0;i<qb.length;i++){
  94. if($("[name='qKeyword']:checked")[0].value==="on"){
  95. $(`.List-item:contains(${qb[i]})`).css("display","none");
  96. }else{
  97. $(`.List-item:contains(${qb[i]})`).css("display","block");
  98. }
  99. }
  100. }
  101.  
  102. }
  103.  
  104. function funcBlockSite(){
  105. if($("[name='zhihu']:checked")[0].value==="on"){
  106. var blockTip=$(".blocksite")[0].value?$(".blocksite")[0].value:$(".blocksite")[0].placeholder;
  107. var blockHtml=`<h1 style="text-align:center;font-size:50px;">${blockTip}</h1>`;
  108. //$("body").css("display","none");
  109.  
  110. //$("body").html(blockHtml);
  111.  
  112. var bodyChildren=$("body").children();
  113. for(let i=0;i<bodyChildren.length;i++){
  114. if(bodyChildren[i].id!="control-div"){
  115. $(bodyChildren[i]).css("display","none")
  116. }
  117. }
  118. //$("#control-div").css("display","block");
  119. $(".toggle-control").css("display","block");
  120. $("body").prepend(blockHtml);
  121. $("#container").css("display","none");
  122. $("iframe").css("display","none");
  123. }else{
  124. //$("body").html("");
  125. }
  126. }
  127.  
  128.  
  129. $("[name='recommend']").on("click",function(){
  130. setCookie('recommend',$("[name='recommend']:checked")[0].value);
  131. });
  132.  
  133. $("[name='ads']").on("click",function(){
  134. setCookie('ads',$("[name='ads']:checked")[0].value);
  135. });
  136.  
  137. $("[name='keyword']").on("click",function(){
  138. setCookie('blockkeywordSwitch',$("[name='keyword']:checked")[0].value);
  139. setCookie('blockkeyword',$(".blockkeyword")[0].value);
  140. });
  141.  
  142. $("[name='qKeyword']").on("click",function(){
  143. setCookie('questionBlockSwitch',$("[name='qKeyword']:checked")[0].value);
  144. setCookie('questionKeyword',$(".questionB")[0].value);
  145. });
  146.  
  147. $("[name='zhihu']").on("click",function(){
  148. setCookie('blocksiteswitch',$("[name='zhihu']:checked")[0].value);
  149. setCookie('blocksiteTip',$(".blocksite")[0].value);
  150. });
  151.  
  152. $(".blockkeyword").blur(function(){
  153. setCookie('blockkeyword',$(".blockkeyword")[0].value);
  154. });
  155.  
  156. $(".questionB").blur(function(){
  157. setCookie('questionKeyword',$(".questionB")[0].value);
  158. });
  159.  
  160. $(".blocksite").blur(function(){
  161. setCookie('blocksiteTip',$(".blocksite")[0].value);
  162. });
  163.  
  164. $(".toggle-control").click(function(){
  165. $("#control-div").toggle();
  166. });
  167.  
  168.  
  169. function setCookie(name,value)
  170. {
  171. var Days = 30;
  172. var exp = new Date();
  173. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  174. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  175. }
  176.  
  177. function getCookie(name)
  178. {
  179. var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
  180.  
  181. if(arr=document.cookie.match(reg))
  182.  
  183. return unescape(arr[2]);
  184. else
  185. return null;
  186. }
  187.  
  188. function loadSetting(){
  189. if(getCookie("recommend")!=null){
  190. $(`[name='recommend'][value=${getCookie("recommend")}]`)[0].checked=true;
  191. }else{
  192. }
  193.  
  194. if(getCookie("ads")!=null){
  195. $(`[name='ads'][value=${getCookie("ads")}]`)[0].checked=true;
  196. }else{
  197. }
  198.  
  199. if(getCookie("blockkeywordSwitch")!=null){
  200. $(`[name='keyword'][value=${getCookie("blockkeywordSwitch")}]`)[0].checked=true;
  201. $(".blockkeyword")[0].value=getCookie("blockkeyword");
  202. }else{
  203. }
  204.  
  205. if(getCookie("questionBlockSwitch")!=null){
  206. $(`[name='qKeyword'][value=${getCookie("questionBlockSwitch")}]`)[0].checked=true;
  207. $(".questionB")[0].value=getCookie("questionKeyword");
  208. }else{
  209. }
  210.  
  211. if(getCookie("blocksiteswitch")!=null){
  212. $(`[name='zhihu'][value=${getCookie("blocksiteswitch")}]`)[0].checked=true;
  213. $(".blocksite")[0].value=getCookie("blocksiteTip");
  214. }else{
  215. }
  216. }
  217.  
  218. function initSetting(){
  219. if(getCookie("recommend")==null){
  220. setCookie('recommend',$("[name='recommend']:checked")[0].value);
  221. }else{
  222. }
  223.  
  224. if(getCookie("ads")==null){
  225. setCookie('ads',$("[name='ads']:checked")[0].value);
  226. }else{
  227. }
  228.  
  229. if(getCookie("blockkeywordSwitch")==null){
  230. setCookie('blockkeywordSwitch',$("[name='keyword']:checked")[0].value);
  231. setCookie('blockkeyword',$(".blockkeyword")[0].value);
  232. }else{
  233. }
  234.  
  235. if(getCookie("questionBlockSwitch")==null){
  236. setCookie('questionBlockSwitch',$("[name='qKeyword']:checked")[0].value);
  237. setCookie('questionKeyword',$(".questionB")[0].value);
  238. }else{
  239. }
  240.  
  241. if(getCookie("blocksiteswitch")==null){
  242. setCookie('blocksiteswitch',$("[name='zhihu']:checked")[0].value);
  243. setCookie('blocksiteTip',$(".blocksite")[0].value);
  244. }else{
  245. }
  246. }
  247.  
  248. })();

QingJ © 2025

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