forked from twistezo/netflix-subtitles-styler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (40 loc) · 1.54 KB
/
script.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
chrome.runtime.onMessage.addListener((message, _sender, _sendResponse) => {
changeSubtitlesStyle(message.vPos, message.fSize, message.fColor);
});
changeSubtitlesStyle = (vPos, fSize, fColor) => {
console.log("%cnetflix-subtitles-styler : observer is working... ", "color: red;");
callback = () => {
// .player-timedText
const subtitles = document.querySelector(".player-timedtext");
if (subtitles) {
subtitles.style.bottom = vPos + "px";
// .player-timedtext > .player-timedtext-container [0]
const firstChildContainer = subtitles.firstChild;
if (firstChildContainer) {
// .player-timedtext > .player-timedtext-container [0] > div
const firstChild = firstChildContainer.firstChild;
if (firstChild) {
firstChild.style.backgroundColor = "transparent";
}
// .player-timedtext > .player-timedtext-container [1]
const secondChildContainer = firstChildContainer.nextSibling;
if (secondChildContainer) {
for (const span of secondChildContainer.childNodes) {
// .player-timedtext > .player-timedtext-container [1] > span
span.style.fontSize = fSize + "px";
span.style.fontWeight = "normal";
span.style.color = fColor;
}
secondChildContainer.style.left = "0";
secondChildContainer.style.right = "0";
}
}
}
};
const observer = new MutationObserver(callback);
observer.observe(document.body, {
subtree: true,
attributes: false,
childList: true
});
};