1
0
mirror of https://github.com/zumbiepig/MineXLauncher.git synced 2025-06-08 09:24:48 +00:00

gzip compress storage values

This commit is contained in:
zumbiepig 2024-09-10 19:42:16 -07:00
parent 0929beb00c
commit 8c28f8cba3
No known key found for this signature in database
GPG Key ID: 17C891BE28B953DE

View File

@ -84,10 +84,7 @@ function consoleLog(
messageElement.classList.add(type); messageElement.classList.add(type);
messageElement.innerText = msg; messageElement.innerText = msg;
consoleElement.append(messageElement); consoleElement.append(messageElement);
storage.session.set( storage.session.set('console', consoleElement.innerHTML);
'console',
base64Gzip.compress(consoleElement.innerHTML),
);
if (scrolledToBottom) consoleElement.scroll(0, consoleElement.scrollHeight); if (scrolledToBottom) consoleElement.scroll(0, consoleElement.scrollHeight);
} }
} }
@ -398,8 +395,7 @@ const storage = {
get: function (key: string) { get: function (key: string) {
const item = localStorage.getItem('minexlauncher'); const item = localStorage.getItem('minexlauncher');
if (item !== null) { if (item !== null) {
//const decoded = atob(item); const json = JSON.parse(base64Gzip.decompress(item));
const json = JSON.parse(item);
if (json[key] !== undefined) { if (json[key] !== undefined) {
return json[key]; return json[key];
} }
@ -415,16 +411,17 @@ const storage = {
if (item === null) { if (item === null) {
const json: Record<string, unknown> = {}; const json: Record<string, unknown> = {};
json[key] = value; json[key] = value;
const string = JSON.stringify(json); localStorage.setItem(
//const encoded = btoa(string); 'minexlauncher',
localStorage.setItem('minexlauncher', string); base64Gzip.compress(JSON.stringify(json)),
);
} else { } else {
//const decoded = atob(item); const json = JSON.parse(base64Gzip.decompress(item));
const json = JSON.parse(item);
json[key] = value; json[key] = value;
const string = JSON.stringify(json); localStorage.setItem(
//const encoded = btoa(string); 'minexlauncher',
localStorage.setItem('minexlauncher', string); base64Gzip.compress(JSON.stringify(json)),
);
} }
}, },
}, },
@ -432,7 +429,7 @@ const storage = {
get: function (key: string) { get: function (key: string) {
const item = sessionStorage.getItem('minexlauncher'); const item = sessionStorage.getItem('minexlauncher');
if (item !== null) { if (item !== null) {
const json = JSON.parse(item); const json = JSON.parse(base64Gzip.decompress(item));
if (json[key] !== undefined) { if (json[key] !== undefined) {
return json[key]; return json[key];
} }
@ -444,13 +441,22 @@ const storage = {
key: string, key: string,
value: string | number | object | boolean | null | undefined, value: string | number | object | boolean | null | undefined,
) { ) {
let item = sessionStorage.getItem('minexlauncher'); const item = sessionStorage.getItem('minexlauncher');
if (item === null) { if (item === null) {
item = '{}'; const json: Record<string, unknown> = {};
}
const json = JSON.parse(item);
json[key] = value; json[key] = value;
sessionStorage.setItem('minexlauncher', JSON.stringify(json)); sessionStorage.setItem(
'minexlauncher',
base64Gzip.compress(JSON.stringify(json)),
);
} else {
const json = JSON.parse(base64Gzip.decompress(item));
json[key] = value;
sessionStorage.setItem(
'minexlauncher',
base64Gzip.compress(JSON.stringify(json)),
);
}
}, },
}, },
}; };
@ -677,7 +683,7 @@ if (window.location.pathname === '/') {
if (consoleElement) { if (consoleElement) {
const consoleHistory = storage.session.get('console'); const consoleHistory = storage.session.get('console');
if (consoleHistory) { if (consoleHistory) {
consoleElement.innerHTML = base64Gzip.decompress(consoleHistory); consoleElement.innerHTML = consoleHistory;
consoleElement.style.display = 'flex'; consoleElement.style.display = 'flex';
consoleElement.scroll(0, consoleElement.scrollHeight); consoleElement.scroll(0, consoleElement.scrollHeight);
} }