-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo.js
executable file
·106 lines (76 loc) · 3.21 KB
/
video.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"use strict";
let observer = null;
/**
* @param {Object} mutationList
*/
function observerCallback(mutationList) {
for (const mutation of mutationList) {
if (mutation.target.tagName === 'DIV' && mutation.target.className.includes('video-ads')) {
if (mutation.target.innerHTML.includes('ytp-ad-preview-container')) {
const videos = document.getElementsByTagName('video');
for (let i = 0; i < videos.length; i++) {
if (videos[i].attributes.getNamedItem('src') !== null && videos[i].volume > 0) {
console.log('dropping volume, reducing blur and opacity');
videos[i].volume = 0;
const vidContainer = document.getElementById('movie_player');
vidContainer.style.filter = 'blur(10px)';
vidContainer.style.opacity = 0.05;
break;
}
}
}
if (mutation.target.innerHTML.includes('ytp-ad-skip-button-container')) {
const skipNow = document.getElementsByClassName('ytp-ad-skip-button-container');
if (skipNow.length > 0) {
console.log('skipping');
skipNow[0].click();
}
}
if (mutation.target.innerHTML.includes('ytp-ad-overlay-close-container')) {
const closeButtonContainer = document.getElementsByClassName('ytp-ad-overlay-close-container');
for (let i = 0; i < closeButtonContainer.length; i++) {
console.log('closing');
closeButtonContainer[i].click();
}
}
if (mutation.target.childElementCount === 0) {
console.log('restoring blur and opacity');
const vidContainer = document.getElementById('movie_player');
vidContainer.style.removeProperty('filter');
vidContainer.style.opacity = 1;
}
}
}
}
function startObserver() {
const component = document.getElementById('movie_player');
if (component === null) {
console.error("didn't find the movie player");
} else {
console.log('starting');
observer = new MutationObserver(observerCallback);
observer.observe(component, { attributes: true, childList: true, subtree: true });
const popup = document.getElementsByTagName('ytd-popup-container');
if (popup.length === 1) {
popup[0].style.display = 'none';
}
}
}
browser.runtime.onMessage.addListener((request) => {
if (request.state) {
if (observer === null) {
startObserver();
browser.runtime.sendMessage({m:'starting observer', tid:request.tabID});
}
} else if (observer !== null) {
console.log('stopping');
observer.disconnect();
observer = null;
const popup = document.getElementsByTagName('ytd-popup-container');
if (popup.length === 1) {
popup[0].style.display = null;
}
browser.runtime.sendMessage({m:'disconnecting observer', tid:request.tabID});
}
return true;
});