Fuck ZhiHu Mobile

日他娘的逼乎手机网页版; 针对手机版进行修改,把所有的“App 内查看”按钮屏蔽了;

  1. // ==UserScript==
  2. // @name Fuck ZhiHu Mobile
  3. // @namespace https://github.com/ipcjs
  4. // @version 2.0.2
  5. // @description 日他娘的逼乎手机网页版; 针对手机版进行修改,把所有的“App 内查看”按钮屏蔽了;
  6. // @author ipcjs
  7. // @include https://www.zhihu.com/*
  8. // @include https://zhuanlan.zhihu.com/*
  9. // @grant GM_addStyle
  10. // @require https://greasyfork.org/scripts/373283-ipcjs-lib-js/code/ipcjslibjs.js?version=647820
  11. // ==/UserScript==
  12.  
  13. ipcjs.installInto(({ log, html, $ }) => {
  14. log = GM_info.script.name.endsWith('.dev') ? log : () => { }
  15. GM_addStyle(`
  16. .DownloadGuide {
  17. display: none;
  18. }
  19. .OpenInAppButton {
  20. display: none;
  21. }
  22. .MobileAppHeader-downloadLink {
  23. display: none;
  24. }
  25. /*
  26. button.ContentItem-more {
  27. position: absolute;
  28. }
  29. */
  30. `)
  31.  
  32. installToContent(document)
  33.  
  34. new MutationObserver((mutations, observer) => {
  35. // log(mutations)
  36. for (let m of mutations) {
  37. const $target = $(m.target)
  38. for (let node of m.addedNodes) {
  39. if (node.nodeType === Node.ELEMENT_NODE) {
  40. if ($(node).hasClass('RichContent-inner')
  41. && $target.hasClass('RichContent') && $target.hasClass('is-collapsed')) {
  42. log('contentInner added, need reinstall', node)
  43. installToContent($target.ele.parentElement)
  44. } else {
  45. installToContent(node)
  46. }
  47. }
  48. }
  49. }
  50. }).observe(document.body, {
  51. childList: true,
  52. subtree: true
  53. })
  54.  
  55.  
  56. function installToContent(node) {
  57. if (!node.querySelectorAll) {
  58. return
  59. }
  60. const contentItems = node.querySelectorAll('.RichContent')
  61. const collapseButtonHtml = '<button data-zop-retract-question="true" type="button" class="Button ContentItem-action ContentItem-rightButton Button--plain"><span class="RichContent-collapsedText">收起</span><span style="display: inline-flex; align-items: center;">​<svg class="Zi Zi--ArrowDown ContentItem-arrowIcon is-active" fill="currentColor" viewBox="0 0 24 24" width="24" height="24"><path d="M12 13L8.285 9.218a.758.758 0 0 0-1.064 0 .738.738 0 0 0 0 1.052l4.249 4.512a.758.758 0 0 0 1.064 0l4.246-4.512a.738.738 0 0 0 0-1.052.757.757 0 0 0-1.063 0L12.002 13z" fill-rule="evenodd"></path></svg></span></button>'
  62. if (contentItems.length > 0) {
  63. log('install', contentItems)
  64. }
  65. contentItems.forEach((content, index) => {
  66. const contentInner = content.querySelector('.RichContent-inner')
  67. const actions = content.querySelector('.ContentItem-actions')
  68. const expandButtonOuter = content.querySelector(':scope > button')
  69. const expandButtonInner = contentInner.querySelector(':scope > button')
  70.  
  71. const $content = $(content)
  72.  
  73. let diff = {
  74. expandButton: undefined,
  75. expandButtonText: undefined,
  76. onClick: undefined,
  77. onEach: undefined,
  78. }
  79. if (expandButtonOuter) {
  80. diff = {
  81. expandButton: expandButtonOuter,
  82. expandButtonText: '展开阅读全文',
  83. onClick: function toggleContent() {
  84. let collapseButton = actions.querySelector('button.Button.ContentItem-rightButton')
  85. if ($content.hasClass('is-collapsed')) {
  86. $content.removeClass('is-collapsed')
  87. contentInner.style.maxHeight = ''
  88. diff.expandButton.style.display = 'none'
  89. collapseButton = html(collapseButtonHtml)[0]
  90. collapseButton.addEventListener('click', toggleContent)
  91. actions.appendChild(collapseButton)
  92. } else {
  93. $content.addClass('is-collapsed')
  94. contentInner.style.maxHeight = '400px'
  95. diff.expandButton.style.display = 'inline'
  96. actions.removeChild(collapseButton)
  97. }
  98. },
  99. onEach: () => { }
  100. }
  101. } else if (expandButtonInner) {
  102. const contentCover = content.querySelector('.RichContent-cover')
  103. diff = {
  104. expandButton: expandButtonInner,
  105. expandButtonText: contentCover ? '展开' : '跳转',
  106. onClick: function gotoDetail() {
  107. if (contentCover) {
  108. contentCover.click()
  109. } else {
  110. const urlMeta = content.parentElement.querySelector(':scope > meta[itemprop=url]')
  111. location.href = urlMeta.content
  112. }
  113. },
  114. onEach: function () {
  115. $content.removeClass('is-collapsed')
  116. }
  117. }
  118. } else {
  119. log('expandButton no found')
  120. return
  121. }
  122.  
  123.  
  124. diff.onEach()
  125. if (diff.expandButton.innerText.startsWith('App 内查看')) {
  126. diff.expandButton.innerText = diff.expandButtonText
  127. diff.expandButton.addEventListener('click', e => {
  128. e.stopPropagation()
  129. diff.onClick()
  130. }, true)
  131. } else {
  132. log('skip', content)
  133. return
  134. }
  135. contentInner.addEventListener('click', e => {
  136. e.stopPropagation()
  137. diff.onClick()
  138. }, true)
  139. })
  140. }
  141. })