{% if gallery %}
{% set pathstatic = ".." %}
{% else %}
{% set pathstatic = "." %}
{% endif %}
<!doctype html>
<html class="staticrypt-html">
  <head>
    <meta charset="utf-8">
    <title>{% if gallery %}{{ gallery.title }} · {% endif %}{{ settings.title }}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- do not cache this page -->
    <meta http-equiv="cache-control" content="max-age=0"/>
    <meta http-equiv="cache-control" content="no-cache"/>
    <meta http-equiv="expires" content="0"/>
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/>
    <meta http-equiv="pragma" content="no-cache"/>
    <link type="text/css" rel="stylesheet" href="{{ pathstatic }}/static/css/encrypt.css"  media="screen,projection"/>

  </head>
  <body id="encrypt-body" class="staticrypt-body">
    {% if settings.settings.night_mode %}
    <div class="floating-menu">
      <label class="switch">
        <input type="checkbox" id="toggle-box-checkbox">
        <span class="slider round"></span>
      </label>
    </div>
    {% endif %}
    <script type="text/javascript" src="{{ pathstatic }}/static/js/jquery-2.1.4.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="{{ pathstatic }}/static/js/password.min.js" charset="utf-8"></script>
    <script>
var form = '{{ form }}';
var encryptedMsg = '{{ ciphertext }}';

if (sessionStorage.getItem("password")) {
  var passphrase = sessionStorage.getItem("password");
  var plainHTML = CryptoJS.AES.decrypt(encryptedMsg, passphrase).toString(CryptoJS.enc.Utf8);
  document.open();
  document.write(plainHTML);
  document.close();
} else {
  var plainHTML = CryptoJS.enc.Base64.parse(form).toString(CryptoJS.enc.Utf8);
  document.open();
  document.write(plainHTML);
  document.close();

  document.getElementById('staticrypt-form').addEventListener('submit', function(e) {
    e.preventDefault();

    var passphrase = document.getElementById('staticrypt-password').value;

    try{
      var plainHTML = CryptoJS.AES.decrypt(encryptedMsg, passphrase).toString(CryptoJS.enc.Utf8);
    }
    catch(err) {
      document.getElementById("error").innerHTML = "Wrong keyword entry.";
      return;
    }

    sessionStorage.setItem("password", passphrase);
    document.open();
    document.write(plainHTML);
    document.close();
  });
}

{% if settings.settings.night_mode %}
if (localStorage.getItem("mode_night") == "true") {
  $('body').addClass('night');
  document.getElementById("toggle-box-checkbox").checked = true;
}

$('#toggle-box-checkbox').on('change', function(){
  if(this.checked){
    $('body').addClass('night');
    localStorage.setItem("mode_night", true);
  }else{
    $('body').removeClass('night');
    localStorage.setItem("mode_night", false);
  }
});
{% endif %}

    </script>
  </body>
</html>
