/* Цены в рупиях + конвертер по наведению/тапу. Курсы зашиты, внешних запросов нет. Подключается сборкой build.py. */ (() => { /* Источник: курсы ЦБ РФ на 18.11.2026 (RUB за единицу: USD 82,4529, EUR 90,8136, AUD 55,5897, SGD 63,9964, IDR 45,1797 за 10 000). База: 1 USD. */ const IDR_PER_USD = 18250; const CUR = { RUB: { r: 82.4529, sym: '₽', name: 'Рубли' }, USD: { r: 1, sym: '$', name: 'Доллары США' }, EUR: { r: 0.90794, sym: '€', name: 'Евро' }, AUD: { r: 1.48324, sym: 'A$', name: 'Австралийские доллары' }, SGD: { r: 1.28842, sym: 'S$', name: 'Сингапурские доллары' }, }; const store = { get(k) { try { return localStorage.getItem(k); } catch (_) { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch (_) {} }, }; const nb = ' '; const grp = n => String(Math.round(n)).replace(/\B(?=(\d{3})+(?!\d))/g, nb); const dec = (x, d) => x.toFixed(d).replace(/\.?0+$/, '').replace('.', ','); /* Рупии: красивые округления. ≥1 млрд: «Rp 1,31 млрд»; иначе «Rp 105 млн» / «Rp 1,1 млн» */ function idrParts(usd) { const v = usd * IDR_PER_USD; if (v >= 1e9) return { n: dec(Math.round(v / 1e7) / 100, 2), u: 'млрд' }; if (v >= 1e7) return { n: String(Math.round(v / 1e6)), u: 'млн' }; return { n: dec(Math.round(v / 1e5) / 10, 1), u: 'млн' }; } /* Доллары в скобках: от 10 000 округляем до $500, меньше — до $10 */ const usdR = u => (u >= 10000 ? Math.round(u / 500) * 500 : Math.round(u / 10) * 10); const usdS = u => '$' + grp(usdR(u)); const usdTxt = (usd, pair) => '(' + (pair != null ? usdS(pair) + '\u2013' + usdS(usd).slice(1) : usdS(usd)) + ')'; const idr = (usd, mode, pair) => { const p = idrParts(usd); if (mode === 'start') return 'Rp' + nb + p.n; if (mode === 'end') return p.n + nb + p.u + ' ' + usdTxt(usd, pair); return 'Rp' + nb + p.n + nb + p.u + ' ' + usdTxt(usd); }; window.pranaMoney = usd => idr(usd, ''); /* Валюта посетителя: сначала сохранённый выбор, потом язык и часовой пояс */ const RU_TZ = /^(Europe\/(Moscow|Kaliningrad|Samara|Volgograd|Kirov|Saratov|Ulyanovsk|Astrakhan|Minsk)|Asia\/(Yekaterinburg|Omsk|Novosibirsk|Krasnoyarsk|Irkutsk|Yakutsk|Vladivostok|Magadan|Kamchatka|Sakhalin|Chita|Barnaul|Tomsk|Novokuznetsk|Anadyr|Srednekolymsk|Khandyga|Ust-Nera))$/; function detect() { let tz = '', lang = ''; try { tz = Intl.DateTimeFormat().resolvedOptions().timeZone || ''; } catch (_) {} lang = ((navigator.languages && navigator.languages[0]) || navigator.language || '').toLowerCase(); if (lang.startsWith('ru') || RU_TZ.test(tz)) return 'RUB'; if (/^(de|fr|it|es|nl|pt|fi|el|sk|sl|lt|lv|et)\b/.test(lang) || (tz.startsWith('Europe/') && tz !== 'Europe/London')) return 'EUR'; if (tz.startsWith('Australia/')) return 'AUD'; if (tz === 'Asia/Singapore') return 'SGD'; return 'USD'; } let cur = store.get('prana-fx'); if (!cur || !CUR[cur]) cur = detect(); const WORD = { RUB: 'в рублях', USD: 'в долларах', EUR: 'в евро', AUD: 'в австралийских долларах', SGD: 'в сингапурских долларах' }; function altParts(usd) { const c = CUR[cur], v = usd * c.r; if (cur === 'RUB') { if (v >= 1e8) return { n: String(Math.round(v / 1e6)), u: 'млн' + nb + '₽' }; if (v >= 1e6) return { n: dec(Math.round(v / 1e5) / 10, 1), u: 'млн' + nb + '₽' }; return { n: grp(Math.round(v / 100) * 100), u: '₽' }; } const step = v >= 20000 ? 1000 : v >= 1000 ? 10 : 1; return { n: grp(Math.round(v / step) * step), u: '', pre: c.sym }; } const altText = list => { const ps = list.map(altParts); if (cur === 'RUB') return '≈' + nb + (ps.length === 2 && ps[0].u === ps[1].u ? ps[0].n + '–' + ps[1].n + nb + ps[0].u : ps.map(p => p.n + nb + p.u).join('–')); return '≈' + nb + ps[0].pre + ps.map(p => p.n).join('–'); }; /* Что считаем ценой: контейнер (ячейка, блок цены) или одиночное число в тексте */ const GROUPS = ['.pr', '.pr-line', 'td', 'dd', '.ph-meta b', '#cPriceOut']; const SKIP = '.marquee, .mmenu, button, .qz-opts, .tabs'; const topEl = el => !(el.parentElement && el.parentElement.closest('[data-usd]')); const usdOf = h => h.id === 'cPriceOut' ? [+document.getElementById('cPrice').value] : h._marks.map(m => +m.dataset.usd); const hosts = []; function paintIDR() { document.querySelectorAll('[data-usd]').forEach(el => { const s = el.hasAttribute('data-s'), end = el.hasAttribute('data-ns'); const start = s && !end && el.parentElement && el.parentElement.querySelector('[data-ns]'); let pair = null; if (s && end) { const st = [...el.parentElement.querySelectorAll('[data-s]')].find(x => !x.hasAttribute('data-ns') && !x.contains(el)); if (st) pair = +st.dataset.usd; } const txt = s ? idr(+el.dataset.usd, end ? 'end' : start ? 'start' : '', pair) : idr(+el.dataset.usd, ''); const i = txt.indexOf(' ('); if (i > 0) { el.textContent = txt.slice(0, i); const u = document.createElement('span'); u.className = 'usd'; u.textContent = txt.slice(i); el.appendChild(u); } else el.textContent = txt; }); } function build() { const used = new Set(); const add = (host, marks) => { if (host.closest(SKIP)) return; host.querySelectorAll('[data-usd]').forEach(x => used.add(x)); marks.forEach(m => { used.add(m); m.classList.add('fx-u'); }); host._marks = marks; host.classList.add('fx-h'); if (!host.closest('a')) { host.tabIndex = 0; host.setAttribute('role', 'button'); host.setAttribute('aria-label', 'Цена в другой валюте'); } hosts.push(host); }; GROUPS.forEach(sel => document.querySelectorAll(sel).forEach(g => { if (g.classList.contains('fx-h')) return; if (g.id === 'cPriceOut') return add(g, [g]); const ms = [...g.querySelectorAll('[data-usd]')].filter(topEl); if (!ms.length || ms.length > 2 || ms.some(m => used.has(m))) return; if (g.querySelector('.fx-h')) return; add(g, ms); })); document.querySelectorAll('[data-usd]').forEach(el => { if (topEl(el) && !used.has(el)) add(el, [el]); }); } /* Подсказка над ценой */ const hover = matchMedia('(hover:hover) and (pointer:fine)').matches; const tip = document.createElement('div'); tip.className = 'fx-tip'; tip.setAttribute('role', 'dialog'); tip.hidden = true; tip.innerHTML = '

Курс ЦБ РФ на 13.11.2026, ориентировочный. Цена по договору указывается в рупиях.

'; let openHost = null, closeT = 0; const vEl = () => tip.querySelector('.fx-v'); function place(host) { const rs = host._marks.map(m => m.getBoundingClientRect()); const r = { l: Math.min(...rs.map(x => x.left)), r: Math.max(...rs.map(x => x.right)), t: Math.min(...rs.map(x => x.top)), b: Math.max(...rs.map(x => x.bottom)) }; const vw = document.documentElement.clientWidth, w = tip.offsetWidth, h = tip.offsetHeight; let x = (r.l + r.r) / 2 - w / 2; x = Math.max(8, Math.min(x, vw - w - 8)); let below = r.t - h - 12 < 8, y = below ? r.b + 12 : r.t - h - 12; tip.style.left = x + 'px'; tip.style.top = y + 'px'; tip.classList.toggle('below', below); tip.querySelector('.fx-ar').style.left = Math.max(14, Math.min((r.l + r.r) / 2 - x, w - 14)) + 'px'; } function fill() { vEl().textContent = altText(usdOf(openHost)); const ch = tip.querySelector('.fx-chips'); ch.innerHTML = Object.keys(CUR).map(c => ``).join(''); } function show(host) { clearTimeout(closeT); if (openHost !== host && window.pranaTrack) pranaTrack('FxOpen', {}); if (openHost) openHost.classList.remove('fx-on'); openHost = host; host.classList.add('fx-on'); tip.hidden = false; tip.classList.remove('in'); tip.querySelector('.fx-chips').hidden = true; tip.querySelector('.fx-more').setAttribute('aria-expanded', 'false'); fill(); place(host); requestAnimationFrame(() => tip.classList.add('in')); hideHint(true); } function hide() { if (!openHost) return; openHost.classList.remove('fx-on'); openHost = null; tip.hidden = true; tip.classList.remove('in'); } const later = () => { clearTimeout(closeT); closeT = setTimeout(hide, 160); }; tip.addEventListener('mouseenter', () => clearTimeout(closeT)); tip.addEventListener('mouseleave', () => { if (hover) later(); }); tip.querySelector('.fx-more').addEventListener('click', e => { const ch = tip.querySelector('.fx-chips'); ch.hidden = !ch.hidden; e.currentTarget.setAttribute('aria-expanded', String(!ch.hidden)); place(openHost); }); tip.addEventListener('click', e => { const b = e.target.closest('.fx-chips button'); if (!b) return; cur = b.dataset.c; store.set('prana-fx', cur); fill(); vEl().classList.remove('swap'); void vEl().offsetWidth; vEl().classList.add('swap'); tip.querySelector('.fx-chips').hidden = true; tip.querySelector('.fx-more').setAttribute('aria-expanded', 'false'); place(openHost); }); /* Плашка для первого знакомства */ let hint = null, hintHost = null; function hintText() { return (hover ? 'Наведите на цену' : 'Нажмите на цену') + ', покажем ' + WORD[cur] + '.'; } function placeHint() { if (!hint || hint.hidden || !hintHost) return; const r = hintHost.getBoundingClientRect(), vw = document.documentElement.clientWidth, vh = innerHeight; if (r.bottom < 60 || r.top > vh - 60) { hint.classList.remove('in'); return; } hint.classList.add('in'); const w = hint.offsetWidth, h = hint.offsetHeight, cx = (r.left + r.right) / 2; let x = Math.max(8, Math.min(cx - w / 2, vw - w - 8)); const below = r.top - h - 14 < 60; hint.style.left = x + 'px'; hint.style.top = (below ? r.bottom + 14 : r.top - h - 14) + 'px'; hint.classList.toggle('below', below); hint.querySelector('.fx-ar').style.left = Math.max(16, Math.min(cx - x, w - 16)) + 'px'; } function hideHint(save) { if (!hint) return; if (save) store.set('prana-fx-hint', '1'); hint.hidden = true; if (hintHost) hintHost.classList.remove('fx-pulse'); hintHost = null; hint = null; window.removeEventListener('scroll', placeHint); window.removeEventListener('resize', placeHint); } function startHint() { if (store.get('prana-fx-hint')) return; const el = document.createElement('div'); el.className = 'fx-hint'; el.setAttribute('role', 'status'); el.innerHTML = '

Цены в рупиях. Так требует закон Индонезии.

'; el.querySelector('.fx-ht').textContent = hintText(); el.hidden = true; document.body.appendChild(el); el.querySelector('button').addEventListener('click', () => hideHint(true)); const io = new IntersectionObserver(es => { const e = es.find(x => x.isIntersecting); if (!e || hint) return; io.disconnect(); hint = el; hintHost = e.target; el.hidden = false; hintHost.classList.add('fx-pulse'); placeHint(); window.addEventListener('scroll', placeHint, { passive: true }); window.addEventListener('resize', placeHint); }, { rootMargin: '-80px 0px -80px 0px', threshold: 1 }); hosts.filter(h => !h.closest('a, .offer')).forEach(h => io.observe(h)); } const init = () => { paintIDR(); build(); document.body.appendChild(tip); hosts.forEach(h => { if (hover) { h.addEventListener('mouseenter', () => show(h)); h.addEventListener('mouseleave', later); h.addEventListener('focus', () => show(h)); h.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); openHost === h ? hide() : show(h); } }); } else { h.addEventListener('click', e => { e.preventDefault(); e.stopPropagation(); openHost === h ? hide() : show(h); }); } }); document.addEventListener('pointerdown', e => { if (openHost && !tip.contains(e.target) && !openHost.contains(e.target)) hide(); }); document.addEventListener('keydown', e => { if (e.key === 'Escape') hide(); }); window.addEventListener('scroll', () => { if (openHost && !hover) hide(); else if (openHost) place(openHost); }, { passive: true }); window.addEventListener('resize', () => { if (openHost) place(openHost); }); setTimeout(startHint, 900); window.dispatchEvent(new Event('prana:currency')); }; if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init(); window.pranaCur = () => cur; })();