king
2 天以前 047dbd742341e268ca772eda8d2ff0b6ba09cb44
public/index.html
@@ -8,6 +8,65 @@
    <link rel="shortcut icon" href="#">
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <title></title>
    <script>
      let _href = window.location.href.split('#')[0]
      let l_version = localStorage.getItem(_href + 'version')
      let _ctime = parseInt(new Date().getTime() / 1000)
      let _time = ''
      if (l_version) {
        let vers = l_version.split('-')
        l_version = vers[0]
        _time = +vers[1]
      }
      if (_time && _ctime - _time < 180) {
        let meta1 = document.createElement('meta')
        let meta2 = document.createElement('meta')
        let meta3 = document.createElement('meta')
        let meta4 = document.createElement('meta')
        meta1.content = '0'
        meta1.httpEquiv = 'Expires'
        meta2.content = 'no-cache'
        meta2.httpEquiv = 'Pragma'
        meta3.content = 'no-cache'
        meta3.httpEquiv = 'Cache-Control'
        meta4.content = 'no-cache'
        meta4.httpEquiv = 'Cache'
        document.getElementsByTagName('head')[0].appendChild(meta1)
        document.getElementsByTagName('head')[0].appendChild(meta2)
        document.getElementsByTagName('head')[0].appendChild(meta3)
        document.getElementsByTagName('head')[0].appendChild(meta4)
      } else {
        fetch('./manifest.json', { cache: 'no-cache'})
          .then(response => response.json())
          .then(res => {
            if (res && res.mk_version) {
              let version = res.mk_version
              let nocache = false
              if (l_version && version !== l_version) {
                nocache = true
                localStorage.setItem(_href + 'version', version + '-' + _ctime)
              } else if (!l_version) {
                localStorage.setItem(_href + 'version', version + '-' + (_ctime - 360))
              }
              if (nocache) {
                window.location.reload()
              }
            }
          })
      }
      window.mkInfo = function(value, color = '') {
        if (color) {
          console.info(value, color)
        } else {
          console.info(value)
        }
      }
    </script>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>