Co-authored-by: Artur Kołecki <koleckiartur@icloud.com> Co-authored-by: Adam Bem <adam.bem@zoho.eu> Reviewed-on: R11/release11-tools-web#91
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
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"
|
|
|
|
fetch(address, {
|
|
method: 'POST',
|
|
body: input.textContent
|
|
})
|
|
.then(async (response) => {
|
|
if (!response.ok) {
|
|
throw Error(await response.text());
|
|
}
|
|
|
|
return response.text();
|
|
})
|
|
.then((data) => {
|
|
input.innerText = 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>";
|
|
})
|
|
.catch((error) => {
|
|
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
|
console.error('Error:', error);
|
|
});
|
|
}
|
|
|
|
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, {
|
|
method: 'POST',
|
|
body: input.textContent
|
|
})
|
|
.then(async (response) => {
|
|
if (!response.ok) {
|
|
throw Error(await response.text());
|
|
}
|
|
|
|
return response.text();
|
|
})
|
|
.then((data) => {
|
|
input.innerText = 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>";
|
|
})
|
|
.catch((error) => {
|
|
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
|
console.error('Error:', error);
|
|
});
|
|
} |