-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
62 lines (51 loc) · 1.75 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
54
55
56
57
58
59
60
61
62
// Variables
var isFocused = true;
var selfPaused = false;
var ytVideo = document.querySelector(".video-stream.html5-main-video");
// Doesn't start script if there was an issue
if (ytVideo !== undefined) {
initScript();
}
// Focus event handlers
function onBlur() {
isFocused = false;
};
function onFocus() {
isFocused = true;
};
// Initializes the pause blocker
function initScript() {
// Set the event handlers
if ( /*@cc_on!@*/ false) { // check for Internet Explorer
document.onfocusin = onFocus;
document.onfocusout = onBlur;
} else {
window.onfocus = onFocus;
window.onblur = onBlur;
}
// Check if user paused manually
document.querySelector('.ytp-play-button.ytp-button').addEventListener("click", function() {
selfPaused = !selfPaused;
});
document.querySelector('.video-stream.html5-main-video').addEventListener("click", function() {
selfPaused = !selfPaused;
});
// Check for Youtube's Pause every half a second
setInterval(function() {
// If Youtube is focussed and paused by the popup
if (isFocused) {
let continueDiv = document.querySelector('div#main.yt-confirm-dialog-renderer');
if (continueDiv != undefined) {
let continueBtn = continueDiv.querySelector("tp-yt-paper-button");
let parentDiv = document.querySelector(".style-scope.ytd-popup-container");
if (continueBtn != undefined && parentDiv.styles.display != 'none') {
continueBtn.click();
}
}
}
// If Youtube is not focussed and paused by the popup
if (!isFocused && ytVideo.paused && !selfPaused) {
ytVideo.play();
}
}, 500);
}