知乎单个回答详情页移除多余元素

知乎单个回答详情页移除多余元素,用来截图或分享图

  1. // ==UserScript==
  2. // @name 知乎单个回答详情页移除多余元素
  3. // @namespace http://tampermonkey.net
  4. // @version 1.1.6
  5. // @description 知乎单个回答详情页移除多余元素,用来截图或分享图
  6. // @author general
  7. // @match https://www.zhihu.com/*
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13.  
  14. /******/ (() => { // webpackBootstrap
  15. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  16. function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
  17. function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
  18. function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
  19. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  20. function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  21. var ZhihuAnswerDetailPage = /*#__PURE__*/function () {
  22. function ZhihuAnswerDetailPage() {
  23. _classCallCheck(this, ZhihuAnswerDetailPage);
  24. }
  25. return _createClass(ZhihuAnswerDetailPage, [{
  26. key: "start",
  27. value: function start() {
  28. var tankUtil = window.tankUtils;
  29. if (!tankUtil) {
  30. return;
  31. }
  32. // 先添加按钮,根据按钮操作,是否要移除 dom
  33. if (tankUtil.isPC) {
  34. this.addPCOperationButton();
  35. } else {
  36. this.removeMobilePageDom();
  37. }
  38. }
  39.  
  40. /**
  41. * 创建操作按钮
  42. */
  43. }, {
  44. key: "createRemoveDomButton",
  45. value: function createRemoveDomButton() {
  46. var removeDomButton = document.createElement('button');
  47. removeDomButton.innerText = '移除其他元素';
  48. window.tankUtils.commonSetDomStyle(removeDomButton, {
  49. padding: '4px 8px',
  50. 'border-radius': '4px',
  51. background: '#ff7000',
  52. color: '#fff',
  53. 'font-size': '16px'
  54. });
  55. return removeDomButton;
  56. }
  57.  
  58. /**
  59. * PC 上,添加操作按钮
  60. */
  61. }, {
  62. key: "addPCOperationButton",
  63. value: function addPCOperationButton() {
  64. var _this = this;
  65. var removeDomButton = this.createRemoveDomButton();
  66. var questionHeaderTopics = window.tankUtils.findDom('.QuestionHeader-topics');
  67. if (questionHeaderTopics) {
  68. questionHeaderTopics.appendChild(removeDomButton);
  69. }
  70. removeDomButton.onclick = function () {
  71. _this.removePCPageDom();
  72. };
  73. }
  74.  
  75. /**
  76. * 移除 PC 页面上的 DOM
  77. */
  78. }, {
  79. key: "removePCPageDom",
  80. value: function removePCPageDom() {
  81. {
  82. // 移除右边的侧边栏
  83. window.tankUtils.removeDom('.Question-sideColumn');
  84.  
  85. // 移除右边的广告
  86. window.tankUtils.removeDom('.Question-sideColumnAdContainer');
  87.  
  88. // 移除右边的关注者、被浏览
  89. window.tankUtils.removeDom('.QuestionFollowStatus');
  90.  
  91. // 移除右边的作者 AnswerAuthor
  92. window.tankUtils.removeDom('.AnswerAuthor');
  93.  
  94. // 移除页面底部的网站声明信息
  95. window.tankUtils.removeDom('[role="contentinfo"]');
  96.  
  97. // 移除更多回答
  98. window.tankUtils.removeDom('.MoreAnswers');
  99.  
  100. // 移除查看全部回答
  101. window.tankUtils.removeDom('.ViewAll');
  102.  
  103. // 移除补充信息
  104. window.tankUtils.removeDom('[role="complementary"]');
  105. }
  106. }
  107.  
  108. /**
  109. * 移除移动端页面上的 DOM
  110. */
  111. }, {
  112. key: "removeMobilePageDom",
  113. value: function removeMobilePageDom() {
  114. {
  115. // 移除页面顶部的【打开App】
  116. var headerOpenBtn = window.tankUtils.findDom('.Button--withLabel');
  117. if (headerOpenBtn) {
  118. var parentElementL1 = headerOpenBtn.parentElement;
  119. parentElementL1.removeChild(headerOpenBtn);
  120. }
  121. }
  122. {
  123. // 移除作者信息
  124. window.tankUtils.removeDom('[itemprop="author"]');
  125.  
  126. // 移除 App 内打开
  127. window.tankUtils.removeDom('.OpenInAppButton');
  128.  
  129. // 移除右下角的 Avatar
  130. window.tankUtils.removeDom('.Avatar');
  131. }
  132. {
  133. // 移除 AI 总结
  134. var richContentDom = window.tankUtils.findDom('.RichContent');
  135. if (richContentDom && richContentDom.nextElementSibling) {
  136. richContentDom.nextElementSibling.remove();
  137. }
  138. }
  139. {
  140. // oia-action-bar
  141. var oiaActionBar = window.tankUtils.findDom('.oia-action-bar');
  142. if (oiaActionBar) {
  143. var agreeButton = window.tankUtils.findDom('.ZDI--AgreeFill24');
  144. if (agreeButton) {
  145. var agreeNumSpan = agreeButton.nextElementSibling;
  146. if (agreeNumSpan) {
  147. var innerText = (agreeNumSpan.innerText || '').replace('已赞同 ', '').trim();
  148. if (innerText) {
  149. var agreeNum = parseInt(innerText || 0);
  150. agreeNumSpan.innerText = "".concat(agreeNum);
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }]);
  158. }();
  159. window.onload = function () {
  160. var zhihuAnswerDetailPage = new ZhihuAnswerDetailPage();
  161. setTimeout(function () {
  162. zhihuAnswerDetailPage.start();
  163. console.log('zhihuAnswerDetailPage.start()');
  164. }, 3000);
  165. };
  166. /******/ })()
  167. ;

QingJ © 2025

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