-
Notifications
You must be signed in to change notification settings - Fork 4
/
content.js
49 lines (41 loc) · 1.61 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
console.log('👨💻 Author: Saurav Hathi \n🌟 GitHub: https://github.com/sauravhathi \n🚀Linkedin: https://www.linkedin.com/in/sauravhathi');
/**
* Watches for the presence of a YouTube ad blocker popup and removes it.
* Also adds a "Donate" button to the video owner's profile.
*/
function watchForElement() {
const backdropSelector = "tp-yt-iron-overlay-backdrop.opened";
const dialogSelector = "tp-yt-paper-dialog";
const playButtonSelector = "[data-title-no-tooltip='Play']";
const donateBtn = document.createElement("button");
donateBtn.innerHTML = "Donate";
donateBtn.classList.add("donate-btn");
donateBtn.addEventListener("click", () => {
window.open("https://github.com/sauravhathi/youtube-ad-blocker-popup-removal#support-the-developer");
});
const observer = new MutationObserver(function (mutations) {
const backdrop = document.querySelector(backdropSelector);
const dialog = document.querySelector(dialogSelector);
const playButton = document.querySelector(playButtonSelector);
const p = document.querySelector("div#owner");
// If the backdrop and dialog exist, remove them.
if (backdrop) {
backdrop.remove();
}
// If the dialog exists, remove it and click the play button.
if (dialog) {
dialog.remove();
if (playButton) {
playButton.click();
}
if (p) {
// Add the donate button to the video owner's profile.
p.appendChild(donateBtn);
}
console.log("Dialog removed");
observer.disconnect();
}
});
observer.observe(document, { childList: true, subtree: true });
}
watchForElement();