自动关闭知乎登录提示

仅仅用于关闭自动弹出的登录提示,不干别的,未来也不会去干别的。

目前为 2023-04-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         自动关闭知乎登录提示
// @namespace    https://github.com/F9y4ng/GreasyFork-Scripts/
// @version      1.1
// @description  仅仅用于关闭自动弹出的登录提示,不干别的,未来也不会去干别的。
// @author       F9y4ng
// @match        *://*.zhihu.com/*
// @icon         none
// @grant        none
// @compatible   Edge version>=105
// @compatible   Chrome version>=105
// @compatible   Firefox version>=103
// @compatible   Opera version>=91
// @compatible   Safari version>=15.4
// @license      GPL-3.0-only
// @copyright    2023, F9y4ng
// @run-at       document-start
// ==/UserScript==

(function () {
  "use strict";
  let nologin = true;
  const targetNode = document;
  const config = { attributes: true, childList: true, subtree: true };
  const callback = function (mutationsList, observer) {
    mutationsList.forEach(() => {
      if (nologin) {
        const loginNode = document.querySelector(`button[aria-label="关闭"]`);
        if (loginNode) loginNode.click();
      }
      const registFloatNode = document.querySelector(`body>div:not([class],[style],[id]) div[class^='css-']:has(svg[class*='css-'])`);
      if (registFloatNode) {
        registFloatNode.style.display = "none";
        registFloatNode.remove();
      }
      const nodes = document.querySelectorAll(`:is(.ColumnPageHeader,.AppHeader-inner,.PageHeader) button[class~='Button']:not(:has(svg))`);
      if (nodes.length > 0) {
        nodes.forEach(node => {
          node.addEventListener("mouseover", () => {
            nologin = false;
          });
        });
      }
    });
  };
  const observer = new MutationObserver(callback);
  observer.observe(targetNode, config);
})();