Move bad log parsing to utils.js and add section headers

This commit is contained in:
2026-02-16 22:58:58 +01:00
parent 4962d398a1
commit 0d551ede53
7 changed files with 179 additions and 249 deletions

View File

@@ -8,31 +8,28 @@ function isLOTRMode(alertCountries) {
return alertCountries.includes('LOTR');
}
// =========================================================================
// Theme Application
// =========================================================================
function applyLOTRTheme(active) {
const body = document.body;
const lotrCSS = document.getElementById('lotr-css');
if (active) {
// Enable CSS first
if (lotrCSS) {
lotrCSS.disabled = false;
}
// Then add class to body
body.classList.add('lotr-mode');
isLOTRModeActive = true;
console.log('🎭 LOTR Mode Activated - Welcome to Middle-earth!');
} else {
// Remove class first
body.classList.remove('lotr-mode');
// Then disable CSS
if (lotrCSS) {
lotrCSS.disabled = true;
}
isLOTRModeActive = false;
console.log('🎭 LOTR Mode Deactivated');
}
// Force a reflow to ensure styles are applied
void body.offsetHeight;
}
@@ -46,51 +43,36 @@ function checkAndApplyLOTRTheme(alertCountries) {
function updateLOTRTerminology(active) {
if (active) {
// Update navigation title
const navTitle = document.querySelector('nav .text-xl');
if (navTitle) {
navTitle.textContent = 'Middle-earth Security';
}
// Update page title
const pageTitle = document.querySelector('title');
if (pageTitle) {
pageTitle.textContent = 'Middle-earth Security Realm';
}
// Update dashboard terminology
updateDashboardLOTRTerminology(true);
// Add decorative elements
addLOTRDecorations();
} else {
// Restore original text
const navTitle = document.querySelector('nav .text-xl');
if (navTitle) {
navTitle.textContent = 'Fail2ban UI';
}
const pageTitle = document.querySelector('title');
if (pageTitle && pageTitle.hasAttribute('data-i18n')) {
const i18nKey = pageTitle.getAttribute('data-i18n');
pageTitle.textContent = t(i18nKey, 'Fail2ban UI Dashboard');
}
// Restore dashboard terminology
updateDashboardLOTRTerminology(false);
// Remove decorative elements
removeLOTRDecorations();
}
}
function updateDashboardLOTRTerminology(active) {
// Update text elements that use data-i18n
const elements = document.querySelectorAll('[data-i18n]');
elements.forEach(el => {
const i18nKey = el.getAttribute('data-i18n');
if (active) {
// Check for LOTR-specific translations
if (i18nKey === 'dashboard.cards.total_banned') {
el.textContent = t('lotr.threats_banished', 'Threats Banished');
} else if (i18nKey === 'dashboard.table.banned_ips') {
@@ -101,14 +83,11 @@ function updateDashboardLOTRTerminology(active) {
el.textContent = t('lotr.realms_protected', 'Manage Realms');
}
} else {
// Restore original translations
if (i18nKey) {
el.textContent = t(i18nKey, el.textContent);
}
}
});
// Update "Unban" buttons
const unbanButtons = document.querySelectorAll('button, a');
unbanButtons.forEach(btn => {
if (btn.textContent && btn.textContent.includes('Unban')) {
@@ -122,26 +101,20 @@ function updateDashboardLOTRTerminology(active) {
}
function addLOTRDecorations() {
// Add decorative divider to settings section if not already present
const settingsSection = document.getElementById('settingsSection');
if (settingsSection && !settingsSection.querySelector('.lotr-divider')) {
const divider = document.createElement('div');
divider.className = 'lotr-divider';
divider.style.marginTop = '20px';
divider.style.marginBottom = '20px';
// Find the first child element (not text node) to insert before
const firstChild = Array.from(settingsSection.childNodes).find(
node => node.nodeType === Node.ELEMENT_NODE
);
if (firstChild && firstChild.parentNode === settingsSection) {
settingsSection.insertBefore(divider, firstChild);
} else if (settingsSection.firstChild) {
// Fallback: append if insertBefore fails
settingsSection.insertBefore(divider, settingsSection.firstChild);
} else {
// Last resort: append to end
settingsSection.appendChild(divider);
}
}
@@ -151,4 +124,3 @@ function removeLOTRDecorations() {
const dividers = document.querySelectorAll('.lotr-divider');
dividers.forEach(div => div.remove());
}