Skip to content

Commit

Permalink
Fix attribute selector parsing (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
rviscomi authored Apr 17, 2024
1 parent 3968270 commit 8bee979
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions crx/capo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crx/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Capo: get your ﹤𝚑𝚎𝚊𝚍﹥ in order",
"description": "Visualize the optimal ordering of ﹤𝚑𝚎𝚊𝚍﹥ elements on any web page",
"version": "1.4.8",
"version": "1.4.9",
"permissions": [
"scripting",
"activeTab",
Expand Down
10 changes: 8 additions & 2 deletions docs/src/lib/capo.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ class $33f7359dc421be0c$export$8f8422ac5947a789 {
const attributes = selector.match(/\[([A-Za-z-]+)="([^"]+)"\]/g) || [];
// Set the attributes on the new element
attributes.forEach((attribute)=>{
const [key, value] = attribute.replace("[", "").replace("]", "").split("=");
element.setAttribute(key, value.slice(1, -1));
// Trim square brackets
attribute = attribute.slice(1, -1);
const delimeterPosition = attribute.indexOf("=");
// Everything before the =
const key = attribute.slice(0, delimeterPosition);
// Everything after the =, with quotes trimmed
const value = attribute.slice(delimeterPosition + 1).slice(1, -1);
element.setAttribute(key, value);
});
return element;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rviscomi/capo.js",
"version": "1.4.8",
"version": "1.4.9",
"description": "Get your ﹤𝚑𝚎𝚊𝚍﹥ in order",
"author": "Rick Viscomi",
"license": "Apache-2.0",
Expand Down
10 changes: 8 additions & 2 deletions snippet/capo.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ class $d410929ede0a2ee4$export$8f8422ac5947a789 {
const attributes = selector.match(/\[([A-Za-z-]+)="([^"]+)"\]/g) || [];
// Set the attributes on the new element
attributes.forEach((attribute)=>{
const [key, value] = attribute.replace("[", "").replace("]", "").split("=");
element.setAttribute(key, value.slice(1, -1));
// Trim square brackets
attribute = attribute.slice(1, -1);
const delimeterPosition = attribute.indexOf("=");
// Everything before the =
const key = attribute.slice(0, delimeterPosition);
// Everything after the =, with quotes trimmed
const value = attribute.slice(delimeterPosition + 1).slice(1, -1);
element.setAttribute(key, value);
});
return element;
}
Expand Down
13 changes: 8 additions & 5 deletions src/lib/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ export class IO {

// Set the attributes on the new element
attributes.forEach((attribute) => {
const [key, value] = attribute
.replace("[", "")
.replace("]", "")
.split("=");
element.setAttribute(key, value.slice(1, -1));
// Trim square brackets
attribute = attribute.slice(1, -1);
const delimeterPosition = attribute.indexOf("=");
// Everything before the =
const key = attribute.slice(0, delimeterPosition);
// Everything after the =, with quotes trimmed
const value = attribute.slice(delimeterPosition + 1).slice(1, -1);
element.setAttribute(key, value);
});

return element;
Expand Down

0 comments on commit 8bee979

Please sign in to comment.