-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathicebox.js
55 lines (51 loc) · 1.74 KB
/
icebox.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
function render(template_name, context) {
var iframe = document.getElementById('theFrame');
var message = {
command: 'render',
template_name: template_name,
context: context
};
iframe.contentWindow.postMessage(message, '*');
}
window.addEventListener('message', function(event) {
var command = event.data.command;
switch(command) {
case 'ready':
display_page();
break;
case 'load_html':
if (event.data.html) {
document.getElementById('body').innerHTML = event.data.html
} else {
document.getElementById('body').innerHTML = 'nodata'
}
var items = document.getElementsByClassName('deleteable');
Array.prototype.forEach.call(items, function(item) {
item.addEventListener('click', function(evt) {
evt.preventDefault();
remove_from_icebox(evt.target.href);
})
});
chrome.storage.sync.getBytesInUse(null, function(size) {
document.getElementById('data_size').innerHTML = size + " bytes in use";
});
break;
}
});
function display_page() {
chrome.storage.sync.get('pages', function(data) {
render('icebox_tabs', data);
});
}
chrome.tabs.onActivated.addListener(display_page);
function remove_from_icebox(url) {
// open new tab
chrome.tabs.create({url: url, active: true})
// remove from storage
chrome.storage.sync.get('pages', function(data) {
var newPages = data.pages.filter(function (element, index, array) {
return element.url != url
});
chrome.storage.sync.set({pages: newPages});
});
}