Skip to content

Commit 09cd8c0

Browse files
authored
Merge pull request #1022 from Zzza38/main
Save Data Manager
2 parents 3418134 + 016eae3 commit 09cd8c0

File tree

4 files changed

+317
-269
lines changed

4 files changed

+317
-269
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
"env-*": true,
2323
"Failed.html": true,
2424
"static/assets/js/fa.js": true
25+
},
26+
"[html]": {
27+
"editor.defaultFormatter": "vscode.html-language-features"
2528
}
2629
}

static/assets/css/settings.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,7 @@ select {
228228
margin-top: 13px;
229229
margin-left: 20px;
230230
}
231+
232+
#warning {
233+
color: red;
234+
}

static/assets/js/settings.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,71 @@ function getRandomURL() {
371371
function randRange(min, max) {
372372
return Math.floor(Math.random() * (max - min) + min);
373373
}
374+
375+
function exportSaveData() {
376+
function getCookies() {
377+
let cookies = document.cookie.split('; ');
378+
let cookieObj = {};
379+
cookies.forEach(cookie => {
380+
let [name, value] = cookie.split('=');
381+
cookieObj[name] = value;
382+
});
383+
return cookieObj;
384+
}
385+
function getLocalStorage() {
386+
let localStorageObj = {};
387+
for (let key in localStorage) {
388+
if (localStorage.hasOwnProperty(key)) {
389+
localStorageObj[key] = localStorage.getItem(key);
390+
}
391+
}
392+
return localStorageObj;
393+
}
394+
const data = {
395+
cookies: getCookies(),
396+
localStorage: getLocalStorage()
397+
};
398+
const dataStr = JSON.stringify(data, null, 2);
399+
const blob = new Blob([dataStr], { type: 'application/json' });
400+
const url = URL.createObjectURL(blob);
401+
const a = document.createElement('a');
402+
a.href = url;
403+
a.download = 'save_data.json';
404+
document.body.appendChild(a);
405+
a.click();
406+
document.body.removeChild(a);
407+
URL.revokeObjectURL(url);
408+
}
409+
410+
function importSaveData() {
411+
const input = document.createElement('input');
412+
input.type = 'file';
413+
input.accept = 'application/json';
414+
input.onchange = function(event) {
415+
const file = event.target.files[0];
416+
if (!file) return;
417+
const reader = new FileReader();
418+
reader.onload = function(e) {
419+
try {
420+
const data = JSON.parse(e.target.result);
421+
if (data.cookies) {
422+
Object.entries(data.cookies).forEach(([key, value]) => {
423+
document.cookie = `${key}=${value}; path=/`;
424+
});
425+
}
426+
if (data.localStorage) {
427+
Object.entries(data.localStorage).forEach(([key, value]) => {
428+
localStorage.setItem(key, value);
429+
});
430+
}
431+
alert('Your save data has been imported. Please test it out.')
432+
alert('If you find any issues then report it in GitHub or the Interstellar Discord.')
433+
} catch (error) {
434+
console.error('Error parsing JSON file:', error);
435+
}
436+
};
437+
reader.readAsText(file);
438+
};
439+
input.click();
440+
}
441+

0 commit comments

Comments
 (0)