-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.js
42 lines (42 loc) · 870 Bytes
/
backup.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
function del(){
if(confirm("Удалить все заметки?")){
localStorage.clear();
}
}
function cle(){
text.value = "";
}
function imp(){
set(text.value);
}
function exp(){
for(var i=0; i<localStorage.length; i++) {
const k = localStorage.key(i);
const v = localStorage.getItem(k);
text.value += k+v;
}
}
function sel(){
text.focus();
document.execCommand('selectAll', false, null);
}
function copy(){
sel();
document.execCommand('copy');
text.blur();
}
function openFile(event){
const input = event.target;
const reader = new FileReader();
reader.onload = function(){
set(reader.result);
};
reader.readAsText(input.files[0]);
}
function set(t){
const kv = t.split('}');
for (var i=0; i<kv.length-1; i++){
const kv1 = kv[i].split('{');
localStorage.setItem(kv1[0], '{'+kv1[1]+'}');
}
}