-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.js
37 lines (34 loc) · 1.25 KB
/
dashboard.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
chrome.storage.local.get(['test'], function(result) {
var stored = result.test;
if(typeof JSON.parse(result.test) === typeof undefined) stored = [];
document.getElementById('rCount').innerHTML = 'Entries saved: '+JSON.parse(stored).length;
document.getElementsByClassName('storage')[0].innerHTML = stored;
});
var clearButton = document.getElementById('clearStore');
clearButton.addEventListener('click', function(){
chrome.storage.local.clear(function() {
var error = chrome.runtime.lastError;
if (error) {
console.error(error);
}
});
});
var downloadButton = document.getElementById('downloadStore');
downloadButton.addEventListener('click', function() {
chrome.storage.local.get(['test'], function(result) {
var stored = result.test;
if(typeof JSON.parse(result.test) === typeof undefined) stored = '[]';
var blob = new Blob([stored], {type: 'text/json'});
if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, 'filename.json');
}
else{
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = 'filename.json';
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
});
});