killZhihuAd-屏蔽知乎广告/文章/视频-沉浸模式浏览

只优化知乎,没有其他乱七八糟的功能。干掉知乎广告+沉浸模式/屏蔽文章/屏蔽视频可选。

  1. // ==UserScript==
  2. // @name killZhihuAd-屏蔽知乎广告/文章/视频-沉浸模式浏览
  3. // @description 只优化知乎,没有其他乱七八糟的功能。干掉知乎广告+沉浸模式/屏蔽文章/屏蔽视频可选。
  4. // @namespace http://tampermonkey.net/
  5. // @icon https://www.zhihu.com/static/favicon.ico
  6. // @version 1.4(2025/3/24)
  7. // @author shawn
  8. // @run-at document-end
  9. // @match *://*.zhihu.com/*
  10. // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_registerMenuCommand
  14. // ==/UserScript==
  15.  
  16.  
  17. (function() {
  18. /* global $ */
  19. 'use strict';
  20. var href = window.location.href;
  21. if (href.indexOf("https://www.zhihu.com/people") != -1) {
  22. return;
  23. }
  24.  
  25. //沉浸模式开关
  26. var focus_mode_on = GM_getValue("focus_mode_on");
  27. if(focus_mode_on){
  28. GM_registerMenuCommand("☑ 沉浸模式", focus_close, "");
  29. } else {
  30. GM_registerMenuCommand("☐ 沉浸模式", focus_open, "");
  31. }
  32. function focus_open () {
  33. GM_setValue("focus_mode_on", true);
  34. location.reload();
  35. }
  36. function focus_close () {
  37. GM_setValue("focus_mode_on", false);
  38. location.reload();
  39. }
  40.  
  41. //屏蔽文章开关
  42. var kill_article_mode_on = GM_getValue("kill_article_mode_on");
  43. if(kill_article_mode_on){
  44. GM_registerMenuCommand("☑ 屏蔽文章", kill_article_close, "");
  45. } else {
  46. GM_registerMenuCommand("☐ 屏蔽文章", kill_article_open, "");
  47. }
  48. function kill_article_open () {
  49. GM_setValue("kill_article_mode_on", true);
  50. location.reload();
  51. }
  52. function kill_article_close () {
  53. GM_setValue("kill_article_mode_on", false);
  54. location.reload();
  55. }
  56.  
  57. //屏蔽视频开关
  58. var kill_video_mode_on = GM_getValue("kill_video_mode_on");
  59. if(kill_video_mode_on){
  60. GM_registerMenuCommand("☑ 屏蔽视频", kill_video_close, "");
  61. } else {
  62. GM_registerMenuCommand("☐ 屏蔽视频", kill_video_open, "");
  63. }
  64. function kill_video_open () {
  65. GM_setValue("kill_video_mode_on", true);
  66. location.reload();
  67. }
  68. function kill_video_close () {
  69. GM_setValue("kill_video_mode_on", false);
  70. location.reload();
  71. }
  72.  
  73. //取消二次转链
  74. if(window.location.host == "link.zhihu.com"){
  75. var regRet = location.search.match(/target=(.+?)(&|$)/);
  76. if(regRet && regRet.length == 3){
  77. location.href = decodeURIComponent(regRet[1]);
  78. }
  79. }
  80.  
  81. //去除广告
  82. $(".Footer").remove();//侧边栏底部信息
  83.  
  84. //+沉浸模式
  85. if(focus_mode_on){
  86. if(href.indexOf("https://www.zhihu.com/question/") != -1) {
  87. setTimeout(resetQuestionColumn, 50);
  88. setInterval(resetQuestionColumn, 1000);
  89. } else if (href.indexOf("https://www.zhihu.com/search") != -1) {
  90. setTimeout(resetSearchColumn, 50);
  91. } else {
  92. setTimeout(resetMainColumn, 50);
  93. setInterval(killCardAd, 500);
  94. }
  95. } else {
  96. if(href.indexOf("https://www.zhihu.com/question/") != -1) {
  97. setInterval(killSideBarAd, 500);
  98. } else {
  99. setInterval(killCardAd, 500);
  100. setInterval(killSideBarAd, 500);
  101. }
  102. }
  103.  
  104. //+屏蔽所有文章
  105. if(kill_article_mode_on || kill_video_mode_on){
  106. setInterval(killArticleAndVedio, 500);
  107. }
  108. return;
  109.  
  110. function killArticleAndVedio() {
  111. $(".TopstoryItem").each(function(){
  112. //去除文章
  113. if (kill_article_mode_on) {
  114. if($(this).find(".ArticleItem").length != 0){
  115. $(this).remove();
  116. }
  117. }
  118. //去除视频
  119. if (kill_video_mode_on) {
  120. if($(this).find(".ZVideoItem").length != 0){
  121. $(this).remove();
  122. }
  123. }
  124. });
  125. }
  126. function killCardAd() {
  127. //答案卡片中的广告
  128. $(".TopstoryItem--advertCard").remove();
  129. // 顶部广告
  130. $(".Pc-Business-Card-PcTopFeedBanner").remove();
  131. }
  132. function killSideBarAd() {
  133. //右边栏广告
  134. $(".Pc-card").each(function(){
  135. if($(this).find(".Banner-adTag").length != 0){
  136. $(this).remove();
  137. }
  138. });
  139. $(".AdvertImg").remove();
  140. }
  141. function resetQuestionColumn() {
  142. $(".Question-sideColumn").remove();
  143. $(".Question-mainColumn").width('960px');
  144. $(".ContentItem-actions").width('920px');
  145. }
  146. function resetMainColumn() {
  147. //$(".GlobalSideBar").remove();
  148. var child = $(".Topstory-container").children();
  149. child[1].remove();
  150. $(".Topstory-mainColumn").width('960px');
  151. $(".ContentItem-actions").width('920px');
  152. }
  153. function resetSearchColumn() {
  154. $(".SearchSideBar").remove();
  155. $(".SearchMain").width('960px');
  156. $(".ContentItem-actions").width('920px');
  157. }
  158.  
  159. })();

QingJ © 2025

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