mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-17 16:10:02 -04:00
actually prettier
This commit is contained in:
parent
fb53b44869
commit
56767f5b31
41 changed files with 1914 additions and 1919 deletions
|
@ -1,58 +1,58 @@
|
|||
import { URL } from "../../client/url";
|
||||
import { rewriteJs } from "./js";
|
||||
import { URL } from "../../client/url"
|
||||
import { rewriteJs } from "./js"
|
||||
|
||||
function canParseUrl(url: string, origin?: URL) {
|
||||
try {
|
||||
new URL(url, origin);
|
||||
try {
|
||||
new URL(url, origin)
|
||||
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// something is broken with this but i didn't debug it
|
||||
export function encodeUrl(url: string | URL, origin?: URL) {
|
||||
if (url instanceof URL) {
|
||||
return url.toString();
|
||||
}
|
||||
if (url instanceof URL) {
|
||||
return url.toString()
|
||||
}
|
||||
|
||||
if (!origin) {
|
||||
origin = new URL(
|
||||
self.$scramjet.config.codec.decode(
|
||||
location.href.slice(
|
||||
(location.origin + self.$scramjet.config.prefix).length,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (!origin) {
|
||||
origin = new URL(
|
||||
self.$scramjet.config.codec.decode(
|
||||
location.href.slice(
|
||||
(location.origin + self.$scramjet.config.prefix).length
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (url.startsWith("javascript:")) {
|
||||
return "javascript:" + rewriteJs(url.slice("javascript:".length));
|
||||
} else if (/^(#|mailto|about|data)/.test(url)) {
|
||||
return url;
|
||||
} else if (canParseUrl(url, origin)) {
|
||||
return (
|
||||
location.origin +
|
||||
self.$scramjet.config.prefix +
|
||||
self.$scramjet.config.codec.encode(new URL(url, origin).href)
|
||||
);
|
||||
}
|
||||
if (url.startsWith("javascript:")) {
|
||||
return "javascript:" + rewriteJs(url.slice("javascript:".length))
|
||||
} else if (/^(#|mailto|about|data)/.test(url)) {
|
||||
return url
|
||||
} else if (canParseUrl(url, origin)) {
|
||||
return (
|
||||
location.origin +
|
||||
self.$scramjet.config.prefix +
|
||||
self.$scramjet.config.codec.encode(new URL(url, origin).href)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// something is also broken with this but i didn't debug it
|
||||
export function decodeUrl(url: string | URL) {
|
||||
if (url instanceof URL) {
|
||||
return url.toString();
|
||||
}
|
||||
if (url instanceof URL) {
|
||||
return url.toString()
|
||||
}
|
||||
|
||||
if (/^(#|about|data|mailto|javascript)/.test(url)) {
|
||||
return url;
|
||||
} else if (canParseUrl(url)) {
|
||||
return self.$scramjet.config.codec.decode(
|
||||
url.slice((location.origin + self.$scramjet.config.prefix).length),
|
||||
);
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
if (/^(#|about|data|mailto|javascript)/.test(url)) {
|
||||
return url
|
||||
} else if (canParseUrl(url)) {
|
||||
return self.$scramjet.config.codec.decode(
|
||||
url.slice((location.origin + self.$scramjet.config.prefix).length)
|
||||
)
|
||||
} else {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue