function walkAllRoots(root, callback) { const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, null); let node = walker.currentNode; do { if (node.shadowRoot) { walkAllRoots(node.shadowRoot, callback); } } while (node = walker.nextNode()); callback(root); } function formatTextIn(root) { // الحالة الأولى: رقم مكتوب جنب "ر.س" بنفس السطر const textWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null); const textNodes = []; while (textWalker.nextNode()) { const node = textWalker.currentNode; if (/\b\d{4,}(\.\d+)?\s*ر\.?س/.test(node.nodeValue)) textNodes.push(node); } textNodes.forEach(node => { node.nodeValue = node.nodeValue.replace(/\b\d{4,}(\.\d+)?\b/g, m => Number(m).toLocaleString('en-US')); }); // الحالة الثانية: عنصر نصه بالكامل رقم بس (زي أيقونة العملة المنفصلة) const elements = root.querySelectorAll ? root.querySelectorAll('*') : []; elements.forEach(el => { if (el.children.length === 0) { const t = el.textContent.trim(); if (/^\d{4,}(\.\d+)?$/.test(t) && !el.dataset.numFormatted) { el.textContent = Number(t).toLocaleString('en-US'); el.dataset.numFormatted = 'true'; } } }); } function runAll() { walkAllRoots(document.body, formatTextIn); } document.addEventListener('DOMContentLoaded', runAll); const observer = new MutationObserver(() => { clearTimeout(window.__donationFormatTimer); window.__donationFormatTimer = setTimeout(runAll, 300); }); observer.observe(document.body, { childList: true, subtree: true, characterData: true });