forked from FriedChickenButt/youtube-webos
-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathuserScript.js
51 lines (43 loc) · 1.54 KB
/
userScript.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
import 'whatwg-fetch';
import './domrect-polyfill';
import { handleLaunch, waitForChildAdd } from './utils';
document.addEventListener(
'webOSRelaunch',
(evt) => {
console.info('RELAUNCH:', evt, window.launchParams);
handleLaunch(evt.detail);
},
true
);
import './adblock.js';
import './sponsorblock.js';
import './ui.js';
// This IIFE is to keep the video element fill the entire window so that screensaver doesn't kick in.
(async () => {
/** @type {HTMLVideoElement} */
const video = await waitForChildAdd(
document.body,
(node) => node instanceof HTMLVideoElement
);
const playerCtrlObs = new MutationObserver(() => {
const style = video.style;
const targetWidth = `${window.innerWidth}px`;
const targetHeight = `${window.innerHeight}px`;
const targetLeft = '0px';
// YT uses a negative top to hide player when not in use. Don't know why but let's not affect it.
const targetTop =
style.top === `-${window.innerHeight}px` ? style.top : '0px';
/**
* Check to see if identical before assignment as some webOS versions will trigger a mutation
* mutation event even if the assignment effectively does nothing, leading to an infinite loop.
*/
style.width !== targetWidth && (style.width = targetWidth);
style.height !== targetHeight && (style.height = targetHeight);
style.left !== targetLeft && (style.left = targetLeft);
style.top !== targetTop && (style.top = targetTop);
});
playerCtrlObs.observe(video, {
attributes: true,
attributeFilter: ['style']
});
})();