-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
49 lines (43 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
// Listen for the DOM to load
document.addEventListener("DOMContentLoaded", function () {
// Get the start button
const startButton = document.getElementById("startButton");
// Add a click event listener to the start button
startButton.addEventListener("click", function () {
// Get the active tab
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const tab = tabs[0];
// Send a message to the content script to start the process
chrome.tabs.sendMessage(
tab.id,
{ message: "start" },
function (response) {
// Check for errors
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}
// Log success message
console.log("Start button clicked 👍");
}
);
});
});
});
// Listen for messages from the content script
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
// Handle messages
switch (request.message) {
case "click_connect":
// Perform necessary actions here, such as logging or updating the UI
console.log("Connect button clicked from content script");
break;
default:
console.warn("Unknown message received:", request);
break;
}
// Send response
sendResponse({ success: true });
});
// Handle errors
chrome.runtime.lastError && console.error(chrome.runtime.lastError.message);