-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
35 lines (29 loc) · 974 Bytes
/
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
var localData;
//register the open_edit_view (Command+Shift+E) command to open editor.html in a new tab
chrome.commands.onCommand.addListener(function (command) {
if(command === 'open_edit_view')
chrome.tabs.create({url:chrome.extension.getURL('editor.html')});
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
// log this
if(changeInfo.url)
save(changeInfo.url);
});
// refactor this to handle getting existing data and updating in place
// need mechanism to make sure we don't lose data
function save(content) {
// get existing data
chrome.storage.sync.get(function(data){
//console.log(data);
if('items' in data)
localData = data;
else {
data['items'] = [];
localData = data;
}
var timestamp = new Date();
var entry = {content:content, timestamp: String(timestamp), type:'url'};
localData['items'].push(entry);
chrome.storage.sync.set({'items':localData['items']});
});
}