refactor: everything

This commit is contained in:
velzie 2024-07-27 11:41:02 -04:00
parent 78e666d314
commit 506d99f9b6
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
37 changed files with 925 additions and 885 deletions

View file

@ -1,37 +1,44 @@
// @ts-nocheck
import { ScramjetClient } from "./client";
import { encodeUrl, decodeUrl } from "./shared";
function createLocation() {
const loc = new URL(decodeUrl(location.href));
loc.assign = (url: string) => location.assign(encodeUrl(url));
loc.reload = () => location.reload();
loc.replace = (url: string) => location.replace(encodeUrl(url));
loc.toString = () => loc.href;
export function createLocationProxy(
client: ScramjetClient,
self: typeof globalThis
) {
function createLocation() {
const loc = new URL(client.url.href);
return loc;
}
loc.assign = (url: string) => self.location.assign(encodeUrl(url));
loc.reload = () => self.location.reload();
loc.replace = (url: string) => self.location.replace(encodeUrl(url));
loc.toString = () => loc.href;
export const locationProxy = new Proxy(
{
host: "",
},
{
get(target, prop) {
const loc = createLocation();
return loc[prop];
},
set(obj, prop, value) {
const loc = createLocation();
if (prop === "href") {
location.href = encodeUrl(value);
} else {
loc[prop] = value;
}
return true;
},
return loc;
}
);
return new Proxy(
{
host: "",
},
{
get(target, prop) {
const loc = createLocation();
return loc[prop];
},
set(obj, prop, value) {
const loc = createLocation();
if (prop === "href") {
self.location.href = encodeUrl(value);
} else {
loc[prop] = value;
}
return true;
},
}
);
}