-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.html
95 lines (70 loc) · 2.5 KB
/
dashboard.html
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
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>Dashboard</title>
</head>
<body>
<h1>Dashboard</h1>
<button onclick="downloadMainSave()">Download LocalStorage</button>
<button onclick="uploadMainSave()">Upload LocalStorage</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
<script>
function getMainSave() {
var mainSave = {};
localStorageSave = Object.entries(localStorage);
localStorageSave = btoa(JSON.stringify(localStorageSave));
mainSave.localStorage = localStorageSave;
cookiesSave = document.cookie;
cookiesSave = btoa(cookiesSave);
mainSave.cookies = cookiesSave;
mainSave = btoa(JSON.stringify(mainSave));
mainSave = CryptoJS.AES.encrypt(mainSave, 'save').toString();
return mainSave;
}
function downloadMainSave() {
var data = new Blob([getMainSave()]);
var dataURL = URL.createObjectURL(data);
var fakeElement = document.createElement('a');
fakeElement.href = dataURL;
fakeElement.download = 'localStorage.data';
fakeElement.click();
URL.revokeObjectURL(dataURL);
}
function getMainSaveFromUpload(data) {
data = CryptoJS.AES.decrypt(data, 'save').toString(CryptoJS.enc.Utf8);
var mainSave = JSON.parse(atob(data));
var mainLocalStorageSave = JSON.parse(atob(mainSave.localStorage));
var cookiesSave = atob(mainSave.cookies);
for (let item in mainLocalStorageSave) {
localStorage.setItem(mainLocalStorageSave[item][0], mainLocalStorageSave[item][1]);
}
document.cookie = cookiesSave;
}
function uploadMainSave() {
var hiddenUpload = document.createElement('input');
hiddenUpload.type = 'file';
hiddenUpload.accept = '.data';
document.body.appendChild(hiddenUpload);
hiddenUpload.click();
hiddenUpload.addEventListener('change', function (e) {
var files = e.target.files;
var file = files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function (e) {
getMainSaveFromUpload(e.target.result);
var uploadResult = document.querySelector('.upload-result');
uploadResult.innerText = 'Uploaded localStorage!';
setTimeout(function () {
uploadResult.innerText = '';
}, 3000);
};
reader.readAsText(file);
document.body.removeChild(hiddenUpload);
});
}
</script>
</body>
</html>