Skip to content

Commit 57f92d5

Browse files
committed
Bugfix remove uri encoding for txt generation
1 parent 1fec59f commit 57f92d5

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

.github/workflows/npm.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ jobs:
3434
with:
3535
name: build-artifact
3636
path: dist/*
37-
37+
3838
release:
3939
runs-on: ubuntu-latest
4040
needs: build
41-
41+
4242
steps:
4343
- name: Download Build Artifacts
4444
uses: actions/download-artifact@v5
@@ -61,15 +61,15 @@ jobs:
6161
Changes in this Release
6262
- First Change
6363
- Second Change
64-
draft: false
64+
draft: true
6565
prerelease: false
6666
- name: Upload bookmarklet
6767
id: upload-bookmarklet
6868
uses: actions/upload-release-asset@v1
6969
env:
7070
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7171
with:
72-
upload_url: ${{ steps.create_release.outputs.upload_url }}
72+
upload_url: ${{ steps.create_release.outputs.upload_url }}
7373
asset_path: ./bookmarklet.txt
7474
asset_name: bookmarklet.txt
7575
asset_content_type: text/plain

esbuild.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ const bookmarkletPlugin = options => ({
3333
if (!outputFiles) return;
3434

3535
for (const file of outputFiles) {
36-
const outputBuffer = file.contents;
3736
const utf8Decoder = new TextDecoder();
38-
const outputContent = utf8Decoder.decode(outputBuffer);
39-
file.contents = Buffer.concat([
40-
Buffer.from('javascript:', 'utf8'),
41-
Buffer.from(encodeURI(outputContent), 'utf8'),
42-
]);
37+
const outputContent = utf8Decoder.decode(file.contents);
38+
const compactCode = outputContent
39+
.replace(/\s+/g, ' ')
40+
.replace(/\s*([{}();,:])\s*/g, '$1');
41+
const bookmarklet = 'javascript:(function(){' + compactCode + '})();';
42+
file.contents = Buffer.from(bookmarklet, 'utf8');
4343
}
4444
});
4545
}
@@ -65,6 +65,9 @@ await esbuild.build({
6565
fs.writeFileSync(file.path, file.contents);
6666
bookmarkletCode = file.contents.toString();
6767
}
68+
const encodedBookmarklet = 'javascript:' + encodeURI(
69+
bookmarkletCode.replace(/^javascript:/, '')
70+
);
6871

6972
const htmlContent = `
7073
<!DOCTYPE html>
@@ -80,7 +83,7 @@ await esbuild.build({
8083
<h2>Bookmark Color Contrast Calculation Tool</h2>
8184
<ol>
8285
<li>Activate the bookmark toolbar in your browser (if not active yet). Most Browsers allow this by pressing Ctrl+Shift+B.</li>
83-
<li>Drag & drop the link <a href="${bookmarkletCode}">CAAT Contrast Checker</a> to the bookmark toolbar.</li>
86+
<li>Drag & drop the link <a href="${encodedBookmarklet}">CAAT Contrast Checker</a> to the bookmark toolbar.</li>
8487
<li>Activate the bookmarklet on any page.</li>
8588
<li>Use the pipette to transfer color values or enter them manually into the fields to determine the color contrast.</li>
8689
</ol>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "color-contrast-bookmarklet",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "color contrast checker bookmarklet",
55
"main": "dist/bookmarklet.js",
66
"scripts": {

0 commit comments

Comments
 (0)