-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfocused.js
50 lines (42 loc) · 1.62 KB
/
focused.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
// ==UserScript==
// @name Focused
// @namespace https://solanaceae.xyz/
// @icon https://raw.githubusercontent.com/0xSolanaceae/focused/refs/heads/main/assets/eye-icon.png
// @description Prevent websites from knowing that you switched tabs
// @author Solanaceae
// @version 1.0
// @match *://*/*
// @run-at document-start
// ==/UserScript==
"use strict";
(function() {
const preventTabSwitchDetection = () => {
unsafeWindow.onblur = null;
unsafeWindow.blurred = false;
unsafeWindow.document.hasFocus = () => true;
unsafeWindow.window.onFocus = () => true;
Object.defineProperty(document, "hidden", { value: false });
Object.defineProperty(document, "mozHidden", { value: false });
Object.defineProperty(document, "msHidden", { value: false });
Object.defineProperty(document, "webkitHidden", { value: false });
Object.defineProperty(document, 'visibilityState', { get: () => "visible" });
unsafeWindow.document.onvisibilitychange = undefined;
const events = [
"visibilitychange",
"webkitvisibilitychange",
"blur", // may cause issues on some websites
"mozvisibilitychange",
"msvisibilitychange"
];
events.forEach(event_name => {
window.addEventListener(event_name, event => {
event.stopImmediatePropagation();
}, true);
});
};
try {
preventTabSwitchDetection();
} catch (error) {
console.error("Failed to initialize Focused script:", error);
}
})();