Skip to content

Commit ddce9d6

Browse files
authored
Update 404.html
1 parent da503bd commit ddce9d6

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

404.html

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,20 @@
4949
document.addEventListener("DOMContentLoaded", function() {
5050
var currentUrl = window.location.href;
5151
if (currentUrl.includes("/wiki/")) {
52-
// Check if the current URL already ends with '/en', to prevent infinite redirection
53-
if (!currentUrl.endsWith("/en")) {
54-
// Extract the base URL and the last segment
55-
var baseUrl = currentUrl.substring(0, currentUrl.lastIndexOf('/') + 1);
56-
var lastSegment = currentUrl.substring(currentUrl.lastIndexOf('/') + 1);
52+
var urlParts = currentUrl.split("/");
53+
var lastSegment = urlParts[urlParts.length - 1];
54+
55+
if (lastSegment !== 'en') {
56+
var newUrl = currentUrl.endsWith('/') ? currentUrl + 'en' : currentUrl + '/en';
5757

58-
// Check if the last segment is not 'en'
59-
if (lastSegment !== 'en') {
60-
var newUrl = baseUrl + 'en';
61-
62-
// Make an XMLHttpRequest to check the existence of the new URL
63-
var xhr = new XMLHttpRequest();
64-
xhr.open('HEAD', newUrl, true);
65-
xhr.onreadystatechange = function() {
66-
if (xhr.readyState === 4) {
67-
if (xhr.status === 404) {
68-
window.location.href = newUrl;
69-
} else {
70-
document.querySelector('.container').style.display = 'block';
71-
}
58+
fetch(newUrl, { method: 'HEAD' })
59+
.then(response => {
60+
if (!response.ok) {
61+
window.location.href = newUrl;
7262
}
73-
};
74-
xhr.send();
75-
} else {
76-
document.querySelector('.container').style.display = 'block';
77-
}
78-
} else {
79-
document.querySelector('.container').style.display = 'block';
63+
})
64+
.catch(error => console.error('Error checking URL:', error));
8065
}
81-
} else {
82-
document.querySelector('.container').style.display = 'block';
8366
}
8467
});
8568
</script>

0 commit comments

Comments
 (0)