知乎浏览助手

知乎浏览助手. 如果想报 bug, 可以通过知乎私信联系我, zhihu.com/people/kougazhang

  1. // ==UserScript==
  2. // @name 知乎浏览助手
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.0
  5. // @description 知乎浏览助手. 如果想报 bug, 可以通过知乎私信联系我, zhihu.com/people/kougazhang
  6. // @author kgzhang
  7. // @match https://www.zhihu.com/*
  8. // @grant GM_addStyle
  9. // @grant GM_log
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_unregisterMenuCommand
  12. // @grant GM_openInTab
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_notification
  16. // @run-at document-end
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. 'use strict';
  21.  
  22. /****************** Global ****************************************/
  23. // Be largger the font;
  24. GM_addStyle("body {font-size: 25px}");
  25. // Hidden Topstory-hot
  26. GM_addStyle('a[aria-controls="Topstory-hot"] { display: none !important; }');
  27. // Hidden Topstory-zvideo
  28. GM_addStyle('a[aria-controls="Topstory-zvideo"] { display: none !important; }');
  29. // Hidden Topstory-recommend
  30. // GM_addStyle('a[aria-controls="Topstory-recommend"] { display: none !important; }');
  31. // Display 首页 only
  32. GM_addStyle('ul[class~="AppHeader-Tabs"] :not(:first-child) { display: none !important; }')
  33. // Hidden placeholder of search bar
  34. GM_addStyle('::placeholder {color: transparent !important;}');
  35. // rightButton 收起
  36. GM_addStyle('.ContentItem-rightButton {color: red}');
  37. // 返回顶部
  38. GM_addStyle('.Zi--BackToTop {color: red}');
  39. // hidden images
  40. let displayImages = GM_getValue("displayImages", true);
  41. // try to hide images in loading page
  42. if (!displayImages) {
  43. GM_addStyle("img {display: none !important; }");
  44. }
  45. GM_registerMenuCommand('Display images', function() {
  46. displayImages = !displayImages;
  47. GM_setValue("displayImages", displayImages);
  48. if (displayImages) {
  49. GM_addStyle("img {display: block !important; }");
  50. } else {
  51. GM_addStyle("img {display: none !important; }");
  52. }
  53. alert("Now displaying images is " + displayImages);
  54. }, 'r');
  55. /****************** Global ****************************************/
  56.  
  57. /****************** CornerButtons ****************************************/
  58. // GM_addStyle('.CornerButtons { right: 400px; bottom: 50px}')
  59. // GM_addStyle('.CornerAnimayedFlex { background: red; }')
  60. /****************** CornerButtons ****************************************/
  61.  
  62.  
  63. /***************** Follow page***********************/
  64. // Remove RightSideBar
  65. GM_addStyle("div[data-za-detail-view-path-module='RightSideBar'] { display: none !important; } ");
  66. // Remove AD
  67. GM_addStyle(".TopstoryItem--advertCard {display: none; }");
  68. // Widen mainColumn
  69. GM_addStyle(".Topstory-container { width: 1500px !important; } ");
  70. GM_addStyle(".Topstory-mainColumn { width: 1500px !important; } ");
  71. // Be lagger the font of question title
  72. GM_addStyle('.ContentItem-title {font-size: x-large}');
  73. /***************** Follow page***********************/
  74.  
  75. /***************** Recommand page***********************/
  76. // hidden video
  77. GM_addStyle(".TopstoryItem-isRecommend:has(.VideoAnswerPlayer-video) { display: none !important; } ");
  78. GM_addStyle(".TopstoryItem-isRecommend:has(.ZVideoItem-video) { display: none !important; } ");
  79. GM_addStyle(".TopstoryItem-isRecommend:has(.RichText-video) { display: none !important; } ");
  80. // hidden article
  81. GM_addStyle(".TopstoryItem-isRecommend:has(.CopyrightRichText-richTex) { display: none !important; } ");
  82. // hidden having -LinkCard
  83. GM_addStyle(".TopstoryItem-isRecommend:has(.RichText-LinkCardContainer) { display: none !important; } ");
  84. // hidden for edu RichText-EduCardContainer
  85. GM_addStyle(".TopstoryItem-isRecommend:has(.RichText-EduCardContainer) { display: none !important; } ");
  86. // hidden zhuanlan
  87. GM_addStyle('.TopstoryItem-isRecommend:has(div[data-za-extra-module*="Post"]) { display: none !important; }');
  88. // hidden Ecommerce
  89. GM_addStyle("TopstoryItem-isRecommend:has(.RichText-Ecommerce) {display: none !important; }");
  90. GM_addStyle(".TopstoryItem-isRecommend:has(.ecommerce-ad-box) {display: none !important; }");
  91.  
  92. // color
  93. // GM_addStyle(".TopstoryItem-isRecommend:nth-child(odd) {background: #f6f6f6}")
  94. // GM_addStyle(".TopstoryItem-isRecommend:nth-child(even) {background: #dfe1e5}")
  95. /***************** Recommand page***********************/
  96.  
  97. /****************** Question page *********************************/
  98. // Widen mainColumn
  99. GM_addStyle(".Question-main { width: 1500px !important; } ");
  100. GM_addStyle(".Question-mainColumn { width: 1500px !important; } ");
  101. // display & Make time at top
  102. GM_addStyle('meta[itemprop="dateModified"] {display: block; height: 20px; padding: 10px}');
  103. GM_addStyle('meta[itemprop="dateModified"]::after {content: "DateModified: " attr(content); color:#8590a6;}');
  104. // hidden link,
  105. // GM_addStyle(".AnswerItem:has(.RichText-LinkCardContainer) { display: none !important; } ");
  106. // hidden video
  107. GM_addStyle(".AnswerItem:has(.VideoCard-video-content) { display: none !important; } ");
  108. GM_addStyle(".AnswerItem:has(.VideoAnswerPlayer) { display: none !important; } ");
  109. // go back and refresh
  110. document.querySelector('div[class="CornerButtons"]').addEventListener('click', (e)=>{
  111. location.reload();
  112. });
  113. /****************** Question page *********************************/
  114.  
  115. /****************** Search page ***********************************************/
  116. // Hidden right bar
  117. GM_addStyle(".css-knqde {display: none !important;}");
  118. // Widen main bar
  119. GM_addStyle(".Search-container { width: 1500px !important; } ");
  120. GM_addStyle(".SearchMain { width: 1500px !important; } ");
  121. /****************** Search page ***********************************************/
  122.  
  123. /****************** Topic page ***********************************************/
  124. // Widen main bar
  125. GM_addStyle('div[data-za-detail-view-path-module="TopicItem"] { max-width: 1500px !important; } ');
  126. /****************** Topic page ***********************************************/
  127.  
  128. /****************** Column page **********************************************************/
  129. // GM_addStyle('main[role="main"]>div>div:last-child {width: 1500px}');
  130. // GM_addStyle('main[role="main"]>div>div:last-child > div > div {width: 1500px}');
  131. /****************** Column page **********************************************************/
  132.  
  133. /**************************** is-collapsed *************************************************/
  134. // reload for MutationObserver
  135. window.addEventListener('load', (e)=>{
  136. console.log("load", e);
  137. let btn=document.querySelector('a[class="QuestionMainAction ViewAll-QuestionMainAction"]');
  138. btn.addEventListener('click', (e)=>{
  139. e.stopPropagation();
  140. let h = window.open(btn.href, "_self");
  141. h.location.reload();
  142. })
  143. });
  144. // close to is collapsed
  145. try {
  146. (new MutationObserver(mutations => {
  147. if (!window.location.href.contains("zhihu.com/question")) {
  148. console.log("href", window.location.href);
  149. return
  150. }
  151. for(let mutation of mutations) {
  152. if (mutation.addedNodes.length > 0) {
  153. for (let node of mutation.addedNodes) {
  154. if (node===null) {
  155. continue;
  156. }
  157. node.querySelector('button[data-zop-retract-question="true"]').click();
  158. }
  159. }
  160. }
  161. })).observe(document.querySelector('div[role="list"]'), {
  162. childList: true, // 观察直接子节点
  163. subtree: true,
  164. attributes: false,
  165. characterData: false
  166. });
  167. } catch (e) {
  168. console.log(e)
  169. }
  170. /**************************** is-collapsed *************************************************/
  171.  
  172. /******************* Free copy**********************************************/
  173. let body = document.getElementsByTagName('body')[0];
  174. body.addEventListener('copy', function (e) {
  175. e.stopPropagation();
  176. console.log("copy...");
  177. }, false);
  178. body.addEventListener('contextmenu', (e) => {
  179. e.stopPropagation();
  180. }, false);
  181. body.addEventListener('select', (event) => {
  182. event.stopPropagation();
  183. }, false);
  184. body.addEventListener('selectstart', (event) => {
  185. event.stopPropagation();
  186. }, false);
  187. body.addEventListener('cut', (event) => {
  188. event.stopPropagation();
  189. }, false);
  190. body.addEventListener('dragstart', (event) => {
  191. event.stopPropagation();
  192. }, false);
  193. body.addEventListener('mousemove', (event) => {
  194. event.stopPropagation();
  195. }, false);
  196. /******************* Free copy**********************************************/
  197. })()

QingJ © 2025

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