From 23b2ba9928b1b17b03d7265940a8cc08a8df2a09 Mon Sep 17 00:00:00 2001 From: velzie Date: Sat, 12 Oct 2024 10:57:30 -0400 Subject: [PATCH] setAttributeNS --- src/client/dom/element.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index b207a73..2717144 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -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", { apply(ctx) {