Advertisement
toorr2p

Untitled

Apr 17th, 2024
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2.     let e;
  3.  
  4.     function t() {
  5.         const e = document.querySelectorAll(".pwa-install-like-app");
  6.         e.length > 0 && e.forEach((e => {
  7.             e.remove()
  8.         }))
  9.     }
  10.     function instPwa() {
  11.         const e = document.querySelectorAll(".pwa-install-like-app");
  12.         e.length > 0 && e.forEach((e => {
  13.             e.click()
  14.         }))
  15.     }
  16.  
  17.     window.addEventListener("load", (() => {
  18.         if ("serviceWorker" in navigator) try {
  19.             navigator.serviceWorker.register("/local/assets/js/pwa-worker.js")
  20.         } catch (e) {
  21.             console.log("Service worker register fail")
  22.         }
  23.  
  24.         //instPwa();
  25.         $("#pwa-install").click();
  26.  
  27.     })), window.addEventListener("DOMContentLoaded", (() => {
  28.         let e = "browser tab";
  29.         window.matchMedia("(display-mode: standalone)").matches && (e = "standalone", t()), console.log("DISPLAY_MODE_LAUNCH:", e)
  30.     })), window.addEventListener("beforeinstallprompt", (t => {
  31.        
  32.         // TODO
  33.         alert("beforeinstallprompt");
  34.  
  35.         t.preventDefault(), e = t,
  36.             function() {
  37.                 const t = document.querySelectorAll(".pwa-install-like-app");
  38.                 t.length > 0 && t.forEach((t => {
  39.                     t.addEventListener("click", (async () => {
  40.                         //console.log(e.prompt());
  41.                         //console.log(e.userChoice);
  42.  
  43.                         e.prompt(), "accepted" === await e.userChoice && console.log("User accepted the A2HS prompt")
  44.                     }));
  45.                 }))
  46.             }(), console.log("beforeinstallprompt event was fired");
  47.  
  48.             //instPwa();
  49.  
  50.             $("#pwa-install").click();
  51.  
  52.     })), window.addEventListener("appinstalled", (() => {
  53.         t(), e = null, console.log("PWA was installed")
  54.     }));
  55.  
  56. })();
  57.  
  58.  
  59.  
  60. $(function(){
  61.     $("#pwa-install").click();
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement