Co-authored-by: Artur Kołecki <koleckiartur@icloud.com> Reviewed-on: R11/release11-tools-web#106
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
function formatAndValidateJson(errorElement) {
|
||||
const input = document.querySelector('#jsonBlock');
|
||||
const processInfo = document.getElementById(errorElement);
|
||||
const start = new Date();
|
||||
|
||||
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
|
||||
|
||||
@@ -10,22 +9,22 @@ function formatAndValidateJson(errorElement) {
|
||||
body: input.textContent
|
||||
})
|
||||
.then(async (response) => {
|
||||
const promise = response.json();
|
||||
if (!response.ok) {
|
||||
throw Error(await response.text());
|
||||
throw Error(await promise);
|
||||
}
|
||||
|
||||
return response.text();
|
||||
return promise;
|
||||
})
|
||||
.then((data) => {
|
||||
input.innerText = data;
|
||||
input.innerText = data.data;
|
||||
processInfo.innerText = "";
|
||||
hljs.highlightElement(input);
|
||||
|
||||
const end = new Date();
|
||||
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
||||
})
|
||||
.catch((error) => {
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
@@ -34,7 +33,6 @@ function minimizeJson(errorElement) {
|
||||
const input = document.querySelector('#jsonBlock');
|
||||
const processInfo = document.getElementById(errorElement);
|
||||
|
||||
const start = new Date();
|
||||
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize"
|
||||
|
||||
fetch(address, {
|
||||
@@ -42,22 +40,33 @@ function minimizeJson(errorElement) {
|
||||
body: input.textContent
|
||||
})
|
||||
.then(async (response) => {
|
||||
const promise = response.json();
|
||||
if (!response.ok) {
|
||||
throw Error(await response.text());
|
||||
throw Error(await promise);
|
||||
}
|
||||
|
||||
return response.text();
|
||||
return promise;
|
||||
})
|
||||
.then((data) => {
|
||||
input.innerText = data;
|
||||
input.innerText = data.data;
|
||||
processInfo.innerText = "";
|
||||
hljs.highlightElement(input);
|
||||
|
||||
const end = new Date();
|
||||
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
||||
})
|
||||
.catch((error) => {
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user