-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
46 lines (40 loc) · 1.14 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
38
39
40
41
42
43
44
45
46
var input, localData;
// wait for extension content to load
document.addEventListener('DOMContentLoaded', function(){
input = document.querySelector('#input');
// linux doesn't autofocus the input field
input.focus();
// setup enter key listener
input.addEventListener('keypress', function(e){
if (e.keyCode === 13){
console.log(input.value);
save(input.value);
input.value = '';
window.close();
}
});
// get existing data
chrome.storage.sync.get(function(data){
//console.log(data);
if('items' in data)
localData = data;
else {
data['items'] = [];
localData = data;
}
});
//register the open_edit_view command to trigger creation of a new tab
chrome.commands.onCommand.addListener(function (command) {
console.log(command);
});
});
chrome.runtime.onMessage.addListener(function(message, sender, sendresponse){
save(message);
sendresponse();
});
function save(content) {
var timestamp = new Date();
var entry = {content:content, timestamp: String(timestamp), type:'note'};
localData['items'].push(entry);
chrome.storage.sync.set({'items':localData['items']});
}