Add loading to iFrame

This commit is contained in:
MotorTruck1221 2024-10-17 04:03:18 -06:00
parent d6ff02f284
commit a2e67033c8
No known key found for this signature in database
GPG key ID: 08F417E2B8B61EA4
2 changed files with 32 additions and 1 deletions

View file

@ -37,6 +37,8 @@ import { VERSION } from "astro:env/client";
<iframe
id="neb-iframe"
class="hidden z-100 w-full h-full absolute top-0 bottom-0 bg-primary"
src="/loading"
preload="lazy"
></iframe>
<div id="version" class="flex flex-row w-full absolute bottom-4 pr-4 pl-4 text-text-color h-6 justify-between roboto">
<p> Version: { VERSION } </p>
@ -102,8 +104,10 @@ import { VERSION } from "astro:env/client";
const input = document.getElementById("nebula-input") as HTMLInputElement;
const iframe = document.getElementById("neb-iframe") as HTMLIFrameElement;
const omnibox = document.getElementById("omnibox") as HTMLDivElement;
const copyright = document.getElementById("version") as HTMLDivElement;
input?.addEventListener("keypress", async function (event: any) {
if (event.key === "Enter") {
if (event.key === "Enter") {
copyright.classList.add("hidden");
if (localStorage.getItem(Settings.ProxySettings.proxy) === "automatic") {
const key = SupportedSites[input?.value];
switch(key) {

27
src/pages/loading.astro Normal file
View file

@ -0,0 +1,27 @@
---
import Loading from "@components/Loading.astro";
import Layout from "@layouts/Layout.astro";
---
<Layout title="Loading page..." noHeader="true">
<Loading />
</Layout>
<script>
import { pageLoad } from "@utils/events";
import { navigate } from "astro:transitions/client";
function isComingFromIframe() {
try {
return window.self !== window.top;
}
catch (e) {
return true;
}
}
pageLoad(() => {
const isIframe = isComingFromIframe();
if (!isIframe) {
console.log("Assuming request isn't coming from iFrame. Redirecting...");
navigate('/');
}
});
</script>