-
Notifications
You must be signed in to change notification settings - Fork 7
/
background.js
74 lines (65 loc) · 2.14 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const btnsave = document.getElementById('savebtn');
const btnset = document.getElementById('getbtn');
const btnAdd = document.getElementById('addBtn');
const btnAll = document.getElementById('workspacebtn');
const workspacediv = document.getElementById('workspaces');
// var gettingAll;
var workspaces = {};
var tabsInfo = {};
var workspacesArr = [];
//to save tabs
btnsave.addEventListener('click', () => {
var input = document.getElementById('input_name').value;
workspacesArr.push(input);
console.log(input);
window.alert(input + " has been created");
chrome.tabs.query({},function(tabs){
// console.log("tabs",tabs);
tabsInfo = tabs.map(tab=>({
// "title" : tab.title
"url":tab.url
}));
// console.log('tabsInfo', tabsInfo);
chrome.storage.sync.set({'key': tabsInfo}, () => {
console.log('saved');
});
});
});
//to get tabs array in a promise in console
btnset.addEventListener('click', () => {
chrome.storage.sync.get('key', () => {
for(var i=0;i<tabsInfo.length; i++){
// console.log(tabsInfo[i].url);
chrome.tabs.create({'url': tabsInfo[i].url}, callback1);
}
});
});
function callback1(){
console.log('displayed');
};
//chrome.tabs.executeScript(null,{file: "content.js"});
//add button to display second section
btnAdd.addEventListener('click', () => {
console.log('wokring');
document.getElementById('all_workspace').style.display = 'none';
document.getElementById('create_workspace').style.display = 'block';
});
//all button to display first section
btnAll.addEventListener('click', () => {
document.getElementById('all_workspace').style.display = 'block';
document.getElementById('create_workspace').style.display = 'none';
printBtn();
});
//to get all the workspaces (currently static)
// var arr =['w1','w2','w3','w4','w5'];
function printBtn() {
for(var i=0; i<workspacesArr.length; i++)
{
var btn = document.createElement("button");
btn.className = "button"
var t = document.createTextNode(workspacesArr[i]);
btn.appendChild(t);
workspacediv.appendChild(btn);
console.log(workspacesArr[i]);
}
}