-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathWindowScript.js
More file actions
39 lines (37 loc) · 1.19 KB
/
WindowScript.js
File metadata and controls
39 lines (37 loc) · 1.19 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
// Security: Code here is exposed to the website.
// Automaticly add media elements to DOM.
(function () {
'use strict';
// This is okay because the HTMLMediaElement prototype gets hooked.
// Note to self: DO NOT CHANGE NAME
if (window.autoPauseExtensionInjected) return;
window.autoPauseExtensionInjected = true;
const play = window.HTMLMediaElement.prototype.play;
let div = null;
window.HTMLMediaElement.prototype.play = function () {
try {
if (this instanceof HTMLMediaElement && !this.isConnected) {
if (!document.contains(div)) {
div = document.createElement('div');
div.hidden = true;
document.head.appendChild(div);
// If media gets paused remove it from the div
div.addEventListener(
'pause',
(event) => {
const src = event.srcElement;
if (src instanceof HTMLMediaElement) {
div.removeChild(src);
}
},
{passive: true, capture: true}
);
}
div.appendChild(this);
}
} catch {
// Extension errors should not affect the API.
}
return play.apply(this, arguments);
};
})();