-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
68 lines (56 loc) · 1.26 KB
/
Copy pathcontent.js
File metadata and controls
68 lines (56 loc) · 1.26 KB
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
(function () {
"use strict";
function clickContinueButton() {
const container = document.querySelector(
"#player-error-message-container.yt-player-error-message-renderer"
);
if (!container) {
return false;
}
const button = container.querySelector("#button button");
if (button && !button.disabled) {
button.click();
return true;
}
return false;
}
let observer = null;
let checkInterval = null;
const timer = 500;
function stopMonitoring() {
if (observer) {
observer.disconnect();
observer = null;
}
if (checkInterval) {
clearInterval(checkInterval);
checkInterval = null;
}
}
function startMonitoring() {
if (observer || checkInterval) {
return;
}
observer = new MutationObserver((mutations, obs) => {
if (clickContinueButton()) {
stopMonitoring();
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
checkInterval = setInterval(() => {
if (clickContinueButton()) {
stopMonitoring();
}
}, timer);
}
if (clickContinueButton()) {
return;
}
startMonitoring();
window.addEventListener("beforeunload", () => {
stopMonitoring();
});
})();