极简知乎

有些时候看知乎不是那么方便,你懂的.

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

  1. // ==UserScript==
  2. // @name 极简知乎
  3. // @version 0.1.18
  4. // @author hceasy
  5. // @namespace https://hceasy.com
  6. // @supportURL https://github.com/hceasy/simpleZhiHu/issues
  7. // @description 有些时候看知乎不是那么方便,你懂的.
  8. // @match *://www.zhihu.com/question/*
  9. // @match *://www.zhihu.com/search*
  10. // @match *://www.zhihu.com/hot
  11. // @match *://www.zhihu.com/follow
  12. // @match *://www.zhihu.com/
  13. // @match *://www.zhihu.com/signin*
  14. // @run-at document-end
  15. // ==/UserScript==
  16. ; (function () {
  17. 'use strict'
  18. // 设置菜单
  19. const menuHTML = '<div class="extMenu"><img src="https://zhstatic.zhihu.com/assets/error/liukanshan_wire.svg" alt="刘看山" width="15px" height="19px"><p>显示提问标题栏 <input id="showQuestion" type="checkbox"></p><p>浏览器标题替换 <input id="showFakeTitle" type="checkbox"></p><p>黑名单列表:</p><p><textarea placeholder="刘看山,匿名用户" id="blackList" cols="20" rows="2"></textarea></p><p><button id="saveConfig">保存</button></p></div>'
  20. const menuCss = '.extMenu {position: fixed;top: 10px;right: 10px;width: 15px;height: 19px;font-size: 12px;overflow: hidden;}.extMenu:hover {width: auto;height: auto;border: 1px solid #000;padding:10px;}.extMenu:hover img {display: none;}'
  21.  
  22. // 区分搜索问答页面
  23. const webUrl = window.location.pathname
  24. let pageType
  25. if (webUrl.indexOf('question') >= 0) {
  26. pageType = 'question'
  27. } else if (webUrl.indexOf('search') >= 0) {
  28. pageType = 'search'
  29. } else if (webUrl.indexOf('hot') >= 0 || webUrl.indexOf('follow') >= 0 || window.location.href === "https://www.zhihu.com/") {
  30. pageType = 'hot'
  31. } else if (webUrl.indexOf('signin') >= 0) {
  32. pageType = 'signin'
  33. }
  34.  
  35. // 用GitHub的图标替换
  36. const fake_title = 'GitHub'
  37. // icon也改了
  38. const fake_icon = 'https://github.githubassets.com/favicon.ico'
  39. let link =
  40. document.querySelector("link[rel*='icon']") ||
  41. document.createElement('link')
  42. window.onload = function () {
  43. const sConfig = window.localStorage
  44. if (sConfig.fakeTitle === undefined || sConfig.showQuestion === undefined || sConfig.blackList === undefined) {
  45. sConfig.fakeTitle = 'true'
  46. sConfig.showQuestion = 'true'
  47. sConfig.blackList = ''
  48. }
  49. // 添加菜单
  50. let cssFix = document.createElement('style')
  51. cssFix.innerHTML += menuCss
  52. document.getElementsByTagName('head')[0].appendChild(cssFix)
  53. let htmlFix = document.createElement('div')
  54. htmlFix.innerHTML += menuHTML
  55. document.body.appendChild(htmlFix)
  56.  
  57. // 绑定操作
  58. document.getElementById('showFakeTitle').checked = JSON.parse(sConfig.fakeTitle)
  59. document.getElementById('showQuestion').checked = JSON.parse(sConfig.showQuestion)
  60. document.getElementById('blackList').value = sConfig.blackList
  61. document.getElementById('saveConfig').addEventListener('click', function () {
  62. sConfig.fakeTitle = document.getElementById('showFakeTitle').checked
  63. sConfig.showQuestion = document.getElementById('showQuestion').checked
  64. sConfig.blackList = document.getElementById('blackList').value.split(',')
  65. window.location.reload()
  66. })
  67.  
  68. // 改下标题
  69. if (sConfig.fakeTitle === 'true') {
  70. window.document.title = fake_title
  71. link.type = 'image/x-icon'
  72. link.rel = 'shortcut icon'
  73. link.href = fake_icon
  74. document.getElementsByTagName('head')[0].appendChild(link)
  75. }
  76. switch (pageType) {
  77. case 'question':
  78. fixQuestionPage()
  79. break
  80. case 'search':
  81. fixSearchPage()
  82. break
  83. case 'hot':
  84. fixHomePage()
  85. break
  86. case 'signin':
  87. addHotList()
  88. break
  89. }
  90. }
  91. window.onscroll = function () {
  92. hideAuthor()
  93. }
  94. function addHotList () {
  95. let signButton = document.querySelector('.SignFlow-submitButton')
  96. if (signButton) {
  97. let hotButton = signButton.cloneNode(false)
  98. let parent = signButton.parentNode;
  99. parent.appendChild(hotButton)
  100. hotButton.innerHTML = '不想登录(不可用),去热榜转转'
  101. hotButton.onclick = function () {
  102. location.href = 'https://www.zhihu.com/billboard'
  103. }
  104. }
  105. }
  106. function fixQuestionPage () {
  107. const sConfig = window.localStorage
  108. let cssFix = document.createElement('style')
  109. // 吸底的评论栏
  110. cssFix.innerHTML += '.RichContent-actions{bottom:auto !important;}'
  111. // 直接屏蔽顶部问题相关
  112. if (sConfig.showQuestion === 'false') {
  113. cssFix.innerHTML += '.QuestionHeader-footer{display:none !important;}'
  114. cssFix.innerHTML += '.QuestionHeader{display:none !important;}'
  115. cssFix.innerHTML += '.Question-main{margin:0 !important;}'
  116. }
  117. // 问题页面登录(不可用)弹窗
  118. cssFix.innerHTML += '.Modal-backdrop{background-color: transparent;}'
  119. cssFix.innerHTML += '.signFlowModal{display:none !important;}'
  120. // 顶部关键词
  121. cssFix.innerHTML += '.QuestionHeader-tags{display:none !important;}'
  122. // 问题相关撑满
  123. cssFix.innerHTML += '.QuestionHeader-content{width:100% !important;}'
  124. cssFix.innerHTML += '.QuestionHeader{min-width:auto !important;}'
  125. // 内容图片/视频最大300px
  126. cssFix.innerHTML += '.origin_image{max-width:300px !important;}'
  127. cssFix.innerHTML += '.RichText-video{max-width:300px !important;}'
  128. // 内容链接去特征
  129. cssFix.innerHTML +=
  130. '.LinkCard{margin:auto !important;display:inline !important;}.LinkCard-content{background-color: transparent;}.LinkCard-title{color:#999 !important}'
  131. // 点赞
  132. cssFix.innerHTML +=
  133. '.VoteButton{color:#999 !important;background: none; !important}'
  134. // 广告商品链接
  135. cssFix.innerHTML +=
  136. '.RichText-MCNLinkCardContainer{display:none !important;}'
  137. document.getElementsByTagName('head')[0].appendChild(cssFix)
  138. // 右侧问题相关
  139. document.getElementsByClassName('QuestionHeader-side')[1].style.display =
  140. 'none'
  141. document.getElementsByClassName('Question-sideColumn')[0].style.display =
  142. 'none'
  143. // 顶部问题标题
  144. document.getElementsByTagName('header')[0].style.display = 'none'
  145. // 内容撑满
  146. document.getElementsByClassName('Question-main')[0].style.width = 'auto'
  147. document.getElementsByClassName('Question-main')[0].style.padding = '0'
  148. document.getElementsByClassName('Question-mainColumn')[0].style.margin =
  149. '0 auto'
  150. }
  151. function fixSearchPage () {
  152. let cssFix = document.createElement('style')
  153. // header
  154. cssFix.innerHTML += 'header{display:none !important;}'
  155. // SearchTabs
  156. cssFix.innerHTML += '.SearchTabs{display:none !important;}'
  157. // SearchSideBar
  158. cssFix.innerHTML += '.SearchSideBar{display:none !important;}'
  159. // CornerButtons
  160. cssFix.innerHTML += '.CornerButtons{display:none !important;}'
  161. // .SearchMain
  162. cssFix.innerHTML +=
  163. '.SearchMain{width:100% !important;margin: 0 !important;}'
  164. // Search-container
  165. cssFix.innerHTML +=
  166. '.Search-container{width: auto !important;min-height: auto !important;margin:none !important;}'
  167. cssFix.innerHTML += '.SearchSections{width:auto !important}'
  168. // 点赞
  169. cssFix.innerHTML +=
  170. '.VoteButton{color:#999 !important;background: none; !important}'
  171. // 内容图片/视频最大300px
  172. cssFix.innerHTML += '.origin_image{max-width:300px !important;}'
  173. cssFix.innerHTML += '.RichText-video{max-width:300px !important;}'
  174. document.getElementsByTagName('head')[0].appendChild(cssFix)
  175. }
  176. function fixHomePage () {
  177. let cssFix = document.createElement('style')
  178. // header
  179. cssFix.innerHTML += '.GlobalSideBar{display:none !important;}'
  180. cssFix.innerHTML += '.Topstory-container{width:100% !important;padding:0 !important}'
  181. cssFix.innerHTML += '.Topstory-mainColumn{width:100% !important;}'
  182. document.getElementsByTagName('head')[0].appendChild(cssFix)
  183. }
  184. function hideAuthor () {
  185. const answerList = document.getElementsByClassName('List-item')
  186. for (let index = 0; index < answerList.length; index++) {
  187. const obj = answerList[index]
  188. const key = JSON.parse(obj.getElementsByTagName("div")[0].getAttribute("data-zop"))
  189. if (key === null) {
  190. return
  191. }
  192. const blackList = window.localStorage.blackList.split(',')
  193. blackList.forEach(name => {
  194. if (key.authorName === name) {
  195. obj.style.display = 'none'
  196. }
  197. });
  198. }
  199. }
  200. })()

QingJ © 2025

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