<html>
<head>
<meta charset="utf-8"/>
<script>
  var currUrl = "$URL";
  var mainUrl = "{{ MAIN_URL }}";

  // check if toolbar exists, and hide it
  // note: kiwix insert is left here to be able to check 'window.block_path'
  window.addEventListener("load", function() {
    var toolbar = document.querySelector(".kiwix");
    if (toolbar) {
      toolbar.style.display = "none";
    }
  });

  if (window.parent === window.top) {
    // check if URL is from same domain as the main url
    var mainOrigin;

    try {
      mainOrigin = new URL(mainUrl).origin;
    } catch (e) {
      mainOrigin = mainUrl;
    }

    if (!currUrl.startsWith(mainOrigin)) {
      // check if kiwix-serve 'blocking' is enabled, show interstitional if it is
      if (window.block_path) {
        window.parent.location.href = encodeURI(block_path + "?source=" + currUrl);
      } else {
        // otherwise, just redirect
        window.parent.location.href = currUrl;
      }
    }
  }
</script>
</head>
<body>
<h3></h3>
<script>document.querySelector("h3").outerHTML = `<h3>{{_("Sorry, the url ${currUrl} is not found on this server")}}</h3>`;</script>
</body>
</html>
