-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.js
53 lines (40 loc) · 1.44 KB
/
popup.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
45
46
47
48
49
50
51
52
53
const function1 = document.getElementById('button1');
const function2 = document.getElementById('button2');
async function getCurrentTab() {
const queryOptions = { active: true, currentWindow: true };
const [tab] = await chrome.tabs.query(queryOptions);
return tab;
}
// Listen for messages from the background.js
let currentlyEnabled = false;
function1.addEventListener('click', async () => {
const tab = await getCurrentTab();
if (currentlyEnabled) {
await chrome.scripting.removeCSS({
target: {
tabId: tab.id
},
files: ["inject.css"],
});
chrome.action.setBadgeText({ text: "",tabId: tab.id });
currentlyEnabled = false;
} else {
// If not currently enabled, insert the CSS file
await chrome.scripting.insertCSS({
target: {
tabId: tab.id
},
files: ["inject.css"],
});
// Set the label on the action button
chrome.action.setBadgeText({ text: "ON", tabId: tab.id });
// Set currently enabled to true
currentlyEnabled = true;
}
});
function2.addEventListener('click', async function () {
// Get the current tab
const currentTab = await getCurrentTab();
// Send a message to the content script in the current tab to execute the script
chrome.tabs.sendMessage(currentTab.id, 'executeScript');
});