2024-02-07 20:44:39 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
const checkbox = document.getElementById('nice_urls');
|
|
|
|
const out_span = document.getElementById('nicetest');
|
|
|
|
|
|
|
|
if(checkbox !== null && out_span !== null) {
|
|
|
|
checkbox.disabled = true;
|
|
|
|
out_span.innerHTML = '(testing...)';
|
2024-06-19 21:18:25 +00:00
|
|
|
const test_url = document.body.getAttribute('data-base-href') + "/nicetest";
|
|
|
|
console.log("NiceURL testing with", test_url);
|
2024-02-07 20:44:39 +00:00
|
|
|
|
2024-06-19 21:18:25 +00:00
|
|
|
fetch(test_url).then(response => {
|
2024-02-07 22:27:47 +00:00
|
|
|
if(!response.ok) {
|
2024-02-07 20:44:39 +00:00
|
|
|
checkbox.disabled = true;
|
2024-02-07 22:27:47 +00:00
|
|
|
out_span.innerHTML = '(http error)';
|
2024-06-19 21:18:25 +00:00
|
|
|
console.log("NiceURL test got HTTP error:", response.status, response.statusText);
|
2024-02-07 22:27:47 +00:00
|
|
|
} else {
|
|
|
|
response.text().then(text => {
|
|
|
|
if(text === 'ok') {
|
|
|
|
checkbox.disabled = false;
|
|
|
|
out_span.innerHTML = '(test passed)';
|
2024-06-19 21:18:25 +00:00
|
|
|
console.log("NiceURL test passed");
|
2024-02-07 22:27:47 +00:00
|
|
|
} else {
|
|
|
|
checkbox.disabled = true;
|
|
|
|
out_span.innerHTML = '(test failed)';
|
2024-06-19 21:18:25 +00:00
|
|
|
console.log("NiceURL test got wrong content:", text);
|
2024-02-07 22:27:47 +00:00
|
|
|
}
|
|
|
|
});
|
2024-02-07 20:44:39 +00:00
|
|
|
}
|
2024-06-19 21:18:25 +00:00
|
|
|
}).catch((e) => {
|
2024-02-07 20:44:39 +00:00
|
|
|
checkbox.disabled = true;
|
|
|
|
out_span.innerHTML = '(request failed)';
|
2024-06-19 21:18:25 +00:00
|
|
|
console.log("NiceURL test hit an exception:", e);
|
2024-02-07 20:44:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|