(function () {
'use strict';
if (!('serviceWorker' in navigator) || !('Audio' in window)) return;
const base = new URL('../', document.currentScript.src);
const audio = new Audio(new URL('static/chime.ogg', base).href);
audio.preload = 'auto';
audio.volume = 0.7;
let unlocked = false;
function unlock() {
if (unlocked) return;
unlocked = true;
audio.play().then(() => {
audio.pause();
audio.currentTime = 0;
}).catch(() => {
unlocked = false;
});
}
['pointerdown', 'keydown', 'touchstart'].forEach((ev) =>
window.addEventListener(ev, unlock, { once: true, passive: true }),
);
function chime() {
try {
audio.currentTime = 0;
const p = audio.play();
if (p && typeof p.catch === 'function') p.catch(() => {});
} catch (_) {
}
}
navigator.serviceWorker.addEventListener('message', (event) => {
if (event.data && event.data.type === 'mobux-push') {
chime();
}
});
window.__mobuxChime = chime;
})();