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.get("/favicon.ico", (req, res) => {
res.sendFile(path.join(process.cwd(), "dist/client/favicon.svg"));
})
});
app.get("/search", async (req, res) => {
try {
const { query } = req.query;

View file

@ -1,11 +1,11 @@
/* CSS for about:blank iframes */
body {
margin: 0;
margin: 0;
}
iframe {
width: 100%;
height: 100%;
border: none;
width: 100%;
height: 100%;
border: none;
}

View file

@ -1,8 +1,8 @@
importScripts('/epoxy/index.js');
importScripts("/epoxy/index.js");
importScripts("/uv/uv.bundle.js");
importScripts("/uv.config.js");
importScripts(__uv$config.sw);
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");
iframe.src = await getProxyURL();
// Inject css into the iframe
let css = newWindowDocument.createElement("link")
let css = newWindowDocument.createElement("link");
css.rel = "stylesheet";
css.href = "/iframe.css";
newWindowDocument.head.appendChild(css);
@ -195,8 +195,10 @@
function updateProxiedFavicon(iframe) {
let proxiedFavicon = document.getElementById("proxied-favicon");
if (iframe) {
if (iframe.contentDocument) {
let favicon = iframe.contentDocument.querySelector("link[rel='icon']") || iframe.contentDocument.querySelector("link[rel*='icon']");
if (iframe.contentDocument) {
let favicon =
iframe.contentDocument.querySelector("link[rel='icon']") ||
iframe.contentDocument.querySelector("link[rel*='icon']");
if (favicon) {
proxiedFavicon.src = favicon.href;
} else {
@ -206,10 +208,8 @@
}
}
setTimeout(() => updateProxiedFavicon(iframe), 400);
}
function iframeURLChange(iframe, callback) {
var lastDispatched = null;
@ -251,15 +251,14 @@
let urlText = document.getElementById("url-text");
if (urlText) {
if (preference === "rammerhead") {
let newurl = newURL.slice(
let newurl = newURL.slice(
newURL.indexOf("/" + getCookie("rammerhead-session")) +
getCookie("rammerhead-session").length +
2
);
if (newurl.length > 30) newurl = newurl.slice(0, 50) + "...";
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>

View file

@ -35,7 +35,7 @@ const presetCloaks = [
{
cloakTitle: "YouTube",
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";
export const STATIC_PATHS = [{ params: { lang: "en" } }, { params: { lang: "jp" } }];
export function getLangFromUrl(url: URL) {
// comma lol
const [, lang] = url.pathname.split("/");

View file

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

View file

@ -3,12 +3,12 @@ import Layout from "../../layouts/Layout.astro";
import games from "../../json/games.json";
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 t = useTranslations(lang);
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 { getLangFromUrl, useTranslations } from "../../i18n/utils";
import { STATIC_PATHS, getLangFromUrl, useTranslations } from "../../i18n/utils";
import Link from "../../components/Link.astro";
import TransportManager from "../../components/TransportManager.astro";
const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
export function getStaticPaths() {
return [{ params: { lang: "en" } }, { params: { lang: "jp" } }];
return STATIC_PATHS;
}
---
<Layout title={t("pages.home")}>
<script src="/baremux/bare.cjs" is:inline></script>
<script src="/epoxy/index.js" is:inline></script>
<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>
<TransportManager />
<div class="main-content">
<h1 class="title-text">{t("menu.welcome")}</h1>
<div class="form-wrapper">

View file

@ -2,12 +2,12 @@
import SettingsTablist from "../../components/SettingsTablist.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 t = useTranslations(lang);
export function getStaticPaths() {
return [{ params: { lang: "en" } }, { params: { lang: "jp" } }];
return STATIC_PATHS;
}
---