-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgworker.js
28 lines (27 loc) · 1.21 KB
/
bgworker.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
(async () => {
const env = this.chrome || this.browser;
var IsFirefox = false;
if (env.runtime.getBrowserInfo) {
let BrowserInfo = await env.runtime.getBrowserInfo();
IsFirefox = BrowserInfo.name == "Firefox" || BrowserInfo.vendor == "Mozilla"; // yeah dawg, if you're using smth that doesn't follow this rule, GFY LMFAOOOOOOO FORK USER (user issue frfr)
}
env.runtime.onMessage.addListener((Message, Sender, Respond) => {
switch (Message.Operation) {
case "SeriStyle_LoadScript":
env.scripting.executeScript({
target: IsFirefox
? { tabId: Sender.tab.id } // jshint ignore: line
: { tabId: Sender.tab.id, documentIds: Sender.documentId ? [Sender.documentId] : undefined },
files: [Message.Args[0]]
});
return;
case "SeriStyle_OpenURL":
env.tabs.create({ url: env.runtime.getURL(Message.Args[0]) });
return;
}
});
env.webNavigation.onHistoryStateUpdated.addListener(function (Data) {
if (Data == null || !new URL(Data.url).hostname.includes("youtube")) return;
env.tabs.sendMessage(Data.tabId, { Operation: "SeriStyle_HistoryState", Args: [Data.url] }).catch(() => console.log("Receiving end error.", JSON.stringify(Data, null, "\t")));
});
})();