-
Notifications
You must be signed in to change notification settings - Fork 2
/
nightbot.js
26 lines (22 loc) · 1 KB
/
nightbot.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
// Nightbot creates the song title element at runtime.
// Observe mutations to body until the element is created.
new MutationObserver((mutationList, observer) => {
for (let mutation of mutationList) {
let element = mutation.target;
// The properties of the song title element.
if (element.nodeName === 'STRONG' && element.className === 'ng-binding' && element.textContent !== 'Song Requests') {
// No need to observe any further mutations.
observer.disconnect();
// Sends the name.
function sendName() {
chrome.runtime.sendMessage({ name: element.textContent });
}
// Send the current name.
sendName();
// Observe changes on the element, and send the names.
new MutationObserver(() => {
sendName();
}).observe(element, { characterData: true, subtree: true });
}
}
}).observe(document.body, { childList: true, subtree: true });