setAttributeNS

This commit is contained in:
velzie 2024-10-12 10:57:30 -04:00
parent d2fb87b09f
commit 23b2ba9928

View file

@ -154,6 +154,29 @@ export default function (client: ScramjetClient, self: typeof window) {
} }
}, },
}); });
client.Proxy("Element.prototype.setAttributeNS", {
apply(ctx) {
const [namespace, name, value] = ctx.args;
const ruleList = htmlRules.find((rule) => {
const r = rule[name];
if (!r) return false;
if (r === "*") return true;
if (typeof r === "function") return false; // this can't happen but ts
return r.includes(ctx.this.tagName.toLowerCase());
});
if (ruleList) {
ctx.args[2] = ruleList.fn(value, client.meta, client.cookieStore);
nativeSetAttribute.call(
ctx.this,
`data-scramjet-${ctx.args[1]}`,
value
);
}
},
});
client.Proxy("Element.prototype.getAttribute", { client.Proxy("Element.prototype.getAttribute", {
apply(ctx) { apply(ctx) {