From 7d95a8825d20c6c02adcb4720f31be154807fe33 Mon Sep 17 00:00:00 2001 From: ByteDice Date: Sun, 28 Jun 2026 20:31:17 +0200 Subject: [PATCH] added a hashed ID & fixed some bugs when importing --- global/globalScript.js | 14 +++++++- toys/license/index.html | 9 +++-- toys/license/input.js | 72 +++++++++++++++++++++++++--------------- toys/license/license.css | 10 +++++- toys/license/license.js | 6 +++- toys/license/script.js | 8 +++-- 6 files changed, 82 insertions(+), 37 deletions(-) diff --git a/global/globalScript.js b/global/globalScript.js index 8107e02..7a621f9 100644 --- a/global/globalScript.js +++ b/global/globalScript.js @@ -173,7 +173,7 @@ document.addEventListener("DOMContentLoaded", async function() { switch (CURRENT_PAGE) { case (PAGES.SYNTHWAVE): loadingScreenSynthwave(); break - case (PAGES.LICENSE): loadingScreenLicense(); loadingScreenStars(); break + case (PAGES.LICENSE): loadingScreenStars(); await loadingScreenLicense(); break case (PAGES.TOYS): loadingScreenStars(); break case (PAGES.LIBS): loadingScreenStars(); break } @@ -236,6 +236,18 @@ window.addEventListener("pageshow", (event) => { let prevAnimationState = isAnimating + +async function sha256(text) { + const data = new TextEncoder().encode(text); + + const hash = await crypto.subtle.digest("SHA-256", data); + + return [...new Uint8Array(hash)] + .map(x => x.toString(16).padStart(2, "0")) + .join(""); +} + + /* document.addEventListener("visibilitychange", function() { if (document.hidden) { diff --git a/toys/license/index.html b/toys/license/index.html index 4dbd338..0ed4c90 100644 --- a/toys/license/index.html +++ b/toys/license/index.html @@ -59,7 +59,7 @@

Basic


- + @@ -87,12 +87,9 @@

- +

NR-ID: 8f434346648f6b96

diff --git a/toys/license/input.js b/toys/license/input.js index e10974d..598a151 100644 --- a/toys/license/input.js +++ b/toys/license/input.js @@ -17,42 +17,43 @@ let jsonData = { const customPicOption = document.getElementById("customPic") -function prepInputs() { - const VMAP = { - img: "picInput", - user: "authorInput", - title: "titleInput", - silly: "sillyInput", - issued: "createdInput", - expires: "expireInput", - identity: "identityInput", - signature: "signatureInput", - imgUpload: "picUpload" - } +const VMAP = { + img: "picInput", + user: "authorInput", + title: "titleInput", + silly: "sillyInput", + issued: "createdInput", + expires: "expireInput", + identity: "identityInput", + signature: "signatureInput", + imgUpload: "picUpload" +} + +async function prepInputs() { function getE(e) { return document.getElementById(e) } - getE(VMAP.img) .oninput = function() { jsonData.img.preset = this.value; updLicense() } - getE(VMAP.user) .oninput = function() { jsonData.user = this.value; updLicense() } - getE(VMAP.title) .oninput = function() { jsonData.title = this.value; updLicense() } - getE(VMAP.silly) .oninput = function() { jsonData.silly = this.value; updLicense() } - getE(VMAP.issued) .oninput = function() { jsonData.issued = this.value; updLicense() } - getE(VMAP.expires) .oninput = function() { jsonData.expires = this.value; updLicense() } - getE(VMAP.identity) .oninput = function() { jsonData.identity = this.value; updLicense() } - getE(VMAP.signature).oninput = function() { jsonData.signature = this.value; updLicense() } + getE(VMAP.img) .oninput = async function() { jsonData.img.preset = this.value; await updLicense() } + getE(VMAP.user) .oninput = async function() { jsonData.user = this.value; await updLicense() } + getE(VMAP.title) .oninput = async function() { jsonData.title = this.value; await updLicense() } + getE(VMAP.silly) .oninput = async function() { jsonData.silly = parseInt(this.value); await updLicense() } + getE(VMAP.issued) .oninput = async function() { jsonData.issued = this.value; await updLicense() } + getE(VMAP.expires) .oninput = async function() { jsonData.expires = this.value; await updLicense() } + getE(VMAP.identity) .oninput = async function() { jsonData.identity = this.value; await updLicense() } + getE(VMAP.signature).oninput = async function() { jsonData.signature = this.value; await updLicense() } - getE(VMAP.imgUpload).oninput = function() { + getE(VMAP.imgUpload).oninput = async function() { if (this.files.length == 0) { return; } let f = this.files[0] jsonData.img.file = URL.createObjectURL(f) customPicOption.innerHTML = `Custom (${f.name})` - updLicense() + await updLicense() } } -function updLicense() { license.updateFromJSON(jsonData) } +async function updLicense() { await license.updateFromJSON(jsonData) } function importData() { @@ -61,7 +62,7 @@ function importData() { } -function importFromB64(b64) { +async function importFromB64(b64) { if (b64.startsWith("B8D6:")) { b64 = b64.slice(5) } try { @@ -72,12 +73,29 @@ function importFromB64(b64) { { alert("Invalid data string imported (Invalid fields). Full results:\n" + isValid.join("\n")); return } jsonData = data - updLicense() + // make sure to add this since it isnt exported + jsonData.img = { preset: "boykisser", file: "" } + await updLicense() + makeOptionsTheSameAsJSON() } catch (err) { alert("Invalid data string imported. Full results:\n" + err); return } } +function makeOptionsTheSameAsJSON() { + function getE(e) { return document.getElementById(e) } + + getE(VMAP.user).value = jsonData.user + getE(VMAP.title).value = jsonData.title + getE(VMAP.silly).value = jsonData.silly + getE(VMAP.issued).value = jsonData.issued + getE(VMAP.expires).value = jsonData.expires + getE(VMAP.identity).value = jsonData.identity + getE(VMAP.signature).value = jsonData.signature + getE(VMAP.img).value = jsonData.img.preset +} + + // I wanna keep compatibility with older versions function validateJSON_v0(obj) { let is_valid = ( @@ -115,7 +133,9 @@ function validateJSON_v0(obj) { function exportData() { - let str = JSON.stringify(jsonData) + let strippedData = jsonData + delete strippedData.img + let str = JSON.stringify(strippedData) let b64 = btoa(str) let watermarked = "B8D6:" + b64 navigator.clipboard.writeText(watermarked) diff --git a/toys/license/license.css b/toys/license/license.css index 34dd04e..79863dd 100644 --- a/toys/license/license.css +++ b/toys/license/license.css @@ -121,10 +121,18 @@ h2 { .sillyValue:last-child { border-radius: 0px 5px 5px 0px; } -#titleValue, #DtitleValue { +#titleValue { grid-area: 1 / 1 / 2 / 3; font-size: 2rem; margin: 0% auto 0% auto; height: max-content; text-align: center; +} +#hashID { + position: absolute; + bottom: 12px; + right: 0%; + margin: 0% 30px 0% 0%; + color: var(--navBarBtn_Inner); + font-size: 0.6rem; } \ No newline at end of file diff --git a/toys/license/license.js b/toys/license/license.js index 1ca6c52..181b42f 100644 --- a/toys/license/license.js +++ b/toys/license/license.js @@ -3,6 +3,7 @@ const sillyOptNumber = document.getElementById("sillyNumberValue") class License { constructor() { + this.idE = undefined this.imgE = undefined this.userE = undefined this.titleE = undefined @@ -17,7 +18,7 @@ class License { } - updateFromJSON(json) { + async updateFromJSON(json) { this.userE .textContent = json.user this.titleE .textContent = json.title this.issuedE .textContent = json.issued @@ -27,6 +28,9 @@ class License { this.setSillyValue(json.silly) this.setImgValue(json.img) + + let hash = await sha256(JSON.stringify(json)) + this.idE.textContent = "NR-ID: " + hash.slice(0, 16) } diff --git a/toys/license/script.js b/toys/license/script.js index 634c98f..cd03d30 100644 --- a/toys/license/script.js +++ b/toys/license/script.js @@ -1,7 +1,7 @@ CURRENT_PAGE = PAGES.LICENSE -function loadingScreenLicense() { +async function loadingScreenLicense() { setLoadingProgress("Preparing license...") const VMAP = { @@ -11,7 +11,8 @@ function loadingScreenLicense() { expires: "expireValue", identity: "genderValue", signature: "signatureValue", - img: "picValue" + img: "picValue", + id: "hashID" } function getE(e) { return document.getElementById(e) } @@ -23,6 +24,7 @@ function loadingScreenLicense() { license.identityE = getE(VMAP.identity) license.signatureE = getE(VMAP.signature) license.imgE = getE(VMAP.img) + license.idE = getE(VMAP.id) for (let i = 0; i < 10; i++) { license.sillyValues.push(document.getElementById(`sillyValue${i}`)) @@ -30,6 +32,6 @@ function loadingScreenLicense() { setLoadingProgress("Preparing options...") prepInputs() - updLicense(); + await updLicense(); scaleDisplayLicense(); } \ No newline at end of file