-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (64 loc) · 1.77 KB
/
main.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
// ==UserScript==
// @name onFocus
// @include *
// @description kill blur eventListener, force onfocus
// @author the0cp
// @version 1.0.0
// @license GPLv3
// ==/UserScript==
unsafeWindow.onblur = null;
unsafeWindow.blurred = false;
unsafeWindow.document.hasFocus = () => true;
unsafeWindow.window.onFocus = () => true;
[
"hidden",
"mozHidden",
"msHidden",
"webkitHidden"
].forEach(prop_name => {
Object.defineProperty(document, prop_name, {value: false});
})
Object.defineProperty(document, "visibilityState", {get: () => "visible"});
Object.defineProperty(document, "webkitVisibilityState", {get: () => "visible"});
unsafeWindow.document.onvisibilitychange = undefined;
const blurWhitelist = [
HTMLInputElement,
HTMLAnchorElement,
HTMLSpanElement,
HTMLParagraphElement,
]
const hoverBlacklist = [
HTMLIFrameElement,
HTMLHtmlElement,
HTMLBodyElement,
HTMLHeadElement,
];
var event_handler = (event) => {
if (event.type === 'blur' &&
((blurWhitelist.some(type => event.target instanceof type) ||
event.target.classList?.contains('ql-editor')))) {
return;
}
if (['mouseleave', 'mouseout'].includes(event.type) &&
!hoverBlacklist.some(type => event.target instanceof type)) {
return;
}
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
}
// kill event listeners
[
"visibilitychange",
"webkitvisibilitychange",
"blur",
"hasFocus",
"mouseleave",
"mouseout",
"mozvisibilitychange",
"fullscreenchange",
"msvisibilitychange"
].forEach(event_name => {
window.addEventListener(event_name, event_handler, true);
document.addEventListener(event_name, event_handler, true);
})