<!DOCTYPE html>
<html manifest="webxoss.appcache">
<head>
  <title>Migrate WEBXOSS data</title>
</head>
<body>
  <iframe id="iframe" style="display: none;" src="about:blank"></iframe>
  <script>
(function () {
  if (location.protocol === 'https:') {
    return
  }
  // migrated by the old way, buggy in safari
  if (localStorage.getItem('migrated') === 'true') {
    if (!window.safari) {
      return location.replace(location.href.replace(/^http:/, 'https:'))
    }
  }
  // migrated by the new way
  if (localStorage.getItem('migrated') === '2') {
    return location.replace(location.href.replace(/^http:/, 'https:'))
  }
  function getStorage() {
    var storage = {}
    for (var i = 0; i < localStorage.length; i++) {
      var key = localStorage.key(i)
      storage[key] = localStorage.getItem(key)
    }
    return storage
  }
  var storage = getStorage()
  localStorage.setItem('migrated', 2)
  // pass localStorage via url hash, which is ignored in network request
  var url = location.href.replace(/^http:/, 'https:') + '#storage=' + JSON.stringify(storage)
  return location.replace(url)
})()
  </script>
</body>
</html>