reload_on_sentinel.js (Source)

(function pollSentinel(interval = 1000) {
    let lastContent = null;
    let intervalId = null;
    async function checkForChange() {
        try {
            const response = await fetch('/sentinel', { cache: 'no-store' });
            if (!response.ok) throw new Error('Fetch failed');
            const text = await response.text();
            if (lastContent === null) {
                const container = document.getElementById("git-status-container");
                container.innerHTML = text;
                lastContent = text;
                // console.log(text);
            } else if (text !== lastContent) {
                console.log('Sentinel changed — reloading...');
                location.reload();
            }
        } catch (err) {
            console.error('Error checking sentinel:', err);
            clearInterval(intervalId);
        }
    }
    intervalId = setInterval(checkForChange, interval);
})();