-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
36 lines (33 loc) · 1.1 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
var stash = [];
document.addEventListener("DOMContentLoaded", function() {
// Called when the user clicks on the browser action.
const stashButton = document.getElementById('stash');
const applyButton = document.getElementById('apply');
stashButton.addEventListener('click', function() {
stash = [];
let query = chrome.tabs.query({}, tabs => {
tabs.map(tab => {
stash.push(tab.url);
chrome.tabs.remove(tab.id);
});
chrome.storage.local.clear();
chrome.storage.local.set({stash: stash}, function() {
chrome.windows.create({}, function() {
chrome.extension.getBackgroundPage()
.console.log('Settings saved', stash.length);
});
});
});
});
applyButton.addEventListener('click', function() {
chrome.storage.local.get(null, function(items) {
chrome.extension.getBackgroundPage()
.console.log('Settings retrieved', items['stash'].length);
if(items['stash'].length > 0) {
items['stash'].map(url => {
chrome.tabs.create({url: url});
});
}
});
});
}, false);