-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfocus-patch.js
More file actions
42 lines (39 loc) · 1.25 KB
/
Copy pathfocus-patch.js
File metadata and controls
42 lines (39 loc) · 1.25 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
// Keeps Storyline/SCORM players running when the tab is in the background.
(() => {
const hide = () => false;
try {
for (const k of ['hidden', 'webkitHidden']) {
Object.defineProperty(document, k, { configurable: true, get: hide });
}
for (const k of ['visibilityState', 'webkitVisibilityState']) {
Object.defineProperty(document, k, { configurable: true, get: () => 'visible' });
}
document.hasFocus = () => true;
} catch (_) {}
const noop = () => {};
for (const [obj, prop] of [
[document, 'onvisibilitychange'],
[window, 'onblur'],
[window, 'onpagehide'],
]) {
try {
Object.defineProperty(obj, prop, { configurable: true, get: () => null, set: noop });
} catch (_) {}
}
const block = new Set([
'visibilitychange',
'webkitvisibilitychange',
'blur',
'focusout',
'pagehide',
'freeze',
]);
const add = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function (type, listener, options) {
if (typeof type === 'string' && block.has(type.toLowerCase())) return;
return add.call(this, type, listener, options);
};
for (const type of block) {
window.addEventListener(type, (e) => e.stopImmediatePropagation(), true);
}
})();