(function () {
// --- POMOĆNE FUNKCIJE ---
function fixLang() {
if (document.documentElement.lang !== 'hr') {
document.documentElement.lang = 'hr';
}
}
function fixHeadings() {
// Samo duplikati h1 -> h2
document.querySelectorAll('h1').forEach((h1, i) => {
if (i > 0) {
const h2 = document.createElement('h2');
h2.innerHTML = h1.innerHTML;
h1.parentNode.replaceChild(h2, h1);
}
});
// h3 -> h2
document.querySelectorAll('h3.module-name, h3.entry-title, .xg_module_h3, h3.fn').forEach(el => {
const h2 = document.createElement('h2');
h2.innerHTML = el.innerHTML;
h2.className = el.className;
h2.style.fontSize = 'inherit';
h2.style.fontWeight = 'bold';
el.parentNode.replaceChild(h2, el);
});
// h4 -> h3
document.querySelectorAll('h4.comments-title').forEach(el => {
const h3 = document.createElement('h3');
h3.innerHTML = el.innerHTML;
h3.className = el.className;
h3.style.fontSize = 'inherit';
h3.style.fontWeight = 'inherit';
el.parentNode.replaceChild(h3, el);
});
}
function fixPhoneNumbers() {
const phoneRegex = /(? {
block.innerHTML = block.innerHTML.replace(phoneRegex, (match) => {
let clean = match.replace(/\s+/g, '');
let dial = clean.startsWith('09') ? '+385' + clean.substring(1) : clean;
return `
${match}`;
});
block.classList.add('phone-fixed-final');
});
}
function fixDialogs() {
document.querySelectorAll('.ui-dialog').forEach(dialog => {
dialog.style.backgroundColor = '#ffffff';
dialog.style.color = '#000000';
dialog.querySelectorAll('label, span').forEach(el => el.style.color = '#000000');
});
}
function fixSelectLabels() {
document.querySelectorAll('select.subnav.condensed').forEach((sel, idx) => {
if (!sel.id) sel.id = 'fixed-select-' + idx;
if (!document.querySelector(`label[for="${sel.id}"]`)) {
const lb = document.createElement('label');
lb.setAttribute('for', sel.id);
lb.innerText = 'Navigacijski izbornik';
lb.style.cssText = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0;';
sel.parentNode.insertBefore(lb, sel);
}
});
}
function fixImages() {
document.querySelectorAll('img:not([alt])').forEach(img => {
const title = img.getAttribute('title');
const figcaption = img.closest('figure')?.querySelector('figcaption')?.innerText;
img.alt = title || figcaption || '';
});
}
function fixMain() {
if (document.querySelector('[role="main"]')) return; // već postoji, ne diraj
const selectors = ['#ning-body', '.xg_layout', '#xg_body', '.column-center'];
for (let selector of selectors) {
const el = document.querySelector(selector);
if (el) {
el.setAttribute('role', 'main');
if (!el.id) el.id = 'main-content-area';
break;
}
}
}
function fixSearch() {
document.querySelectorAll('input.globalsearch, #search_input').forEach(input => {
if (!input.hasAttribute('aria-label')) input.setAttribute('aria-label', 'Pretraživanje');
});
}
function fixButtons() {
document.querySelectorAll('button, .xn_button').forEach(btn => {
if (!btn.innerText.trim() && !btn.hasAttribute('aria-label')) {
btn.setAttribute('aria-label', 'Opcije');
}
});
}
function fixLinkSelectors() {
document.querySelectorAll('.linkSelector').forEach(el => {
if (!el.hasAttribute('aria-label')) {
el.setAttribute('aria-label', 'Navigacijski izbornik');
}
});
}
// --- GLAVNA FUNKCIJA ---
function runFixes() {
fixLang();
fixHeadings();
fixPhoneNumbers();
fixDialogs();
fixSelectLabels();
fixImages();
fixMain();
fixSearch();
fixButtons();
fixLinkSelectors();
}
// --- POKRETANJE ---
runFixes(); // odmah pri učitavanju
// MutationObserver umjesto setInterval
const observer = new MutationObserver(runFixes);
observer.observe(document.body, {
childList: true,
subtree: true
});
})();