-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (32 loc) · 1.05 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
chrome.action.onClicked.addListener(async function () {
await chrome.tabs.create(
{ url: "https://www.twitch.tv/directory/following/channels" },
async function (tab) {
chrome.tabs.onUpdated.addListener(async function b(tabId, changeInfo) {
if (tabId === tab.id && changeInfo.status === "complete") {
await chrome.scripting.insertCSS({
files: ["style.css"],
target: { tabId: tab.id },
});
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["html.js"],
});
await chrome.scripting.executeScript({
target: { tabId: tab.id },
function: injectScript,
});
await chrome.tabs.onUpdated.removeListener(b);
}
});
}
);
});
async function injectScript() {
const script = document.createElement("script");
script.src = chrome.runtime.getURL("script.js");
script.onload = function () {
this.remove();
};
(document.head || document.documentElement).appendChild(script);
}