mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
url.pathname and node baseurl
This commit is contained in:
parent
70e0a684ae
commit
48052ab3fe
1 changed files with 51 additions and 0 deletions
|
@ -31,6 +31,15 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
imagesrcset: [self.HTMLLinkElement],
|
||||
};
|
||||
|
||||
const urlinterfaces = [
|
||||
self.HTMLAnchorElement.prototype,
|
||||
self.HTMLAreaElement.prototype,
|
||||
];
|
||||
const originalhrefs = [
|
||||
nativeGetOwnPropertyDescriptor(self.HTMLAnchorElement.prototype, "href"),
|
||||
nativeGetOwnPropertyDescriptor(self.HTMLAreaElement.prototype, "href"),
|
||||
];
|
||||
|
||||
const attrs = Object.keys(attrObject);
|
||||
|
||||
for (const attr of attrs) {
|
||||
|
@ -67,6 +76,48 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
}
|
||||
}
|
||||
|
||||
// note that href is not here
|
||||
const urlprops = [
|
||||
"protocol",
|
||||
"hash",
|
||||
"host",
|
||||
"hostname",
|
||||
"origin",
|
||||
"pathname",
|
||||
"port",
|
||||
"search",
|
||||
];
|
||||
for (const prop of urlprops) {
|
||||
for (const i in urlinterfaces) {
|
||||
const target = urlinterfaces[i];
|
||||
const desc = originalhrefs[i];
|
||||
client.RawTrap(target, prop, {
|
||||
get(ctx) {
|
||||
let href = desc.get.call(ctx.this);
|
||||
if (!href) return href;
|
||||
|
||||
const url = new URL(decodeUrl(href));
|
||||
|
||||
return url[prop];
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
client.Trap("Node.prototype.baseURI", {
|
||||
get() {
|
||||
const base = self.document.querySelector("base");
|
||||
if (base) {
|
||||
return new URL(base.href, client.url).href;
|
||||
}
|
||||
|
||||
return client.url.href;
|
||||
},
|
||||
set() {
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("Element.prototype.setAttribute", {
|
||||
apply(ctx) {
|
||||
const [name, value] = ctx.args;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue