🏠 

Greasy Fork is available in English.

极简知乎

优化阅读界面,免登录,广告去除,黑名单功能.


安装此脚本?
  1. // ==UserScript==
  2. // @name 极简知乎
  3. // @version 0.1.34
  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 *://www2.zhihu.com/question/*
  10. // @match *://www.zhihu.com/search*
  11. // @match *://www.zhihu.com/hot
  12. // @match *://www.zhihu.com/follow
  13. // @match *://www.zhihu.com/
  14. // @match *://zhuanlan.zhihu.com/*
  15. // @match *://www.zhihu.com/signin*
  16. // @run-at document-end
  17. // ==/UserScript==
  18. ; (function () {
  19. 'use strict'
  20. // 设置菜单
  21. 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>页面宽度(694px/80%) <input id="pageWidth" type="text"></p><p>黑名单列表:</p><p><textarea placeholder="刘看山,匿名用户" id="blackList" cols="20" rows="2"></textarea></p><p><button id="saveConfig">保存</button></p></div>`
  22. 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;}`
  23. const blinkLiu = `.extMenu{animation:jumpLiu 5s infinite}@keyframes jumpLiu{0%{right:10px;background-color:#264653}20%{right:20px;background-color:#2a9d8f}40%{right:30px;background-color:#e9c46a}60%{right:10px;background-color:#f4a261}80%{right:20px;background-color:#e76f51}100%{right:10px;background-color:#264653}}`
  24. // 区分搜索问答页面
  25. const pathName = window.location.pathname
  26. const hostName = window.location.hostname
  27. let pageType
  28. if (pathName.indexOf('question') >= 0) {
  29. pageType = 'question'
  30. } else if (pathName.indexOf('search') >= 0) {
  31. pageType = 'search'
  32. } else if (pathName.indexOf('hot') >= 0 || pathName.indexOf('follow') >= 0 || window.location.href === "https://www.zhihu.com/") {
  33. pageType = 'hot'
  34. } else if (pathName.indexOf('signin') >= 0) {
  35. pageType = 'signin'
  36. } else if (hostName === "zhuanlan.zhihu.com") {
  37. pageType = 'zhuanlan'
  38. }
  39. // 用GitHub的图标替换
  40. const fake_title = 'GitHub'
  41. // icon也改了
  42. const fake_icon = 'https://github.githubassets.com/favicon.ico'
  43. let link =
  44. document.querySelector("link[rel*='icon']") ||
  45. document.createElement('link')
  46. window.onload = function () {
  47. const sConfig = window.localStorage
  48. if (sConfig.fakeTitle === undefined || sConfig.showQuestion === undefined || sConfig.blackList === undefined || sConfig.pageWidth === undefined) {
  49. sConfig.fakeTitle = 'true'
  50. sConfig.showQuestion = 'true'
  51. sConfig.blackList = ''
  52. sConfig.pageWidth = '694px'
  53. }
  54. // 不登陆不让滚动
  55. let modelsNum = 0
  56. let fixTimer = setInterval(() => {
  57. const mainHtml = document.getElementsByTagName('html')[0]
  58. if (mainHtml.style.overflow === 'hidden') {
  59. mainHtml.style.overflow = ''
  60. }
  61. }, 200);
  62. // 添加菜单
  63. let cssFix = document.createElement('style')
  64. cssFix.innerHTML += menuCss
  65. if (typeof (sConfig.blinkLiu) === 'undefined') {
  66. cssFix.innerHTML += blinkLiu
  67. }
  68. document.getElementsByTagName('head')[0].appendChild(cssFix)
  69. let htmlFix = document.createElement('div')
  70. htmlFix.innerHTML += menuHTML
  71. document.body.appendChild(htmlFix)
  72. // 绑定操作
  73. document.getElementById('showFakeTitle').checked = JSON.parse(sConfig.fakeTitle)
  74. document.getElementById('showQuestion').checked = JSON.parse(sConfig.showQuestion)
  75. document.getElementById('blackList').value = sConfig.blackList
  76. document.getElementById('pageWidth').value = sConfig.pageWidth
  77. document.getElementById('saveConfig').addEventListener('click', function () {
  78. sConfig.fakeTitle = document.getElementById('showFakeTitle').checked
  79. sConfig.showQuestion = document.getElementById('showQuestion').checked
  80. sConfig.blackList = document.getElementById('blackList').value.split(',')
  81. sConfig.pageWidth = document.getElementById('pageWidth').value
  82. sConfig.blinkLiu = false
  83. window.location.reload()
  84. })
  85. // 改下标题
  86. if (sConfig.fakeTitle === 'true') {
  87. window.document.title = fake_title
  88. link.type = 'image/x-icon'
  89. link.rel = 'shortcut icon'
  90. link.href = fake_icon
  91. document.getElementsByTagName('head')[0].appendChild(link)
  92. }
  93. switch (pageType) {
  94. case 'question':
  95. fixQuestionPage()
  96. fixPageWidth()
  97. break
  98. case 'search':
  99. fixSearchPage()
  100. break
  101. case 'hot':
  102. fixHomePage()
  103. break
  104. case 'signin':
  105. addHotList()
  106. break
  107. case 'zhuanlan':
  108. fixZhuanLan()
  109. break
  110. }
  111. hideAuthor()
  112. }
  113. window.onscroll = function () {
  114. hideAuthor()
  115. }
  116. function addHotList () {
  117. let signButton = document.querySelector('.SignFlow-submitButton')
  118. if (signButton) {
  119. let hotButton = signButton.cloneNode(false)
  120. let parent = signButton.parentNode;
  121. parent.appendChild(hotButton)
  122. hotButton.innerHTML = '不想登录,去热榜转转'
  123. hotButton.onclick = function () {
  124. location.href = 'https://www.zhihu.com/billboard'
  125. }
  126. }
  127. }
  128. function fixQuestionPage () {
  129. const sConfig = window.localStorage
  130. let cssFix = document.createElement('style')
  131. // 吸底的评论栏
  132. cssFix.innerHTML += `.RichContent-actions{bottom:auto !important;}`
  133. // 直接屏蔽顶部问题相关
  134. if (sConfig.showQuestion === 'false') {
  135. cssFix.innerHTML += `.QuestionHeader-footer{display:none !important;}`
  136. cssFix.innerHTML += `.QuestionHeader{display:none !important;}`
  137. cssFix.innerHTML += `.Question-main{margin:0 !important;}`
  138. }
  139. // 问题页面登录弹窗
  140. //cssFix.innerHTML += `.Modal-backdrop{background-color: transparent;}`
  141. //cssFix.innerHTML += `.signFlowModal{display:none !important;}`
  142. cssFix.innerHTML += `.ysn1om,.css-1hwwfws,.css-1ynzxqw{display:none !important;}`
  143. const but = document.getElementsByClassName('Button Modal-closeButton Button--plain')[0]
  144. but.click()
  145. // 顶部关键词
  146. cssFix.innerHTML += `.QuestionHeader-tags{display:none !important;}`
  147. // 问题相关撑满
  148. cssFix.innerHTML += `.QuestionHeader-content{padding-left:0}`
  149. cssFix.innerHTML += `.QuestionHeader-footer{display:none !important;}`
  150. // cssFix.innerHTML += `.QuestionHeader-main {margin:10px;}'
  151. cssFix.innerHTML += `.QuestionHeader{width:694px;margin:0 auto;padding:0;min-width:auto;}`
  152. // 未展开时内容居中
  153. cssFix.innerHTML += `.ListShortcut{margin:0 auto;}`
  154. // 展开时居中
  155. cssFix.innerHTML += `.Question-sideColumn{display:none;}`
  156. cssFix.innerHTML += `.Question-mainColumn{margin:0 auto;}`
  157. // 内容图片/视频最大300px
  158. cssFix.innerHTML += `.origin_image{max-width:300px !important;}`
  159. cssFix.innerHTML += `.RichText-video{max-width:300px !important;}`
  160. // 内容链接去特征
  161. cssFix.innerHTML +=
  162. `.LinkCard{margin:auto !important;display:inline !important;}.LinkCard-content{background-color: transparent;}.LinkCard-title{color:#999 !important}`
  163. // 点赞
  164. cssFix.innerHTML +=
  165. `.VoteButton{color:#999 !important;background: none; !important}`
  166. // 评论展开宽度
  167. cssFix.innerHTML += `.Modal--fullPage{width:650px}`
  168. // 评论展开关闭按钮复位
  169. cssFix.innerHTML += `.Modal-closeButton{right:0;}`
  170. cssFix.innerHTML += `.Modal-closeIcon{fill:#919191;}`
  171. // 广告商品链接
  172. cssFix.innerHTML +=
  173. `.RichText-MCNLinkCardContainer{display:none !important;}`
  174. // 夹缝广告
  175. cssFix.innerHTML +=
  176. `.Pc-word{display:none !important;}`
  177. document.getElementsByTagName('head')[0].appendChild(cssFix)
  178. // 右侧问题相关
  179. document.getElementsByClassName('QuestionHeader-side')[1].style.display =
  180. 'none'
  181. document.getElementsByClassName('Question-sideColumn')[0].style.display =
  182. 'none'
  183. // 顶部问题标题
  184. document.getElementsByTagName('header')[0].style.display = 'none'
  185. // 内容撑满
  186. document.getElementsByClassName('Question-main')[0].style.width = 'auto'
  187. document.getElementsByClassName('Question-main')[0].style.padding = '0'
  188. document.getElementsByClassName('Question-mainColumn')[0].style.margin =
  189. '0 auto'
  190. }
  191. function fixSearchPage () {
  192. let cssFix = document.createElement('style')
  193. // header
  194. cssFix.innerHTML += `header{display:none !important;}`
  195. // SearchTabs
  196. cssFix.innerHTML += `.SearchTabs{display:none !important;}`
  197. // SearchSideBar
  198. cssFix.innerHTML += `.SearchSideBar{display:none !important;}`
  199. // CornerButtons
  200. cssFix.innerHTML +=`.CornerButtons{display:none !important;}`
  201. // .SearchMain
  202. cssFix.innerHTML +=
  203. `.SearchMain{width:100% !important;margin: 0 !important;}`
  204. // Search-container
  205. cssFix.innerHTML +=
  206. `.Search-container{width: auto !important;min-height: auto !important;margin:none !important;}`
  207. cssFix.innerHTML += `.SearchSections{width:auto !important}`
  208. // 点赞
  209. cssFix.innerHTML +=
  210. `.VoteButton{color:#999 !important;background: none; !important}`
  211. // 内容图片/视频最大300px
  212. cssFix.innerHTML += `.origin_image{max-width:300px !important;}`
  213. cssFix.innerHTML += `.RichText-video{max-width:300px !important;}`
  214. document.getElementsByTagName('head')[0].appendChild(cssFix)
  215. }
  216. function fixZhuanLan () {
  217. let cssFix = document.createElement('style')
  218. cssFix.innerHTML +=`.Recommendations-Main{display:none !important;}`
  219. document.getElementsByTagName('head')[0].appendChild(cssFix)
  220. }
  221. function fixHomePage () {
  222. let cssFix = document.createElement('style')
  223. cssFix.innerHTML += `.GlobalSideBar{display:none !important;}`
  224. cssFix.innerHTML += `.Topstory-container{width:100% !important;padding:0 !important}`
  225. cssFix.innerHTML += `.Topstory-mainColumn{width:100% !important;}`
  226. document.getElementsByTagName('head')[0].appendChild(cssFix)
  227. }
  228. function hideAuthor () {
  229. const answerList = document.getElementsByClassName('List-item')
  230. for (let index = 0; index < answerList.length; index++) {
  231. const obj = answerList[index]
  232. if(obj.innerHTML.includes('本内容版权为知乎及版权方所有,侵权必究'))
  233. {
  234. obj.style.display = 'none'
  235. }
  236. const key = JSON.parse(obj.getElementsByClassName('ContentItem AnswerItem')[0].getAttribute("data-zop"))
  237. if (key === null) {
  238. return
  239. }
  240. const blackList = window.localStorage.blackList.split(',')
  241. blackList.forEach(name => {
  242. if (key.authorName === name) {
  243. obj.style.display = 'none'
  244. }
  245. });
  246. }
  247. }
  248. function fixPageWidth(){
  249. let page = document.querySelector(".Question-mainColumn")
  250. let header = document.querySelector(".QuestionHeader")
  251. let headerCont = document.getElementsByClassName("QuestionHeader-content")
  252. page.style.width = window.localStorage.pageWidth
  253. header.style.width = window.localStorage.pageWidth
  254. headerCont[1].style.width = '100%'
  255. }
  256. })()