-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreventPageVisibility.user.js
More file actions
50 lines (43 loc) · 1.56 KB
/
Copy pathPreventPageVisibility.user.js
File metadata and controls
50 lines (43 loc) · 1.56 KB
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
// ==UserScript==
// @name PreventPageVisibility
// @namespace https://github.com/IceWreck
// @match *://*/*
// @run-at document-start
// @grant none
// @version 1.1
// @author IceWreck
// @description Block websites from knowing if you switched tabs/windows
// @downloadURL https://update.greasyfork.org/scripts/427254/PreventPageVisibility.user.js
// @updateURL https://update.greasyfork.org/scripts/427254/PreventPageVisibility.meta.js
// ==/UserScript==
// This userscript blocks the page visibility API and to some extent the old blur/focus APIs.
let events_to_block = [
"visibilitychange",
"webkitvisibilitychange",
"mozvisibilitychange",
"hasFocus",
"blur",
"focus",
"mouseleave"
]
for (event_name of events_to_block) {
document.addEventListener(event_name, function (event) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
}, true);
}
for (event_name of events_to_block) {
window.addEventListener(event_name, function (event) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
}, true);
}
document.hasFocus = function () { return true; };
document.onvisibilitychange = null;
Object.defineProperty(document, "visibilityState", { value: "visible" });
Object.defineProperty(document, "hidden", { value: false });
Object.defineProperty(document, "mozHidden", { value: false });
Object.defineProperty(document, "webkitHidden", { value: false });
Object.defineProperty(document, "webkitVisibilityState", { value: "visible" });