forked from twistezo/netflix-subtitles-styler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
39 lines (36 loc) · 1.1 KB
/
background.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
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({ vPos: 300, fSize: 24, fColor: "#FFFFFF" });
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostSuffix: "netflix.com" }
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}
]);
});
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === "complete" && tab.active) {
chrome.storage.local.get(["vPos", "fSize", "fColor"], data => {
chrome.tabs.executeScript(
tabId,
{
file: "script.js"
},
() => {
const error = chrome.runtime.lastError;
if (error) "Error. Tab ID: " + tab.id + ": " + JSON.stringify(error);
chrome.tabs.sendMessage(tabId, {
vPos: data.vPos,
fSize: data.fSize,
fColor: data.fColor
});
}
);
});
}
});