Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

libai / footseen-large-website

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • footseen-large-website
  • mTest
  • index.js
Find file
BlameHistoryPermalink
  • libai's avatar
    测试 · 8d81f484
    libai committed 2 years ago
    8d81f484
index.js 2.92 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98


// Register service worker to control making site work offline

if ('serviceWorker' in navigator) {
  navigator.serviceWorker
    .register('/mobile/sw.js?V=2022120701')
    .then(() => { console.log('Service Worker Registered'); });
}

// Code to handle install prompt on desktop
var pwaT=null
let deferredPrompt;
const addBtn = document.querySelector('.add-button');
addBtn.style.display = 'none';

window.addEventListener('beforeinstallprompt', (e) => {
  var ua = window.navigator.userAgent.toLowerCase();
  if (/android/.test(ua)) {
    if(sessionStorage.type=="pwa")return;
    //安卓观看3个直播间
    if(sessionStorage.lookNum>=3){
      sessionStorage.lookNum=0
      setTimeout(() => {
        e.preventDefault();
        deferredPrompt = e;
        addBtn.style.display = 'block';
        addBtn.addEventListener('click', () => {
          addBtn.style.display = 'none';
          deferredPrompt.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;
          });
        });
      }, 3000);
  
    }
    //安卓首页停留20秒
    if(sessionStorage.time==undefined){
      if(sessionStorage.type=="pwa")return;
      setTimeout(function() {
        var bbb = location.href;
        if (bbb.indexOf("liveRoom") > -1){
          return;
        }
        sessionStorage.time=1
        e.preventDefault();
        deferredPrompt = e;
        addBtn.style.display = 'block';
        addBtn.addEventListener('click', () => {
          addBtn.style.display = 'none';
          deferredPrompt.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;
          });
        });
      }, 20000);
  
    }
    //安卓首次登陆
    pwaT=setInterval(function(){
      if(sessionStorage.type=="pwa")return;
      if(sessionStorage.oneLogin==1){
        clearInterval(pwaT)
        sessionStorage.oneLogin=0
        e.preventDefault();
        deferredPrompt = e;
        addBtn.style.display = 'block';
        addBtn.addEventListener('click', () => {
          addBtn.style.display = 'none';
          deferredPrompt.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;
          });
        });
      }
    },2000)
    setTimeout(function(){
      clearInterval(pwaT)
    },8000)
  }
});