-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
37 lines (35 loc) · 1.33 KB
/
background.js
File metadata and controls
37 lines (35 loc) · 1.33 KB
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
// Handle scheduled URL opening
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name.startsWith('scheduled_urls_')) {
chrome.storage.local.get(['scheduledUrls'], (result) => {
const urls = result.scheduledUrls || [];
if (urls.length > 0) {
// Open each URL in a new tab
urls.forEach((url) => {
chrome.tabs.create({ url, active: false });
});
}
});
}
});
chrome.commands.onCommand.addListener(function(command) {
if (command === "save-tabs") {
chrome.tabs.query({ currentWindow: true }, (tabs) => {
const urlsToAdd = tabs.map(tab => tab.url).filter(Boolean);
const createdDate = new Date();
const formattedDate = `${createdDate.getDate()}/${createdDate.getMonth() + 1}/${createdDate.getFullYear()}`;
chrome.storage.local.get({ accordions: [] }, (result) => {
const accordions = result.accordions || [];
const quickSaveCount = accordions.filter(item =>
item.name.startsWith("Quick Save")
).length;
const uniqueName = quickSaveCount === 0 ? "Quick Save_1" : `Quick Save_${quickSaveCount + 1}`;
accordions.push({ name: uniqueName, date: formattedDate, urls: urlsToAdd });
chrome.storage.local.set({ accordions });
});
});
}
if (command === "open-popup") {
chrome.action.openPopup();
}
});