极简知乎

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

目前为 2021-09-17 提交的版本。查看 最新版本

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

QingJ © 2025

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