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

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

// ==UserScript==
// @name                                    知乎单个回答详情页移除多余元素
// @namespace                               http://tampermonkey.net
// @version                                 1.1.6
// @description                             知乎单个回答详情页移除多余元素,用来截图或分享图
// @author                                  general
// @match                                   https://www.zhihu.com/*
// @license                                 MIT
// @grant                                   none
// ==/UserScript==



/******/ (() => { // webpackBootstrap
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); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
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); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
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); }
var ZhihuAnswerDetailPage = /*#__PURE__*/function () {
  function ZhihuAnswerDetailPage() {
    _classCallCheck(this, ZhihuAnswerDetailPage);
  }
  return _createClass(ZhihuAnswerDetailPage, [{
    key: "start",
    value: function start() {
      var tankUtil = window.tankUtils;
      if (!tankUtil) {
        return;
      }
      // 先添加按钮,根据按钮操作,是否要移除 dom
      if (tankUtil.isPC) {
        this.addPCOperationButton();
      } else {
        this.removeMobilePageDom();
      }
    }

    /**
     * 创建操作按钮
     */
  }, {
    key: "createRemoveDomButton",
    value: function createRemoveDomButton() {
      var removeDomButton = document.createElement('button');
      removeDomButton.innerText = '移除其他元素';
      window.tankUtils.commonSetDomStyle(removeDomButton, {
        padding: '4px 8px',
        'border-radius': '4px',
        background: '#ff7000',
        color: '#fff',
        'font-size': '16px'
      });
      return removeDomButton;
    }

    /**
     * PC 上,添加操作按钮
     */
  }, {
    key: "addPCOperationButton",
    value: function addPCOperationButton() {
      var _this = this;
      var removeDomButton = this.createRemoveDomButton();
      var questionHeaderTopics = window.tankUtils.findDom('.QuestionHeader-topics');
      if (questionHeaderTopics) {
        questionHeaderTopics.appendChild(removeDomButton);
      }
      removeDomButton.onclick = function () {
        _this.removePCPageDom();
      };
    }

    /**
     * 移除 PC 页面上的 DOM
     */
  }, {
    key: "removePCPageDom",
    value: function removePCPageDom() {
      {
        // 移除右边的侧边栏
        window.tankUtils.removeDom('.Question-sideColumn');

        // 移除右边的广告
        window.tankUtils.removeDom('.Question-sideColumnAdContainer');

        // 移除右边的关注者、被浏览
        window.tankUtils.removeDom('.QuestionFollowStatus');

        // 移除右边的作者 AnswerAuthor
        window.tankUtils.removeDom('.AnswerAuthor');

        // 移除页面底部的网站声明信息
        window.tankUtils.removeDom('[role="contentinfo"]');

        // 移除更多回答
        window.tankUtils.removeDom('.MoreAnswers');

        // 移除查看全部回答
        window.tankUtils.removeDom('.ViewAll');

        // 移除补充信息
        window.tankUtils.removeDom('[role="complementary"]');
      }
    }

    /**
     * 移除移动端页面上的 DOM
     */
  }, {
    key: "removeMobilePageDom",
    value: function removeMobilePageDom() {
      {
        // 移除页面顶部的【打开App】
        var headerOpenBtn = window.tankUtils.findDom('.Button--withLabel');
        if (headerOpenBtn) {
          var parentElementL1 = headerOpenBtn.parentElement;
          parentElementL1.removeChild(headerOpenBtn);
        }
      }
      {
        // 移除作者信息
        window.tankUtils.removeDom('[itemprop="author"]');

        // 移除 App 内打开
        window.tankUtils.removeDom('.OpenInAppButton');

        // 移除右下角的 Avatar
        window.tankUtils.removeDom('.Avatar');
      }
      {
        // 移除 AI 总结
        var richContentDom = window.tankUtils.findDom('.RichContent');
        if (richContentDom && richContentDom.nextElementSibling) {
          richContentDom.nextElementSibling.remove();
        }
      }
      {
        // oia-action-bar
        var oiaActionBar = window.tankUtils.findDom('.oia-action-bar');
        if (oiaActionBar) {
          var agreeButton = window.tankUtils.findDom('.ZDI--AgreeFill24');
          if (agreeButton) {
            var agreeNumSpan = agreeButton.nextElementSibling;
            if (agreeNumSpan) {
              var innerText = (agreeNumSpan.innerText || '').replace('已赞同 ', '').trim();
              if (innerText) {
                var agreeNum = parseInt(innerText || 0);
                agreeNumSpan.innerText = "".concat(agreeNum);
              }
            }
          }
        }
      }
    }
  }]);
}();
window.onload = function () {
  var zhihuAnswerDetailPage = new ZhihuAnswerDetailPage();
  setTimeout(function () {
    zhihuAnswerDetailPage.start();
    console.log('zhihuAnswerDetailPage.start()');
  }, 3000);
};
/******/ })()
;

QingJ © 2025

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