清爽知乎

将网页主体部分变宽,去除杂冗部分,并添加一些实用的功能

// ==UserScript==
// @name         清爽知乎
// @namespace    https://huanfei.top/
// @version      2.0.1
// @author       huanfei
// @description  将网页主体部分变宽,去除杂冗部分,并添加一些实用的功能
// @license      MIT
// @icon         https://static.zhihu.com/heifetz/favicon.ico
// @match        *://*.zhihu.com/*
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(e=>{if(typeof GM_addStyle=="function"){GM_addStyle(e);return}const i=document.createElement("style");i.textContent=e,document.head.append(i)})(" ul.AppHeader-Tabs li:has(a[href*=zhida]){display:none}.Topstory-mainColumn{width:inherit}.Topstory-mainColumn .Pc-Business-Card-PcTopFeedBanner,.Topstory-mainColumn .Pc-feedAd-new,.Topstory-mainColumn .WriteArea,.Topstory-mainColumn+div{display:none}.Question-main .Question-mainColumn,.Question-main .ListShortcut{width:inherit}.Question-main .Question-mainColumn+div,.Question-main .ListShortcut+div{display:none}.Question-main .AuthorInfo.AnswerItem-authorInfo .FollowButton,.Question-main .Pc-word-new{display:none}.Question-main .RichContent--unescapable.is-collapsed .RichContent-inner{min-height:125px}.QuestionHeader .QuestionHeader-content{width:var(--app-width)}.QuestionHeader .QuestionHeader-content .QuestionHeader-main{width:inherit}.QuestionHeader .QuestionHeader-content .QuestionHeader-side{transform:translate(-100%)}.QuestionHeader .QuestionHeader-content .QuestionHeader-side *{font-size:14px}.QuestionHeader .QuestionHeader-content .QuestionHeader-side div.NumberBoard-item .NumberBoard-itemInner{padding-left:20px}.Profile-main .Profile-mainColumn{width:inherit}.Profile-main .Profile-mainColumn+div,.Profile-main .Profile-mainColumn .AuthorInfo-Widget{display:none}.CollectionsDetailPage .CollectionsDetailPage-mainColumn{width:inherit}.CollectionsDetailPage .CollectionsDetailPage-mainColumn+div{min-width:20%}.QuestionWaiting .QuestionWaiting-mainColumn{width:inherit}.QuestionWaiting .QuestionWaiting-mainColumn+div{display:none}.Search-container .SearchMain{width:inherit}.Search-container .SearchMain+div{display:none}.Notifications-Layout .Notifications-Main{width:inherit}.Notifications-Layout .Notifications-Main+div{display:none}.CornerAnimayedFlex{height:130px}.CornerAnimayedFlex>button:nth-child(2){margin-top:10px;transform:rotate(90deg)}html[data-theme=dark] body{color:#cecece}html[data-theme=dark] body h2.ContentItem-title{color:#cbcbcb} ");

(function () {
  'use strict';

  var _GM_registerMenuCommand = /* @__PURE__ */ (() => typeof GM_registerMenuCommand != "undefined" ? GM_registerMenuCommand : void 0)();
  var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  window.onload = () => {
    var _a, _b;
    const button = (_a = document.querySelector("button.CornerButton")) == null ? void 0 : _a.cloneNode(true);
    if (!button) return;
    button.setAttribute("aria-label", "全部折叠");
    button.setAttribute("data-tooltip", "全部折叠");
    button.addEventListener("click", () => {
      var _a2;
      const topElement = (_a2 = [...document.querySelectorAll(".Topstory-recommend .Card.TopstoryItem")].reverse().find((el) => el.getBoundingClientRect().y < 0)) == null ? void 0 : _a2.nextElementSibling;
      const cards = document.querySelectorAll(".RichContent:not(.is-collapsed) .ContentItem-action:has(.RichContent-collapsedText)");
      const comments = document.querySelectorAll(".Card.TopstoryItem:has(.Comments-container) button.ContentItem-action:has(.Zi--Comment)");
      const toFoldItems = [...comments, ...cards];
      if (toFoldItems.length > 0) {
        toFoldItems.forEach((el) => el.click());
        requestAnimationFrame(() => topElement == null ? void 0 : topElement.scrollIntoView());
      }
    });
    (_b = document.querySelector(".CornerAnimayedFlex")) == null ? void 0 : _b.append(button);
  };
  window.addEventListener("copy", (e) => e.stopPropagation(), true);
  document.addEventListener("click", (e) => {
    if (e.target instanceof HTMLElement && e.target.closest("a.external")) {
      e.preventDefault();
      const raw = new URL(e.target.href).searchParams.get("target");
      raw && window.open(raw, "_blank");
    }
  });
  const originalFetch = _unsafeWindow.fetch;
  const hookFetch = (...args) => {
    const [url, _] = args;
    if (url.startsWith("/api/v3/entity_word")) {
      return Promise.resolve(
        new Response(
          JSON.stringify({
            search_words: null,
            ab_params: { qa_searchword: "0" }
          }),
          { status: 200, headers: { "Content-Type": "application/json" } }
        )
      );
    }
    return originalFetch(...args);
  };
  _unsafeWindow.fetch = hookFetch;
  _GM_registerMenuCommand("深浅主题切换(将刷新页面)", () => {
    const theme = document.documentElement.dataset.theme === "light" ? "dark" : "light";
    const url = new URL(location.href);
    const params = new URLSearchParams(url.search);
    params.set("theme", theme);
    url.search = params.toLocaleString();
    location.href = url.href;
  });

})();

QingJ © 2025

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