-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
37 lines (32 loc) · 1.2 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
// popup.js
console.log("Popup script loaded");
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM content loaded');
// Function to safely add event listener
function addClickListener(id, callback) {
const element = document.getElementById(id);
if (element) {
element.addEventListener('click', callback);
console.log(`Event listener added to ${id}`);
} else {
console.error(`Element with id "${id}" not found`);
}
}
// Gather Tabs functionality
addClickListener('gatherButton', function() {
chrome.tabs.query({currentWindow: true}, function(tabs) {
var tabsToSave = tabs.map(function(tab) {
return {url: tab.url, title: tab.title};
});
chrome.storage.local.set({savedTabs: tabsToSave}, function() {
console.log('Tabs saved');
chrome.tabs.create({url: 'tablist.html'});
});
});
});
// Open Saved Tabs functionality
addClickListener('openTablistButton', function() {
chrome.tabs.create({url: 'tablist.html'});
});
console.log('Popup script finished executing');
});