Skip to content

Commit

Permalink
fix: migrate from data-scramjet to scramjet-data
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Nov 10, 2024
1 parent 21a112b commit 1b50dda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/client/dom/attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default function (client: ScramjetClient, self: typeof window) {
},
has(target, prop) {
if (typeof prop === "symbol") return Reflect.has(target, prop);
if (prop.startsWith("data-scramjet-")) return false;
if (map[prop]?.name?.startsWith("data-scramjet-")) return false;
if (prop.startsWith("scramjet-data-")) return false;
if (map[prop]?.name?.startsWith("scramjet-data-")) return false;

return Reflect.has(target, prop);
},
Expand Down
10 changes: 5 additions & 5 deletions src/client/dom/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function (client: ScramjetClient, self: typeof window) {

if (ruleList) {
ctx.args[1] = ruleList.fn(value, client.meta, client.cookieStore);
ctx.fn.call(ctx.this, `data-scramjet-${ctx.args[0]}`, value);
ctx.fn.call(ctx.this, `scramjet-data-${ctx.args[0]}`, value);
}
},
});
Expand All @@ -155,7 +155,7 @@ export default function (client: ScramjetClient, self: typeof window) {
ctx.args[2] = ruleList.fn(value, client.meta, client.cookieStore);
nativeSetAttribute.call(
ctx.this,
`data-scramjet-${ctx.args[1]}`,
`scramjet-data-${ctx.args[1]}`,
value
);
}
Expand All @@ -166,8 +166,8 @@ export default function (client: ScramjetClient, self: typeof window) {
apply(ctx) {
const [name] = ctx.args;

if (ctx.fn.call(ctx.this, `data-scramjet-${name}`)) {
ctx.return(ctx.fn.call(ctx.this, `data-scramjet-${name}`));
if (ctx.fn.call(ctx.this, `scramjet-data-${name}`)) {
ctx.return(ctx.fn.call(ctx.this, `scramjet-data-${name}`));
}
},
});
Expand All @@ -193,7 +193,7 @@ export default function (client: ScramjetClient, self: typeof window) {
if (ctx.this instanceof self.HTMLScriptElement) {
const scriptSource = client.natives[
"Element.prototype.getAttribute"
].call(ctx.this, "data-scramjet-script-source-src");
].call(ctx.this, "scramjet-data-script-source-src");

if (scriptSource) {
return atob(scriptSource);
Expand Down
14 changes: 7 additions & 7 deletions src/shared/rewriters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export function unrewriteHtml(html: string) {
function traverse(node: ChildNode) {
if ("attribs" in node) {
for (const key in node.attribs) {
if (key == "data-scramjet-script-source-src") {
if (key == "scramjet-data-script-source-src") {
if (node.children[0] && "data" in node.children[0])
node.children[0].data = atob(node.attribs[key]);
continue;
}

if (key.startsWith("data-scramjet-")) {
node.attribs["data-scramjet-".length] = node.attribs[key];
if (key.startsWith("scramjet-data-")) {
node.attribs["scramjet-data-".length] = node.attribs[key];
delete node.attribs[key];
}
}
Expand Down Expand Up @@ -216,14 +216,14 @@ function traverseParsedHtml(
else {
node.attribs[attr] = v;
}
node.attribs[`data-scramjet-${attr}`] = value;
node.attribs[`scramjet-data-${attr}`] = value;
}
}
}
}
for (const [attr, value] of Object.entries(node.attribs)) {
if (eventAttributes.includes(attr)) {
node.attribs[`data-scramjet-${attr}`] = attr;
node.attribs[`scramjet-data-${attr}`] = attr;
node.attribs[attr] = rewriteJs(
value as string,
`(inline ${attr} on element)`,
Expand All @@ -244,8 +244,8 @@ function traverseParsedHtml(
node.children[0] !== undefined
) {
let js = node.children[0].data;
// node.attribs[`data-scramjet-script-source-src`] = btoa(js);
node.attribs["data-scramjet-script-source-src"] = bytesToBase64(
// node.attribs[`scramjet-data-script-source-src`] = btoa(js);
node.attribs["scramjet-data-script-source-src"] = bytesToBase64(
new TextEncoder().encode(js)
);
const htmlcomment = /<!--[\s\S]*?-->/g;
Expand Down

0 comments on commit 1b50dda

Please sign in to comment.