-
Notifications
You must be signed in to change notification settings - Fork 48
/
Autoclose Zhihu Login.user.js
83 lines (76 loc) · 3.6 KB
/
Autoclose Zhihu Login.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// ==UserScript==
// @name 自动关闭知乎登录提示
// @name:en Autoclose Zhihu Login Prompt
// @name:zh-CN 自动关闭知乎登录提示
// @name:zh-TW 自動關閉知乎登錄提示
// @version 2024.04.06.1
// @author F9y4ng
// @description 自动关闭知乎自动弹出的登录与注册提示,仅仅用于关闭自动弹出的登录提示。
// @description:en Autoclose Zhihu Login Prompt is only used to close the pop-up login and registration prompt.
// @description:zh-CN 自动关闭知乎自动弹出的登录与注册提示,仅仅用于关闭自动弹出的登录提示。
// @description:zh-TW 自動關閉知乎自動彈出的登錄與註冊提示,僅僅用於關閉自動彈出的登錄提示。
// @namespace https://github.com/F9y4ng/GreasyFork-Scripts/
// @icon https://img.icons8.com/windows/48/zhihu.png
// @homepage https://f9y4ng.github.io/GreasyFork-Scripts/
// @homepageURL https://f9y4ng.github.io/GreasyFork-Scripts/
// @supportURL https://github.com/F9y4ng/GreasyFork-Scripts/issues
// @updateURL https://github.com/F9y4ng/GreasyFork-Scripts/raw/master/Autoclose%20Zhihu%20Login.meta.js
// @downloadURL https://github.com/F9y4ng/GreasyFork-Scripts/raw/master/Autoclose%20Zhihu%20Login.user.js
// @match *://*.zhihu.com/*
// @grant none
// @noframes true
// @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-2024, F9y4ng
// @run-at document-start
// ==/UserScript==
/* jshint esversion: 11 */
void (function (w) {
"use strict";
let nologin = true;
if (location.hostname.startsWith("link.")) {
const target = decodeURIComponent(new URLSearchParams(location.search).get("target"));
document.documentElement.textContent = "";
location.replace(target);
} else {
const observer = new MutationObserver(hiddenLogin);
const config = { childList: true, subtree: true };
observer.observe(document, config);
w.addEventListener("load", cloze);
document.addEventListener("readystatechange", cloze);
}
function cloze(e) {
document.body?.querySelector(`button[aria-label="关闭"][class~='Modal-closeButton']`)?.click();
if (e.type === "load") nologin = false;
}
function hiddenLoginNode(node) {
if (!nologin) return;
const loginNode = node.querySelector(`button[aria-label="关闭"][class~='Modal-closeButton']`);
if (!loginNode) return;
loginNode.click();
nologin = false;
}
function hiddenFloatNode(node) {
const registFloatNode = node.querySelector(`body>div:not([class],[style],[id]):not(:has(.Modal-content)):not(:has(img[class~='Avatar'])) div[class^='css-']:has(svg[class*='css-'])`);
if (!registFloatNode) return;
registFloatNode.style.display = "none";
}
function hiddenLogin(mutationsList) {
for (let i = 0; i < mutationsList.length; i++) {
const mutation = mutationsList[i];
const type = mutation.type;
if (type !== "childList") continue;
const addedNodes = mutation.addedNodes;
for (let j = 0; j < addedNodes.length; j++) {
const node = addedNodes[j];
if (node.nodeType !== Node.ELEMENT_NODE || node.nodeName !== "DIV" || node.attributes.length) continue;
hiddenLoginNode(node);
hiddenFloatNode(node);
}
}
}
})(typeof window !== "undefined" ? window : this);