This repository was archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoutube-remove-annotations.user.js
More file actions
77 lines (64 loc) · 2.03 KB
/
youtube-remove-annotations.user.js
File metadata and controls
77 lines (64 loc) · 2.03 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
69
70
71
72
73
74
75
76
77
// ==UserScript==
// @name YouTube Remove Annotations
// @namespace https://github.com/Poorchop/userscripts
// @description Automatically toggles off YouTube annotations
// @include http*://www.youtube.com/*
// @version 0.1.1
// @grant none
// ==/UserScript==
// For new Material Design layout (2017)
let settingsBtn;
let settingsPanel;
let menuItems;
let annotationNode;
let observer;
function toggleAnnotations(node) {
node.click();
}
function annotationCheck() {
// open the settings panel
settingsBtn = document.getElementsByClassName("ytp-button ytp-settings-button")[0];
settingsBtn.click();
// locate the settings panel and menu items
settingsPanel = document.getElementsByClassName("ytp-panel-menu")[0];
menuItems = document.getElementsByClassName("ytp-menuitem-label");
// check to see if the annotation toggler exists
for (let item of menuItems) {
if (item.innerHTML === "Annotations") {
annotationNode = item.parentNode;
if (annotationNode.getAttribute("aria-checked") === "true") {
toggleAnnotations(annotationNode);
break;
}
}
}
// annotation toggler might appear later
observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
annotationNode = mutation.addedNodes[0];
if (!annotationNode) {
return;
}
nodeLabel = annotationNode.childNodes[0];
if (nodeLabel.innerHTML === "Annotations" && annotationNode.getAttribute("aria-checked") === "true") {
toggleAnnotations(annotationNode);
observer.disconnect();
}
});
});
observer.observe(settingsPanel, { childList: true });
// close the settings panel
settingsBtn.click();
}
function init() {
window.addEventListener("yt-navigate-finish", function () {
if (window.location.pathname === "/watch") {
annotationCheck();
} else {
if (observer) {
observer.disconnect();
}
}
});
}
init();