-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
29 lines (25 loc) · 1.01 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
// background.js
// Listen for messages and interact with YouTube depending on user's actions
let isWorkCompleted = false;
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action === 'workCompleted') {
// Mark work as completed (you can add additional logic here)
isWorkCompleted = true;
// Close the popup
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'closePopup' });
});
} else if (request.action === 'closeTab') {
// Close the current tab
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.remove(tabs[0].id);
});
} else if (request.action === 'showPopup') {
// Send a message to the content script to show the popup
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'showPopup' });
});
}
}
);