diff --git a/bun.lockb b/bun.lockb index 626f617..fa6c5e3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index cc616dd..f09f41c 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "express": "^4.19.2", "helmet": "^7.1.0", "morgan": "^1.10.0", + "pako": "^2.1.0", "semver": "^7.6.3", "serve-favicon": "^2.5.0" }, @@ -32,6 +33,7 @@ "@types/errorhandler": "^1.5.3", "@types/eslint__js": "^8.42.3", "@types/morgan": "^1.9.9", + "@types/pako": "^2.0.3", "@types/semver": "^7.5.8", "@types/serve-favicon": "^2.5.7", "eslint": "^9.9.1", diff --git a/src/resources/scripts/main.ts b/src/resources/scripts/main.ts index df48945..3fc9a80 100644 --- a/src/resources/scripts/main.ts +++ b/src/resources/scripts/main.ts @@ -1,4 +1,5 @@ import { gt, coerce } from 'semver'; +import { inflate, deflate } from 'pako'; let selectedVersion: string; @@ -308,6 +309,44 @@ const serviceworker = { }, }; +const base64Gzip = { + decode: function (base64: string) { + // Decode Base64 to binary string + const binaryString = atob(base64); + + // Convert binary string to Uint8Array + const len = binaryString.length; + const bytes = new Uint8Array(len); + for (let i = 0; i < len; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + + // Use pako to decompress the Uint8Array + const decompressed = inflate(bytes, { to: 'string' }); + + return decompressed; + }, + encode: function (inputString: string) { + // Convert the input string to a Uint8Array + const encoder = new TextEncoder(); + const inputBytes = encoder.encode(inputString); + + // Use pako to compress the Uint8Array + const compressedBytes = deflate(inputBytes); + + // Convert the compressed Uint8Array to a binary string + let binaryString = ''; + for (const byte of compressedBytes) { + binaryString += String.fromCharCode(byte); + } + + // Encode the binary string to Base64 + const base64String = btoa(binaryString); + + return base64String; + }, +}; + theme.load(); if (detect.mobile()) { @@ -527,5 +566,5 @@ if (window.location.pathname === '/settings/') { if (window.location.hostname === null) { // Stop the minifier from removing these functions - console.debug([navigate, query, versionSelector, game, mods]); + console.debug([navigate, query, versionSelector, game, mods, base64Gzip]); }