页面小优化(知乎/CSDN/简书)

(知乎:移除登录弹窗;CSDN:移除登录弹窗、免登录复制;简书:移除登录弹窗;)

当前为 2025-06-27 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         页面小优化(知乎/CSDN/简书)
// @icon         https://avatars.githubusercontent.com/u/43409097?v=4
// @namespace    http://tampermonkey.net/
// @version      2.1.1
// @description  (知乎:移除登录弹窗;CSDN:移除登录弹窗、免登录复制;简书:移除登录弹窗;)
// @author       leekbillow
// @homepage     https://github.com/leekbillow/customTampermonkey
// @match        https://*.zhihu.com/*
// @match        https://*.blog.csdn.net/*
// @match        https://*.jianshu.com/*
// @grant        GM_addStyle
// @grant        GM_setClipboard
// @grant        GM_xmlhttpRequest
// @run-at       document-end
// ==/UserScript==

(function () {
  "use strict";

  switch (true) {
    case /\bblog\.csdn\.net\b(?!\.)/.test(location.hostname): {
      // CSDN
      GM_addStyle(`
        .passport-login-container,
        #passportbox
        {
            display:none!important
        }
        code
        {
          user-select:text!important;
        }
        .hljs-button
        {
          display:none!important;
        }
      `);
      document.body.querySelector("#content_views").oncopy = function () {
        GM_setClipboard(getSelection().toString());
      };
      break;
    }
    case /\bzhihu\.com\b(?!\.)/.test(location.hostname): {
      // 知乎
      // 不移除搜索结果
      if (location.pathname === "/search") document.querySelector(".List").removeChild = () => null;
      // 移除登录tooltip
      GM_addStyle(`
        .css-1wq6v87,
        .css-yoby3j
        {
          display:none!important;
        }
      `);
      //添加限制样式
      let bhuStyle = GM_addStyle(`
        .Modal-wrapper,
        .Modal-backdrop,
        .signFlowModal
        {
            display:none!important;
        }
      `);
      // 弹窗数量,专栏为2
      let rubbishDialogQuantity = 1 + /\bzhuanlan\.zhihu\.com\b(?!\.)/.test(location.hostname),
        clicked = [];
      // 取消首次自动弹出登录框,解除监听
      let removeStyle = function () {
          bhuStyle.remove();
        },
        targetNode = document.body,
        observerOptions = {
          childList: true,
          subtree: true,
        },
        observer = new MutationObserver(function (mutationList, observer) {
          let rubbishDialogCloseButtons = document.querySelectorAll(".Modal-closeButton");
          if (rubbishDialogCloseButtons.length > 0) {
            // 关闭弹窗
            rubbishDialogCloseButtons.forEach((E) => {
              if (clicked.includes(E)) return;
              E.click();
              clicked.push(E);
              if (--rubbishDialogQuantity < 1) {
                observer.disconnect();
                let loginButton = document.querySelector(".AppHeader-login");
                loginButton && (loginButton.onclick = () => removeStyle());
              }
            });
          } else return;
        });
      observer.observe(targetNode, observerOptions);
      //3秒后移除监听
      setTimeout(() => (observer.disconnect(), removeStyle()), 3000);
      break;
    }
    case /\bjianshu\.com\b(?!\.)/.test(location.hostname): {
      // 简书
      GM_addStyle(`
        body>div:last-child
        {
          display:none!important
        }
        body
        {
            overflow:auto!important
        }
      `);
      break;
    }
    default:
      break;
  }
})();