From 6fe5f972f8cf4cab821f7c369ddf37b4859490ee Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Sat, 18 May 2024 17:23:31 +0200 Subject: [PATCH] improve code quality & fix vsc extension build --- assets/jszip.js | 112 +++++------- assets/script.js | 318 +++++++++++++++++----------------- package-lock.json | 6 +- vscExtension/package.json | 2 +- vscExtension/src/extension.js | 2 +- 5 files changed, 213 insertions(+), 227 deletions(-) diff --git a/assets/jszip.js b/assets/jszip.js index 46b728f..4f4998b 100644 --- a/assets/jszip.js +++ b/assets/jszip.js @@ -12,7 +12,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE // Modified by TomatoCake from https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.js (sha512-3FKAKNDHbfUwAgW45wNAvfgJDDdNoTi5PZWU7ak3Xm0X8u0LbDBWZEyPklRebTZ8r+p0M2KIJWDYZQjDPyYQEA==) -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JSZip = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1); } - _utf8len[254]=_utf8len[254]=1; // Invalid sequence start + _utf8len[254] = 1; // Invalid sequence start // convert string to array (typed, when possible) var string2buf = function (str) { @@ -2716,7 +2714,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE // shrinkBuf(utf16buf, out) if (utf16buf.length !== out) { - if(utf16buf.subarray) { + if (utf16buf.subarray) { utf16buf = utf16buf.subarray(0, out); } else { utf16buf.length = out; @@ -2782,7 +2780,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE // 1st step, re-use what's left of the previous chunk if (this.leftOver && this.leftOver.length) { - if(support.uint8array) { + if (support.uint8array) { var previousData = data; data = new Uint8Array(previousData.length + this.leftOver.length); data.set(this.leftOver, 0); @@ -2815,7 +2813,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE * @see GenericWorker.flush */ Utf8DecodeWorker.prototype.flush = function () { - if(this.leftOver && this.leftOver.length) { + if (this.leftOver && this.leftOver.length) { this.push({ data : exports.utf8decode(this.leftOver), meta : {} @@ -3756,12 +3754,12 @@ https://github.com/nodeca/pako/blob/main/LICENSE // but some unknown platform could set it as a compatibility flag. this.dir = this.externalFileAttributes & 0x0010 ? true : false; - if(madeBy === MADE_BY_DOS) { + if (madeBy === MADE_BY_DOS) { // first 6 bits (0 to 5) this.dosPermissions = this.externalFileAttributes & 0x3F; } - if(madeBy === MADE_BY_UNIX) { + if (madeBy === MADE_BY_UNIX) { this.unixPermissions = (this.externalFileAttributes >> 16) & 0xFFFF; // the octal permissions are in (this.unixPermissions & 0x01FF).toString(8); } @@ -4009,7 +4007,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE return this._data.getCompressedWorker(); } else { var result = this._decompressWorker(); - if(!this._dataBinary) { + if (!this._dataBinary) { result = result.pipe(new utf8.Utf8EncodeWorker()); } return CompressedObject.createWorkerFrom(result, compression, compressionOptions); @@ -5358,7 +5356,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE for (var q = 0; q < 256; q++) { _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1); } - _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start + _utf8len[254] = 1; // Invalid sequence start // convert string to array (typed, when possible) @@ -6361,7 +6359,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE s.strstart++; /*** INSERT_STRING(s, s.strstart, hash_head); ***/ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; - hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; s.head[s.ins_h] = s.strstart; /***/ /* strstart never exceeds WSIZE-MAX_MATCH, so there are @@ -6508,7 +6505,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE if (++s.strstart <= max_insert) { /*** INSERT_STRING(s, s.strstart, hash_head); ***/ s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; - hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; s.head[s.ins_h] = s.strstart; /***/ } @@ -6558,7 +6554,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE if (s.match_available) { //Tracevv((stderr,"%c", s->window[s->strstart-1])); /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ - bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]); s.match_available = 0; } @@ -8939,7 +8934,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE for (;;) { here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/ here_bits = here >>> 24; - here_op = (here >>> 16) & 0xff; here_val = here & 0xffff; if ((here_bits) <= bits) { break; } @@ -9435,10 +9429,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE if (state.wsize || (_out !== strm.avail_out && state.mode < BAD && (state.mode < CHECK || flush !== Z_FINISH))) { - if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) { - state.mode = MEM; - return Z_MEM_ERROR; - } + updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out) } _in -= strm.avail_in; _out -= strm.avail_out; @@ -9459,7 +9450,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE } function inflateEnd(strm) { - if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) { return Z_STREAM_ERROR; } @@ -9513,10 +9503,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE /* copy dictionary to window using updatewindow(), which will amend the existing dictionary if appropriate */ ret = updatewindow(strm, dictionary, dictLength, dictLength); - if (ret) { - state.mode = MEM; - return Z_MEM_ERROR; - } state.havedict = 1; // Tracev((stderr, "inflate: dictionary set\n")); return Z_OK; @@ -10027,7 +10013,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE var REPZ_11_138 = 18; /* repeat a zero length 11-138 times (7 bits of repeat count) */ - /* eslint-disable comma-spacing,array-bracket-spacing */ var extra_lbits = /* extra bits for each length code */ [0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]; @@ -10039,7 +10024,6 @@ https://github.com/nodeca/pako/blob/main/LICENSE var bl_order = [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]; - /* eslint-enable comma-spacing,array-bracket-spacing */ /* The lengths of the bit length codes are sent in order of decreasing * probability, to avoid transmitting the lengths for unused bit length codes. diff --git a/assets/script.js b/assets/script.js index 5b8a99c..d4b3f0f 100644 --- a/assets/script.js +++ b/assets/script.js @@ -112,6 +112,147 @@ const openDialog = dialog => { } } +const encode = s => s.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'") +const localize = str => typeof str == "number" ? str.toLocaleString() : encode(str) + " (Please report if you see this)" + +const createImage = () => { + const canvas = document.getElementById("shareImage") + canvas.style.display = "block" + const ctx = canvas.getContext("2d") + ctx.clearRect(0, 0, canvas.width, canvas.height) + ctx.fillStyle = "white" + ctx.fillRect(0, 0, canvas.width, canvas.height) + + const drawing = new Image() + drawing.src = "./assets/images/generated_background.png" + drawing.onload = () => { + ctx.globalAlpha = 0.3 + ctx.drawImage(drawing, 0, 0) + ctx.globalAlpha = 1 + + let x = 20 + let y = 1 + const lineHeight = 21 + const maxWidth = 400 + ctx.font = lineHeight - 1 + "px Arial" + ctx.fillStyle = "black" + + if (packFiles.length > 0) { + ctx.fillText(packFiles.length + " " + (rpMode ? "Resource" : "Data") + "pack" + (packFiles.length == 1 ? "" : "s") + " found", x, y++ * lineHeight, maxWidth) + packFiles.forEach(pack => { + if (pack.features?.enabled?.length > 0) { + ctx.fillText("Selected internal features:", x + 30, y++ * lineHeight, maxWidth) + pack.features.enabled.forEach(feature => ctx.fillText(feature, x + 60, y++ * lineHeight, maxWidth)) + } + if (pack.filter?.block?.length > 0) { + ctx.fillText("Pack filters:", x + 60, y++ * lineHeight, maxWidth) + pack.filter.block.forEach(filter => { + if (filter.namespace) ctx.fillText("Namespace: " + filter.namespace, x + 90, y++ * lineHeight, maxWidth) + if (filter.path) ctx.fillText("Path: " + filter.path, x + 90, y++ * lineHeight, maxWidth) + }) + } + }) + } + if (packFiles.length == 0 && (filetypes.fsh || filetypes.vsh || filetypes.xcf || filetypes.glsl)) ctx.fillText("Shader found:", x, y++ * lineHeight, maxWidth) + if (Object.keys(commands).length > 0) { + ctx.fillText("Total amount of commands: " + localize(Object.keys(commands).reduce((a, b) => a + commands[b], 0)), x, y++ * lineHeight, maxWidth) + ctx.fillText("Unique commands: " + localize(Object.keys(commands).length), x + 30, y++ * lineHeight, maxWidth) + } + if (comments > 0) ctx.fillText("Comments: " + localize(comments), x + 30, y++ * lineHeight, maxWidth) + if (empty > 0) ctx.fillText("Empty lines: " + localize(empty), x + 30, y++ * lineHeight, maxWidth) + ctx.fillText((Object.keys(filetypes).length > 2 ? "Top 3 p" : "P") + "ack file types found:", x, y++ * lineHeight, maxWidth) + Object.keys(filetypes).sort((a, b) => filetypes[b] - filetypes[a]).slice(0, 3).forEach(type => ctx.fillText("." + type + ": " + localize(filetypes[type]), x + 30, y++ * lineHeight, maxWidth)) + + if (dpExclusive.scoreboards > 0) ctx.fillText("Scoreboards created: " + localize(dpExclusive.scoreboards), x, y++ * lineHeight, maxWidth) + if (!rpMode && Object.values(dpExclusive.selectors).reduce((a, b) => a + b) != 0) { + ctx.fillText((Object.keys(dpExclusive.selectors).filter(i => dpExclusive.selectors[i] > 0).length > 2 ? "Top 3 s" : "S") + "electors used:", x, y++ * lineHeight, maxWidth) + Object.keys(dpExclusive.selectors).filter(i => dpExclusive.selectors[i] > 0).sort((a, b) => dpExclusive.selectors[b] - dpExclusive.selectors[a]).slice(0, 3) + .forEach(type => ctx.fillText("@" + type + ": " + localize(dpExclusive.selectors[type]), x + 30, y++ * lineHeight, maxWidth)) + } + if (!rpMode && Object.values(dpExclusive.folders).reduce((a, b) => a + b) != 0) { + ctx.fillText("Data pack features used:", x, y++ * lineHeight, maxWidth) + Object.keys(dpExclusive.folders).filter(i => dpExclusive.folders[i] > 0).sort((a, b) => dpExclusive.folders[b] - dpExclusive.folders[a]) + .forEach(type => ctx.fillText(type + ": " + localize(dpExclusive.folders[type]), x + 30, y++ * lineHeight, maxWidth)) + } + if (rpMode && Object.values(rpExclusive).reduce((a, b) => a + b) != 0) { + ctx.fillText("Resource pack features used:", x, y++ * lineHeight, maxWidth) + Object.keys(rpExclusive).filter(i => !isNaN(i) && rpExclusive[i] > 0).sort((a, b) => rpExclusive[b] - rpExclusive[a]) + .forEach(type => ctx.fillText(type + ": " + localize(rpExclusive[type]), x + 30, y++ * lineHeight, maxWidth)) + } + + x = 450 + y = 3 + ctx.font = "28px Arial" + ctx.fillText((Object.keys(commands).length > 5 ? "Top c" : "C") + "ommands", x, 40, maxWidth) + ctx.font = "20px Arial" + + commands = Object.fromEntries(Object.entries(commands).sort(([, a], [, b]) => b - a)) + Object.keys(commands).slice(0, 5).forEach(cmd => { + ctx.fillText(cmd + ": " + localize(commands[cmd]), x, y++ * lineHeight, maxWidth) + if (cmdsBehindExecute[cmd]) ctx.fillText("Behind execute: " + localize(cmdsBehindExecute[cmd]), x + 30, y++ * lineHeight, maxWidth) + if (cmdsBehindMacros[cmd]) ctx.fillText("Behind macro: " + localize(cmdsBehindMacros[cmd]), x + (cmdsBehindExecute[cmd] ? 90 : 30), y++ * lineHeight, maxWidth) + }) + } +} + +const share = async type => { + let content = "" + if (type == "txt") content = document.getElementById("result").innerText + else if (type == "json" || type == "link") { + content = JSON.stringify({ + files, + done, + error, + rpMode, + + filetypes, + filetypesOther, + packFiles, + commands, + cmdsBehindExecute, + cmdsBehindMacros, + cmdsBehindReturn, + comments, + empty, + emptyFiles, + dpExclusive, + rpExclusive + }, null, type == "json" ? "\t" : void 0) + + if (type == "link") { + const name = Math.random().toString(36).slice(8) + + const res = await fetch("https://sh0rt.zip", { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "User-Agent": "TomatoCake Pack-Analyzer" + }, + body: JSON.stringify({ + name, + date: Date.now() + 1000 * 60 * 60 * 24 * 30, + url: location.href + "?data=" + encodeURIComponent(content) + }) + }) + + const json = await res.json() + if (res.ok) { + document.getElementById("share-link").href = "https://sh0rt.zip/" + name + document.getElementById("share-link").innerText = "https://sh0rt.zip/" + name + document.getElementById("share-img").src = "https://sh0rt.zip/qr/" + name + openDialog(document.getElementById("shareDialog")) + } else alert("Couldn't create link: " + json.error) + return + } + } else if (type == "png") return createImage() + + const download = document.createElement("a") + download.download = "export." + type + download.href = "data:application/" + type + "," + encodeURIComponent(content) + download.click() +} + window.addEventListener("DOMContentLoaded", () => { if (localStorage.getItem("theme") == "light") document.body.classList.add("light") else if (window.matchMedia("(prefers-color-scheme: light)").matches) { @@ -146,7 +287,7 @@ window.addEventListener("DOMContentLoaded", () => { document.getElementById("clear-results").addEventListener("click", () => { document.getElementById("progress").innerText = "" document.getElementById("result").innerHTML = "" - document.getElementById("resultButtons").hidden = true + document.getElementById("resultButtons").setAttribute("hidden", "") document.getElementById("shareImage").style.display = "none" if (interval) clearInterval(interval) }) @@ -250,145 +391,6 @@ window.addEventListener("paste", async event => { } }) -const localize = string => string.toLocaleString() - -async function share(type) { - let content = "" - if (type == "txt") content = document.getElementById("result").innerText - else if (type == "json" || type == "link") { - content = JSON.stringify({ - files, - done, - error, - rpMode, - - filetypes, - filetypesOther, - packFiles, - commands, - cmdsBehindExecute, - cmdsBehindMacros, - cmdsBehindReturn, - comments, - empty, - emptyFiles, - dpExclusive, - rpExclusive - }, null, type == "json" ? "\t" : void 0) - - if (type == "link") { - const name = Math.random().toString(36).slice(8) - - const res = await fetch("https://sh0rt.zip", { - method: "POST", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "User-Agent": "TomatoCake Pack-Analyzer" - }, - body: JSON.stringify({ - name, - date: Date.now() + 1000 * 60 * 60 * 24 * 30, - url: location.href + "?data=" + encodeURIComponent(content) - }) - }) - - const json = await res.json() - if (res.ok) { - document.getElementById("share-link").href = "https://sh0rt.zip/" + name - document.getElementById("share-link").innerText = "https://sh0rt.zip/" + name - document.getElementById("share-img").src = "https://sh0rt.zip/qr/" + name - openDialog(document.getElementById("shareDialog")) - } else alert("Couldn't create link: " + json.error) - return - } - } else if (type == "png") return createImage() - - const download = document.createElement("a") - download.download = "export." + type - download.href = "data:application/" + type + "," + encodeURIComponent(content) - download.click() -} -function createImage() { - const canvas = document.getElementById("shareImage") - canvas.style.display = "block" - const ctx = canvas.getContext("2d") - ctx.clearRect(0, 0, canvas.width, canvas.height) - ctx.fillStyle = "white" - ctx.fillRect(0, 0, canvas.width, canvas.height) - - const drawing = new Image() - drawing.src = "./assets/images/generated_background.png" - drawing.onload = () => { - ctx.globalAlpha = 0.3 - ctx.drawImage(drawing, 0, 0) - ctx.globalAlpha = 1 - - let x = 20 - let y = 1 - const lineHeight = 21 - const maxWidth = 400 - ctx.font = lineHeight - 1 + "px Arial" - ctx.fillStyle = "black" - - if (packFiles.length > 0) { - ctx.fillText(packFiles.length + " " + (rpMode ? "Resource" : "Data") + "pack" + (packFiles.length == 1 ? "" : "s") + " found", x, y++ * lineHeight, maxWidth) - packFiles.forEach(pack => { - if (pack.features?.enabled?.length > 0) { - ctx.fillText("Selected internal features:", x + 30, y++ * lineHeight, maxWidth) - pack.features.enabled.forEach(feature => ctx.fillText(feature, x + 60, y++ * lineHeight, maxWidth)) - } - if (pack.filter?.block?.length > 0) { - ctx.fillText("Pack filters:", x + 60, y++ * lineHeight, maxWidth) - pack.filter.block.forEach(filter => { - if (filter.namespace) ctx.fillText("Namespace: " + filter.namespace, x + 90, y++ * lineHeight, maxWidth) - if (filter.path) ctx.fillText("Path: " + filter.path, x + 90, y++ * lineHeight, maxWidth) - }) - } - }) - } - if (packFiles.length == 0 && (filetypes.fsh || filetypes.vsh || filetypes.xcf || filetypes.glsl)) ctx.fillText("Shader found:", x, y++ * lineHeight, maxWidth) - if (Object.keys(commands).length > 0) { - ctx.fillText("Total amount of commands: " + localize(Object.keys(commands).reduce((a, b) => a + commands[b], 0)), x, y++ * lineHeight, maxWidth) - ctx.fillText("Unique commands: " + localize(Object.keys(commands).length), x + 30, y++ * lineHeight, maxWidth) - } - if (comments > 0) ctx.fillText("Comments: " + localize(comments), x + 30, y++ * lineHeight, maxWidth) - if (empty > 0) ctx.fillText("Empty lines: " + localize(empty), x + 30, y++ * lineHeight, maxWidth) - ctx.fillText((Object.keys(filetypes).length > 2 ? "Top 3 p" : "P") + "ack file types found:", x, y++ * lineHeight, maxWidth) - Object.keys(filetypes).sort((a, b) => filetypes[b] - filetypes[a]).slice(0, 3).forEach(type => ctx.fillText("." + type + ": " + localize(filetypes[type]), x + 30, y++ * lineHeight, maxWidth)) - - if (dpExclusive.scoreboards > 0) ctx.fillText("Scoreboards created: " + localize(dpExclusive.scoreboards), x, y++ * lineHeight, maxWidth) - if (!rpMode && Object.values(dpExclusive.selectors).reduce((a, b) => a + b) != 0) { - ctx.fillText((Object.keys(dpExclusive.selectors).filter(i => dpExclusive.selectors[i] > 0).length > 2 ? "Top 3 s" : "S") + "electors used:", x, y++ * lineHeight, maxWidth) - Object.keys(dpExclusive.selectors).filter(i => dpExclusive.selectors[i] > 0).sort((a, b) => dpExclusive.selectors[b] - dpExclusive.selectors[a]).slice(0, 3) - .forEach(type => ctx.fillText("@" + type + ": " + localize(dpExclusive.selectors[type]), x + 30, y++ * lineHeight, maxWidth)) - } - if (!rpMode && Object.values(dpExclusive.folders).reduce((a, b) => a + b) != 0) { - ctx.fillText("Data pack features used:", x, y++ * lineHeight, maxWidth) - Object.keys(dpExclusive.folders).filter(i => dpExclusive.folders[i] > 0).sort((a, b) => dpExclusive.folders[b] - dpExclusive.folders[a]) - .forEach(type => ctx.fillText(type + ": " + localize(dpExclusive.folders[type]), x + 30, y++ * lineHeight, maxWidth)) - } - if (rpMode && Object.values(rpExclusive).reduce((a, b) => a + b) != 0) { - ctx.fillText("Resource pack features used:", x, y++ * lineHeight, maxWidth) - Object.keys(rpExclusive).filter(i => !isNaN(i) && rpExclusive[i] > 0).sort((a, b) => rpExclusive[b] - rpExclusive[a]) - .forEach(type => ctx.fillText(type + ": " + localize(rpExclusive[type]), x + 30, y++ * lineHeight, maxWidth)) - } - - x = 450 - y = 3 - ctx.font = "28px Arial" - ctx.fillText((Object.keys(commands).length > 5 ? "Top c" : "C") + "ommands", x, 40, maxWidth) - ctx.font = "20px Arial" - - commands = Object.fromEntries(Object.entries(commands).sort(([, a], [, b]) => b - a)) - Object.keys(commands).slice(0, 5).forEach(cmd => { - ctx.fillText(cmd + ": " + localize(commands[cmd]), x, y++ * lineHeight, maxWidth) - if (cmdsBehindExecute[cmd]) ctx.fillText("Behind execute: " + localize(cmdsBehindExecute[cmd]), x + 30, y++ * lineHeight, maxWidth) - if (cmdsBehindMacros[cmd]) ctx.fillText("Behind macro: " + localize(cmdsBehindMacros[cmd]), x + (cmdsBehindExecute[cmd] ? 90 : 30), y++ * lineHeight, maxWidth) - }) - } -} - const processFile = async (filePath = "", name = "", loadContentCallback = () => {}) => { const ext = name.split(".").pop() if ( @@ -687,7 +689,7 @@ async function mainScan(hasData = false) { if (done + error == files || hasData) { clearInterval(interval) if (files == 0) return document.getElementById("progress").innerText = "No files found!" - document.getElementById("resultButtons").hidden = false + document.getElementById("resultButtons").removeAttribute("hidden") if (error == 0) document.getElementById("progress").innerText = "" if (Object.values(filetypes).reduce((a, b) => a + b) == 0) document.getElementById("progress").innerHTML = "No " + (rpMode ? "resource" : "data") + "pack files found!" @@ -724,24 +726,24 @@ async function mainScan(hasData = false) { } else description = pack.pack.description } else description = "No description" - return "" + description.replace(/§[0-9a-flmnor]/gi, "") + + return "" + encode(description.replace(/§[0-9a-flmnor]/g, "")) + (versions.some(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == pack.pack.pack_format) ? "
Supported versions: " + - (versions.findLast(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == oldestFormat)?.name || "?") + + encode(versions.findLast(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == oldestFormat)?.name || "?") + " - " + - (versions.find(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == newestFormat)?.name || "?") + + encode(versions.find(ver => (rpMode ? ver.resourcepack_version : ver.datapack_version) == newestFormat)?.name || "?") + "" : "") + "
" + (pack.features?.enabled?.length > 0 ? "
Selected internal features: " + - pack.features.enabled.map(feature => "" + feature + "").join(", ") + "" + pack.features.enabled.map(feature => "" + encode(feature) + "").join(", ") + "
" : "") + (pack.filter?.block?.length > 0 ? "
Pack filters:
" + pack.filter.block.map(filter => "" + - (filter.namespace ? "Namespace: " + filter.namespace + "" : "") + + (filter.namespace ? "Namespace: " + encode(filter.namespace) + "" : "") + (filter.namespace && filter.path ? ", " : "") + - (filter.path ? "Path: " + filter.path + "" : "") + + (filter.path ? "Path: " + encode(filter.path) + "" : "") + "" ).join("
") + "
" : "") }).join("
") + "
" @@ -755,54 +757,54 @@ async function mainScan(hasData = false) { (comments > 0 ? "Comments: " + localize(comments) + "
" : "") + (empty > 0 ? "Empty lines: " + localize(empty) + "
" : "") + "Pack file types found:
" + - Object.keys(filetypes).sort((a, b) => filetypes[b] - filetypes[a]).map(type => "." + type + ": " + localize(filetypes[type]) + "
").join("") + + Object.keys(filetypes).sort((a, b) => filetypes[b] - filetypes[a]).map(type => "." + encode(type) + ": " + localize(filetypes[type]) + "
").join("") + (Object.keys(filetypesOther).length > 0 ? "
" + "Non-pack file types found:" + Object.keys(filetypesOther).sort((a, b) => filetypesOther[b] - filetypesOther[a]) - .map(type => "" + type + ": " + localize(filetypesOther[type]) + "
").join("") + + .map(type => "" + encode(type) + ": " + localize(filetypesOther[type]) + "
").join("") + "

" : "") + (uncalledFunctions.length > 0 ? "Uncalled functions:
" + - uncalledFunctions.map(func => "" + func + "
").join("") + + uncalledFunctions.map(func => "" + encode(func) + "
").join("") + "
" : "") + (missingFunctions.length > 0 ? "Missing functions:
" + - missingFunctions.map(func => "" + func + "
").join("") + + missingFunctions.map(func => "" + encode(func) + "
").join("") + "
" : "") + (unaddedAttributes.length > 0 ? "Attribute UUIDs added but not removed (using /attribute):
" + - unaddedAttributes.map(attr => "" + attr + "
").join("") + + unaddedAttributes.map(attr => "" + encode(attr) + "
").join("") + "
" : "") + (unremovedAttributes.length > 0 ? "Attribute UUIDs removed but not added (using /attribute):
" + - unremovedAttributes.map(attr => "" + attr + "
").join("") + + unremovedAttributes.map(attr => "" + encode(attr) + "
").join("") + "
" : "") + (emptyFiles.length > 0 ? "Empty files:
" + - emptyFiles.map(func => "" + func + "
").join("") + + emptyFiles.map(func => "" + encode(func) + "
").join("") + "
" : "") + (dpExclusive.scoreboards > 0 ? "Scoreboards created: " + localize(dpExclusive.scoreboards) + "
" : "") + (!rpMode && Object.values(dpExclusive.selectors).reduce((a, b) => a + b) != 0 ? "Selectors used:
" : "") + Object.keys(dpExclusive.selectors).filter(i => dpExclusive.selectors[i] > 0).sort((a, b) => dpExclusive.selectors[b] - dpExclusive.selectors[a]) - .map(type => "@" + type + ": " + localize(dpExclusive.selectors[type]) + "
").join("") + + .map(type => "@" + encode(type) + ": " + localize(dpExclusive.selectors[type]) + "
").join("") + (!rpMode && Object.values(dpExclusive.folders).reduce((a, b) => a + b) != 0 ? "Data pack features used:
" : "") + Object.keys(dpExclusive.folders).filter(i => dpExclusive.folders[i] > 0).sort((a, b) => dpExclusive.folders[b] - dpExclusive.folders[a]) - .map(type => "" + type + ": " + localize(dpExclusive.folders[type]) + "
").join("") + + .map(type => "" + encode(type) + ": " + localize(dpExclusive.folders[type]) + "
").join("") + (!rpMode && Object.values(dpExclusive.tags).reduce((a, b) => a + b) != 0 ? "Tags used:
" : "") + Object.keys(dpExclusive.tags).filter(i => dpExclusive.tags[i] > 0).sort((a, b) => dpExclusive.tags[b] - dpExclusive.tags[a]) - .map(type => "" + type + ": " + localize(dpExclusive.tags[type]) + "
").join("") + + .map(type => "" + encode(type) + ": " + localize(dpExclusive.tags[type]) + "
").join("") + (rpMode && Object.values(rpExclusive).reduce((a, b) => a + b) != 0 ? "
Resource pack features used:
" : "") + Object.keys(rpExclusive).filter(i => rpExclusive[i] > 0).sort((a, b) => rpExclusive[b] - rpExclusive[a]) - .map(type => "" + type + ": " + localize(rpExclusive[type]) + "
").join("") + .map(type => "" + encode(type) + ": " + localize(rpExclusive[type]) + "
").join("") html += "
" commands = Object.fromEntries(Object.entries(commands).sort(([, a], [, b]) => b - a)) diff --git a/package-lock.json b/package-lock.json index 483a580..8f868df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -707,9 +707,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.773", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.773.tgz", - "integrity": "sha512-87eHF+h3PlCRwbxVEAw9KtK3v7lWfc/sUDr0W76955AdYTG4bV/k0zrl585Qnj/skRMH2qOSiE+kqMeOQ+LOpw==", + "version": "1.4.774", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.774.tgz", + "integrity": "sha512-132O1XCd7zcTkzS3FgkAzKmnBuNJjK8WjcTtNuoylj7MYbqw5eXehjQ5OK91g0zm7OTKIPeaAG4CPoRfD9M1Mg==", "dev": true }, "node_modules/entities": { diff --git a/vscExtension/package.json b/vscExtension/package.json index 69eea5a..0b46ba3 100644 --- a/vscExtension/package.json +++ b/vscExtension/package.json @@ -14,7 +14,7 @@ "url": "https://github.com/DEVTomatoCake/Pack-Analyzer.git" }, "engines": { - "vscode": "^1.88.0" + "vscode": "^1.89.0" }, "categories": [ "Other" diff --git a/vscExtension/src/extension.js b/vscExtension/src/extension.js index 74d362c..d0284bf 100644 --- a/vscExtension/src/extension.js +++ b/vscExtension/src/extension.js @@ -485,7 +485,7 @@ class PackAnalyzer { comments > 0 ? "comments" : void 0, empty > 0 ? "empty" : void 0, - emptyFiles > 0 ? "emptyFiles" : void 0 + emptyFiles.length > 0 ? "emptyFiles" : void 0 ].filter(Boolean).map(child => ({item: child})) } }