/* drop this once in , or include from header.php */ (function () { if (!('Notification' in window)) return; if (Notification.permission === 'default') { Notification.requestPermission(); } if (Notification.permission !== 'granted') return; let last = Date.now(); const basePath = document.querySelector('base').href; setInterval(() => { fetch(basePath + 'public/api/notif_fetch.php?since=' + last) .then(r => r.json()) .then(list => { last = Date.now(); list.forEach(row => { const amt = Number(row.amount).toFixed(2); new Notification( `Payment ${row.status}`, { body: `${amt} ${row.user_currency} – ${row.user_email}` } ); }); }) .catch(console.error); }, 15000); })();