-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
27 lines (23 loc) · 803 Bytes
/
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
function loadScript(tabID) {
chrome.scripting.insertCSS({
target: { tabId: tabID },
files: ['style.css'],
});
chrome.scripting.executeScript({
target: { tabId: tabID },
files: ['main.js', 'pako.js', 'patch_worker.js'],
});
}
function togglePopup(tabID) {
chrome.tabs.sendMessage(tabID, { action: 'togglePopup' });
}
chrome.action.onClicked.addListener((tab) => {
if (tab.url) togglePopup(tab.id);
});
chrome.runtime.onMessage.addListener(async (req, sender) => {
if (req.action === 'togglePopup') togglePopup(sender.tab.id);
if (req.action === 'loadScript') loadScript(sender.tab.id);
});
chrome.runtime.onInstalled.addListener((object) => {
if (object.reason === 'install') chrome.tabs.create({ url: 'https://drednot.io/' });
});