(function () {
const BLUE = '#0050A0';
document.querySelectorAll('.js-installment, .js-installment-price').forEach(n => n.remove());
const style = document.createElement('style');
style.textContent = `
.cp-price:has(> .current-price[data-inst]) > .old-price,
.cp-cnt-bottom:has(.current-price[data-inst]) .cp-price-installment { display:none !important; }
.cp-price:has(> .current-price[data-inst]) { display:block !important; }
.cp-price:has(> .current-price[data-inst])::before {
content:"že od"; display:block; color:${BLUE};
font-size:15px; font-weight:400; line-height:1.2;
}
.cp-price > .current-price[data-inst] {
font-size:0 !important; color:${BLUE} !important; display:block; line-height:1.1;
}
.cp-price > .current-price[data-inst]::before {
content: attr(data-inst);
font-size:30px; font-weight:700; color:${BLUE}; vertical-align:baseline;
}
.cp-price > .current-price[data-inst]::after {
content:" € /mesec";
font-size:15px; font-weight:600; color:${BLUE}; vertical-align:baseline; white-space:pre;
}
`;
document.head.appendChild(style);
const AMOUNT = /\d{1,3}(?:\.\d{3})*,\d{2}|\d+,\d{2}/;
const TERM = /\b(mesec|mj|rat[ae]?|obrok\w*)\b/i; // SI: mesec | HR: rata
function readInstallment(orig) {
const card = orig.closest('article.cp') || orig.closest('.cp') ||
orig.closest('.cp-cnt-bottom') || orig.parentNode;
if (!card) return null;
let el = card.querySelector('.cp-price-installment');
if (!el) el = [...card.querySelectorAll('p, div, span')]
.find(n => TERM.test(n.textContent) && AMOUNT.test(n.textContent));
if (!el) return null;
const src = (el.querySelector('strong') || el).textContent.replace(/\u00A0/g, ' ').trim();
const m = src.match(AMOUNT);
return m ? m[0] : null;
}
function apply() {
document.querySelectorAll('.cp-price > .current-price').forEach(function (orig) {
const value = readInstallment(orig);
if (!value) return; // sticky: never clear what we set
if (orig.dataset.inst !== value) orig.dataset.inst = value;
});
}
let queued = false;
function schedule() {
if (queued) return;
queued = true;
requestAnimationFrame(function () { queued = false; apply(); });
}
apply();
new MutationObserver(schedule).observe(document.body, { childList: true, subtree: true, characterData: true });
window.addEventListener('load', schedule);
[300, 1000, 2500].forEach(t => setTimeout(schedule, t));
})();