// Register service worker to control making site work offline window.addEventListener("load", () => { if ("serviceWorker" in navigator) { navigator.serviceWorker.register("https://www.ruvioli.com/service-worker.js"); } }); // Code to handle install prompt on desktop let deferredPrompt; const addBtn = document.querySelector('.addweb'); addBtn.style.display = 'none'; const conBtn = document.querySelector('.confirmaddweb'); conBtn.style.display = 'none'; const addBnr = document.querySelector('.smartbanner-button'); addBnr.style.display = 'none'; const conBnr = document.querySelector('.smartbanner'); conBnr.style.display = 'none'; window.addEventListener('beforeinstallprompt', (e) => { // Prevent Chrome 67 and earlier from automatically showing the prompt e.preventDefault(); // Stash the event so it can be triggered later. deferredPrompt = e; // Update UI to notify the user they can add to home screen addBtn.style.display = 'inline-block'; conBtn.style.display = 'none'; addBnr.style.display = 'inline-block'; conBnr.style.display = 'inline-block'; addBtn.addEventListener('click', () => { // hide our user interface that shows our A2HS button addBtn.style.display = 'none'; conBtn.style.display = 'block'; conBnr.style.display = 'none'; // Show the prompt deferredPrompt.prompt(); // Wait for the user to respond to the prompt deferredPrompt.userChoice.then((choiceResult) => { if (choiceResult.outcome === 'accepted') { console.log('User accepted the A2HS prompt'); } else { console.log('User dismissed the A2HS prompt'); } deferredPrompt = null; }); }); addBnr.addEventListener('click', () => { // hide our user interface that shows our A2HS button addBtn.style.display = 'none'; conBtn.style.display = 'block'; conBnr.style.display = 'none'; // Show the prompt deferredPrompt.prompt(); // Wait for the user to respond to the prompt deferredPrompt.userChoice.then((choiceResult) => { if (choiceResult.outcome === 'accepted') { console.log('User accepted the A2HS prompt'); } else { console.log('User dismissed the A2HS prompt'); } deferredPrompt = null; }); }); });