From feb43645a5a1ecf3546cbc18e1a65e3b8d5d991c Mon Sep 17 00:00:00 2001 From: PepeYT <106378846+PepeOnGithub@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:11:52 +0100 Subject: [PATCH] Create script.js --- script.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 script.js diff --git a/script.js b/script.js new file mode 100644 index 0000000..135481f --- /dev/null +++ b/script.js @@ -0,0 +1,62 @@ +function generateManifest() { + var name = document.getElementById("name").value; + var description = document.getElementById("description").value; + var version = document.getElementById("version").value; + var uuid = generateUUID(); + var uuid2 = generateUUID2(); + var minimum_api_version = document.getElementById("minimum_api_version").value; + var author = document.getElementById("author").value; + + var manifest = { + "format_version": 2, + "header": { + "name": name, + "description": description, + "uuid": uuid, + "version": [parseInt(version.split(".")[0]), parseInt(version.split(".")[1]), parseInt(version.split(".")[2])], + "min_engine_version": [parseInt(minimum_api_version.split(".")[0]), parseInt(minimum_api_version.split(".")[1]), parseInt(minimum_api_version.split(".")[2])], + "author": author + }, + "modules": [ + { + "type": "resources", + "uuid": uuid2, + "version": [parseInt(version.split(".")[0]), parseInt(version.split(".")[1]), parseInt(version.split(".")[2])] + } + ] + }; + + var manifestJson = JSON.stringify(manifest, null, 2); + + var blob = new Blob([manifestJson], { type: "application/json" }); + var url = URL.createObjectURL(blob); + + var link = document.createElement("a"); + link.href = url; + link.download = "manifest.json"; + link.click(); +} + +function generateUUID() { + var d = new Date().getTime(); + if (typeof performance !== 'undefined' && typeof performance.now === 'function') { + d += performance.now(); + } + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (d + Math.random() * 16) % 16 | 0; + d = Math.floor(d / 16); + return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); + }); +} + +function generateUUID2() { + var d = new Date().getTime(); + if (typeof performance !== 'undefined' && typeof performance.now === 'function') { + d += performance.now(); + } + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (d + Math.random() * 16) % 16 | 0; + d = Math.floor(d / 16); + return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); + }); +}