Create STATIC_PATHS export for astro, and make TransportManager

This commit is contained in:
wearrrrr 2024-03-07 15:56:43 -06:00
parent 3f560d81a0
commit 63b20d1388
11 changed files with 53 additions and 48 deletions

View file

@ -61,7 +61,7 @@ app.use(function (req, res, next) {
app.use("/", express.static("dist/client/")); app.use("/", express.static("dist/client/"));
app.get("/favicon.ico", (req, res) => { app.get("/favicon.ico", (req, res) => {
res.sendFile(path.join(process.cwd(), "dist/client/favicon.svg")); res.sendFile(path.join(process.cwd(), "dist/client/favicon.svg"));
}) });
app.get("/search", async (req, res) => { app.get("/search", async (req, res) => {
try { try {
const { query } = req.query; const { query } = req.query;

View file

@ -1,8 +1,8 @@
importScripts('/epoxy/index.js'); importScripts("/epoxy/index.js");
importScripts("/uv/uv.bundle.js"); importScripts("/uv/uv.bundle.js");
importScripts("/uv.config.js"); importScripts("/uv.config.js");
importScripts(__uv$config.sw); importScripts(__uv$config.sw);
const sw = new UVServiceWorker(); const sw = new UVServiceWorker();
self.addEventListener('fetch', (event) => event.respondWith(sw.fetch(event))); self.addEventListener("fetch", (event) => event.respondWith(sw.fetch(event)));

View file

@ -62,7 +62,7 @@
let iframe = newWindowDocument.createElement("iframe"); let iframe = newWindowDocument.createElement("iframe");
iframe.src = await getProxyURL(); iframe.src = await getProxyURL();
// Inject css into the iframe // Inject css into the iframe
let css = newWindowDocument.createElement("link") let css = newWindowDocument.createElement("link");
css.rel = "stylesheet"; css.rel = "stylesheet";
css.href = "/iframe.css"; css.href = "/iframe.css";
newWindowDocument.head.appendChild(css); newWindowDocument.head.appendChild(css);
@ -196,7 +196,9 @@
let proxiedFavicon = document.getElementById("proxied-favicon"); let proxiedFavicon = document.getElementById("proxied-favicon");
if (iframe) { if (iframe) {
if (iframe.contentDocument) { if (iframe.contentDocument) {
let favicon = iframe.contentDocument.querySelector("link[rel='icon']") || iframe.contentDocument.querySelector("link[rel*='icon']"); let favicon =
iframe.contentDocument.querySelector("link[rel='icon']") ||
iframe.contentDocument.querySelector("link[rel*='icon']");
if (favicon) { if (favicon) {
proxiedFavicon.src = favicon.href; proxiedFavicon.src = favicon.href;
} else { } else {
@ -206,10 +208,8 @@
} }
} }
setTimeout(() => updateProxiedFavicon(iframe), 400); setTimeout(() => updateProxiedFavicon(iframe), 400);
} }
function iframeURLChange(iframe, callback) { function iframeURLChange(iframe, callback) {
var lastDispatched = null; var lastDispatched = null;
@ -258,8 +258,7 @@
); );
if (newurl.length > 30) newurl = newurl.slice(0, 50) + "..."; if (newurl.length > 30) newurl = newurl.slice(0, 50) + "...";
urlText.innerText = newurl; urlText.innerText = newurl;
} } else urlText.innerText = window.__uv$config.decodeUrl(newURL.split(__uv$config.prefix)[1]);
else urlText.innerText = window.__uv$config.decodeUrl(newURL.split(__uv$config.prefix)[1]);
} }
} }
</script> </script>

View file

@ -35,7 +35,7 @@ const presetCloaks = [
{ {
cloakTitle: "YouTube", cloakTitle: "YouTube",
favicon: "https://www.youtube.com/s/desktop/0f128ffd/img/favicon_144x144.png", favicon: "https://www.youtube.com/s/desktop/0f128ffd/img/favicon_144x144.png",
} },
]; ];
--- ---

View file

@ -0,0 +1,25 @@
<script>
import { SetTransport, registerRemoteListener } from "@mercuryworkshop/bare-mux";
const wispURLDefault =
(location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
class TransportManager {
private transport = localStorage.getItem("alu__currentTransport") || "EpxMod.EpoxyClient";
constructor(transport?: string) {
if (transport) {
this.transport = transport;
}
}
getTransport() {
return this.transport;
}
setTransport(transport: string, wispURL = wispURLDefault) {
this.transport = transport;
SetTransport(transport, { wisp: wispURL });
}
}
const TransportMgr = new TransportManager();
registerRemoteListener(navigator.serviceWorker.controller);
TransportMgr.setTransport(TransportMgr.getTransport());
</script>

View file

@ -1,5 +1,7 @@
import { ui, defaultLang } from "./ui"; import { ui, defaultLang } from "./ui";
export const STATIC_PATHS = [{ params: { lang: "en" } }, { params: { lang: "jp" } }];
export function getLangFromUrl(url: URL) { export function getLangFromUrl(url: URL) {
// comma lol // comma lol
const [, lang] = url.pathname.split("/"); const [, lang] = url.pathname.split("/");

View file

@ -193,7 +193,8 @@ const { title, optionalPreloads } = Astro.props;
opacity: 0; opacity: 0;
gap: 10px; gap: 10px;
} }
.top-bar-right, .top-bar-left { .top-bar-right,
.top-bar-left {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;

View file

@ -3,12 +3,12 @@ import Layout from "../../layouts/Layout.astro";
import games from "../../json/games.json"; import games from "../../json/games.json";
import GameItem from "../../components/GameItem.astro"; import GameItem from "../../components/GameItem.astro";
import { getLangFromUrl, useTranslations } from "../../i18n/utils"; import { STATIC_PATHS, getLangFromUrl, useTranslations } from "../../i18n/utils";
const lang = getLangFromUrl(Astro.url); const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang); const t = useTranslations(lang);
export function getStaticPaths() { export function getStaticPaths() {
return [{ params: { lang: "en" } }, { params: { lang: "jp" } }]; return STATIC_PATHS;
} }
--- ---

View file

@ -1,43 +1,21 @@
--- ---
import Layout from "../../layouts/Layout.astro"; import Layout from "../../layouts/Layout.astro";
import { getLangFromUrl, useTranslations } from "../../i18n/utils"; import { STATIC_PATHS, getLangFromUrl, useTranslations } from "../../i18n/utils";
import Link from "../../components/Link.astro"; import Link from "../../components/Link.astro";
import TransportManager from "../../components/TransportManager.astro";
const lang = getLangFromUrl(Astro.url); const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang); const t = useTranslations(lang);
export function getStaticPaths() { export function getStaticPaths() {
return [{ params: { lang: "en" } }, { params: { lang: "jp" } }]; return STATIC_PATHS;
} }
--- ---
<Layout title={t("pages.home")}> <Layout title={t("pages.home")}>
<script src="/baremux/bare.cjs" is:inline></script> <script src="/baremux/bare.cjs" is:inline></script>
<script src="/epoxy/index.js" is:inline></script> <script src="/epoxy/index.js" is:inline></script>
<script> <TransportManager />
import { SetTransport, registerRemoteListener } from "@mercuryworkshop/bare-mux"
const wispURLDefault = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"
class TransportManager {
private transport = localStorage.getItem("alu__currentTransport") || "EpxMod.EpoxyClient";
constructor(transport?: string) {
if (transport) {
this.transport = transport;
}
}
getTransport() {
return this.transport;
}
setTransport(transport: string, wispURL = wispURLDefault) {
this.transport = transport;
SetTransport(transport, { wisp: wispURL });
}
}
const TransportMgr = new TransportManager();
registerRemoteListener(navigator.serviceWorker.controller)
TransportMgr.setTransport(TransportMgr.getTransport());
</script>
<div class="main-content"> <div class="main-content">
<h1 class="title-text">{t("menu.welcome")}</h1> <h1 class="title-text">{t("menu.welcome")}</h1>
<div class="form-wrapper"> <div class="form-wrapper">

View file

@ -2,12 +2,12 @@
import SettingsTablist from "../../components/SettingsTablist.astro"; import SettingsTablist from "../../components/SettingsTablist.astro";
import Layout from "../../layouts/Layout.astro"; import Layout from "../../layouts/Layout.astro";
import { getLangFromUrl, useTranslations } from "../../i18n/utils"; import { STATIC_PATHS, getLangFromUrl, useTranslations } from "../../i18n/utils";
const lang = getLangFromUrl(Astro.url); const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang); const t = useTranslations(lang);
export function getStaticPaths() { export function getStaticPaths() {
return [{ params: { lang: "en" } }, { params: { lang: "jp" } }]; return STATIC_PATHS;
} }
--- ---