From d6c2c863eb05ddd47e5bb55d208679ffc1aa74e1 Mon Sep 17 00:00:00 2001 From: Artur Kolecki Date: Tue, 28 Feb 2023 14:08:26 +0100 Subject: [PATCH] Little changes in json formatter. (#83) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Artur KoĊ‚ecki Reviewed-on: https://gitea.release11.com/R11/release11-tools-web/pulls/83 --- Frontend/assets/scripts/tools/json.js | 22 ++++++++++++++++------ Frontend/tools/jsonFormatter.html | 7 ++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Frontend/assets/scripts/tools/json.js b/Frontend/assets/scripts/tools/json.js index 5528adc..6e448b1 100644 --- a/Frontend/assets/scripts/tools/json.js +++ b/Frontend/assets/scripts/tools/json.js @@ -1,29 +1,39 @@ function formatAndValidateJson(errorElement) { const input = document.querySelector('#jsonBlock'); - const errorOutput = document.getElementById(errorElement); + const processInfo = document.getElementById(errorElement); try { + const start = new Date(); + const obj = JSON.parse(input.textContent); input.innerHTML = JSON.stringify(obj, null, 2); - errorOutput.innerText = ""; + processInfo.innerText = ""; hljs.highlightElement(input); + + const end = new Date(); + processInfo.innerHTML = "Validation and formatting time: " + (end.getMilliseconds() - start.getMilliseconds()) + "ms"; } catch (error) { - errorOutput.innerText = error; + processInfo.innerHTML = "" + error + ""; console.error("Error: ", error) } } function minimizeJson(errorElement) { const input = document.querySelector('#jsonBlock'); - const errorOutput = document.getElementById(errorElement); + const processInfo = document.getElementById(errorElement); try { + const start = new Date(); + const obj = JSON.parse(input.textContent); input.innerHTML = JSON.stringify(obj); - errorOutput.innerText = ""; + processInfo.innerText = ""; hljs.highlightElement(input); + + const end = new Date(); + processInfo.innerHTML = "Validation and formatting time: " + (end.getMilliseconds() - start.getMilliseconds()) + "ms"; } catch (error) { - errorOutput.innerText = error; + processInfo.innerHTML = "" + error + ""; console.error("Error: ", error) } } \ No newline at end of file diff --git a/Frontend/tools/jsonFormatter.html b/Frontend/tools/jsonFormatter.html index a055a04..05a3b6e 100644 --- a/Frontend/tools/jsonFormatter.html +++ b/Frontend/tools/jsonFormatter.html @@ -11,6 +11,7 @@ + @@ -21,7 +22,7 @@

Online JSON Formatter

-

+

           {"enter": "your", "json": "here"}
@@ -29,11 +30,11 @@