diff --git a/Frontend/assets/scripts/tools/jsonFormatter.js b/Frontend/assets/scripts/tools/jsonFormatter.js index 54b7da5..64f7609 100644 --- a/Frontend/assets/scripts/tools/jsonFormatter.js +++ b/Frontend/assets/scripts/tools/jsonFormatter.js @@ -11,13 +11,13 @@ const mergeHTMLPlugin = (function () { */ function escapeHTML(value) { return value - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); } - + /* plugin itself */ @@ -161,6 +161,78 @@ const mergeHTMLPlugin = (function () { }()); +function formatAndValidateJson(errorElement) { + const input = document.querySelector('#jsonBlock'); + const processInfo = document.getElementById(errorElement); + + const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting" + + fetch(address, { + method: 'POST', + body: input.textContent + }) + .then(async (response) => { + const promise = response.json(); + if (!response.ok) { + throw Error(await promise); + } + + return promise; + }) + .then((data) => { + input.innerText = data.data; + processInfo.innerText = ""; + hljs.highlightElement(input); + + processInfo.innerHTML = "Computed in " + data.time + "ms"; + }) + .catch((error) => { + processInfo.innerHTML = "" + error.data + ""; + console.error('Error:', error); + }); +} + +function minimizeJson(errorElement) { + const input = document.querySelector('#jsonBlock'); + const processInfo = document.getElementById(errorElement); + + const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize" + + fetch(address, { + method: 'POST', + body: input.textContent + }) + .then(async (response) => { + const promise = response.json(); + if (!response.ok) { + throw Error(await promise); + } + + return promise; + }) + .then((data) => { + input.innerText = data.data; + processInfo.innerText = ""; + hljs.highlightElement(input); + + processInfo.innerHTML = "Computed in " + data.time + "ms"; + }) + .catch((error) => { + processInfo.innerHTML = "" + error.data + ""; + console.error('Error:', error); + }); +} + +function clearJsonData() { + const input = document.querySelector('#jsonBlock'); + input.textContent = ""; +} + +function insertDefaultJson() { + const input = document.querySelector('#jsonBlock'); + input.textContent = "{\"enter\": \"your\", \"json\": \"here\"}"; + hljs.highlightElement(input); +} /** * This function is executed after the page is loaded. @@ -176,75 +248,3 @@ function init() { hljs.addPlugin(mergeHTMLPlugin); } -function formatAndValidateJson(errorElement) { - const input = document.querySelector('#jsonBlock'); - const processInfo = document.getElementById(errorElement); - - const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting" - - fetch(address, { - method: 'POST', - body: input.textContent - }) - .then(async (response) => { - const promise = response.json(); - if (!response.ok) { - throw Error(await promise); - } - - return promise; - }) - .then((data) => { - input.innerText = data.data; - processInfo.innerText = ""; - hljs.highlightElement(input); - - processInfo.innerHTML = "Computed in " + data.time + "ms"; - }) - .catch((error) => { - processInfo.innerHTML = "" + error.data + ""; - console.error('Error:', error); - }); - } - - function minimizeJson(errorElement) { - const input = document.querySelector('#jsonBlock'); - const processInfo = document.getElementById(errorElement); - - const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize" - - fetch(address, { - method: 'POST', - body: input.textContent - }) - .then(async (response) => { - const promise = response.json(); - if (!response.ok) { - throw Error(await promise); - } - - return promise; - }) - .then((data) => { - input.innerText = data.data; - processInfo.innerText = ""; - hljs.highlightElement(input); - - processInfo.innerHTML = "Computed in " + data.time + "ms"; - }) - .catch((error) => { - processInfo.innerHTML = "" + error.data + ""; - console.error('Error:', error); - }); - } - - function clearJsonData() { - const input = document.querySelector('#jsonBlock'); - input.textContent = ""; - } - - function insertDefaultJson() { - const input = document.querySelector('#jsonBlock'); - input.textContent = "{\"enter\": \"your\", \"json\": \"here\"}"; - hljs.highlightElement(input); - } \ No newline at end of file