-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmin-video-controls-userscript.js
59 lines (51 loc) · 1.73 KB
/
min-video-controls-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
52
53
54
55
56
57
58
59
// ==UserScript==
// @name Min Native Video Controls
// @match https://www.instagram.com
// @match https://www.youtube.com
// @run-at document-start
// ==/UserScript==
function inject() {
if (window.location.toString().includes('/reel')) {
Array.from(document.querySelectorAll('video')).forEach(v => {
v.controls = true;
v.nextSibling.childNodes[0].style['pointer-events'] = 'none'
v.nextSibling.childNodes[0].childNodes[1].style['pointer-events'] = 'auto'
})
}
if (window.location.toString().includes('/shorts')) {
if (!document.getElementById('video-controls-userscript-style')) {
const style = `
reel-player-header-renderer * {
pointer-events: none !important;
}
reel-player-header-renderer {
transition: 0.2s opacity !important;
}
ytd-reel-video-renderer:hover reel-player-header-renderer {
opacity: 0 !important;
}
`
const styleEl = document.createElement('style')
styleEl.innerHTML = style;
styleEl.id = 'video-controls-userscript-style'
document.head.appendChild(styleEl)
}
Array.from(document.querySelectorAll('video')).forEach(v => {
v.controls = true;
const observer = new MutationObserver((list, observer) => {
for (const mutation of list) {
if (mutation.attributeName === 'controls' && v.controls === false) {
v.controls = true
}
}
})
observer.observe(v, { attributes: true })
})
}
}
document.body.addEventListener('click', (e) => {
inject()
})
setTimeout(inject, 2000)
setTimeout(inject, 4000)
setTimeout(inject, 6000)