Create STATIC_PATHS export for astro, and make TransportManager
This commit is contained in:
parent
3f560d81a0
commit
63b20d1388
11 changed files with 53 additions and 48 deletions
2
index.js
2
index.js
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
/* CSS for about:blank iframes */
|
/* CSS for about:blank iframes */
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
iframe {
|
iframe {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)));
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
@ -195,8 +195,10 @@
|
||||||
function updateProxiedFavicon(iframe) {
|
function updateProxiedFavicon(iframe) {
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -251,15 +251,14 @@
|
||||||
let urlText = document.getElementById("url-text");
|
let urlText = document.getElementById("url-text");
|
||||||
if (urlText) {
|
if (urlText) {
|
||||||
if (preference === "rammerhead") {
|
if (preference === "rammerhead") {
|
||||||
let newurl = newURL.slice(
|
let newurl = newURL.slice(
|
||||||
newURL.indexOf("/" + getCookie("rammerhead-session")) +
|
newURL.indexOf("/" + getCookie("rammerhead-session")) +
|
||||||
getCookie("rammerhead-session").length +
|
getCookie("rammerhead-session").length +
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
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>
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
25
src/components/TransportManager.astro
Normal file
25
src/components/TransportManager.astro
Normal 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>
|
||||||
|
|
@ -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("/");
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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">
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue