-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
83 lines (70 loc) · 2.2 KB
/
options.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
75
76
77
78
79
80
81
82
83
// chrome runtime listener
chrome.runtime.onMessage.addListener(req => {
switch(req.todo) {
// reload page once all tabs are saved
case 'reloadOptionsPage':
location.reload();
return;
default:
return;
}
});
// init
$(document).ready(() => {
(async () => {
let storageData = await storageGet();
$('#data-display-area').html(`<pre>${JSON.stringify(storageData,undefined,4)}</pre>`);
$('.tooltipped').tooltip();
})();
});
// resizing textarea
$('#textarea').on('input',function() {
M.textareaAutoResize($(this));
});
// onSubmit data
$('#submit-data-form').on('submit',function(e) {
(async () => {
e.preventDefault();
const storageData = JSON.parse($('#textarea').val());
await storageClear();
await storageSet(storageData);
M.toast({html: 'Successfully overwritten data!'});
chrome.runtime.sendMessage({ todo: 'reloadMainPage' });
})();
});
// copy data
$('#copy-data').on('click',function() {
const data = $('#data-display-area').text();
let $temp = $('<textarea />');
$("body").append($temp);
$temp.val(data).select();
document.execCommand("copy");
$temp.remove();
M.toast({html: 'Data Copied!'});
});
// save groups to an account's sync storage
$('.save-to-account').click(() => {
(async () => {
let localStorageData = await storageGet();
await syncStorageClear();
await syncStorageSet(localStorageData);
M.toast({ html: 'Successfully saved groups to your account' });
})();
});
// Overwrite data w/ account's data
$('.overwrite-with-account-data').click(() => {
(async () => {
let syncStorageData = await syncStorageGet();
let storageData = await storageGet();
if (Object.keys(storageData).length) {
await removeGroupBookmarks(storageData);
}
await storageClear();
if (Object.keys(syncStorageData).length) {
syncStorageData = await condGroupBookmarksNUrls(syncStorageData);
}
await storageSet(syncStorageData);
chrome.runtime.sendMessage({ todo: 'reloadMainPage' });
location.reload();
})();
});