mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 23:10:02 -04:00
start client api
This commit is contained in:
parent
9f2ad08edf
commit
7433e0a7ff
7 changed files with 131 additions and 10 deletions
|
@ -0,0 +1,30 @@
|
|||
function urlLocation() {
|
||||
let loc = new URL(self.__scramjet$bundle.rewriters.url.decodeUrl(location.href));
|
||||
loc.assign = (url: string) => location.assign(self.__scramjet$bundle.rewriters.url.encodeUrl(url));
|
||||
loc.reload = () => location.reload();
|
||||
loc.replace = (url: string) => location.replace(self.__scramjet$bundle.rewriters.url.encodeUrl(url));
|
||||
loc.toString = () => loc.href;
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
export function locationProxy() {
|
||||
const loc = urlLocation();
|
||||
|
||||
return new Proxy(Location, {
|
||||
get(target, prop) {
|
||||
return loc[prop];
|
||||
},
|
||||
set(obj, prop, value) {
|
||||
if (prop === "href") {
|
||||
location.href = self.__scramjet$bundle.rewriters.url.encodeUrl(value);
|
||||
} else {
|
||||
loc[prop] = value;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
window.__location = locationProxy();
|
Loading…
Add table
Add a link
Reference in a new issue