-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
53 lines (49 loc) · 2.11 KB
/
content.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
$(function () {
$(window).bind('load', function () {
let videos;
let loop;
let labelAd;
let vol;
var mute = 0;
videos = document.getElementsByTagName('video');
// const increaseMiniplayer = () => {
// document.querySelector('.tw-title').innerHTML = 'increasing..';
// $('main').attr('style', 'display: none !important');
// $('main').nextAll('div:first').css('width', '100%');
// $('.channel-root__right-column').css('width', '100%');
// $('.channel-root__right-column').css('transform', 'translateX(0) translateZ(0px)');
// }
// const decreaseMiniplayer = () => {
// document.querySelector('.tw-title').innerHTML = 'decreasing..';
// $('main').removeAttr('style');
// $('main').nextAll('div:first').css('width', 'fit-content');
// $('.channel-root__right-column').css('width', '34rem');
// $('.channel-root__right-column').css('transform', 'translateX(-34rem) translateZ(0px)');
// }
loop = setInterval(() => {
chrome.storage.local.get(['muteAll'], function (result) {
labelAd = $("[data-a-target=video-ad-label]");
if (labelAd.length > 0) { // Ads running
if (mute == 0) {
mute = 1;
vol = videos[0].volume;
if (result.muteAll) { // if user checked "muted ads" button
if (videos[0].volume > 0) { // if main video is not muted
videos[0].muted = true; // MUTED
}
}
videos[1].controls = true; // enable the controls in miniplayer
videos[1].muted = false; // set the volume in small window
videos[1].volume = vol; // set the same volume than main video in small window
}
} else if(mute == 1) { // Ads ended
mute = 0;
if (result.muteAll) {
videos[0].muted = false; // UNMUTED
}
videos[1].muted = true;
}
});
}, 1000)
});
});