From b52e12ec3ad0bd1fddef4e643870c0a3da007248 Mon Sep 17 00:00:00 2001 From: Yung-Hsiang Hu Date: Wed, 21 Feb 2024 12:03:06 +0800 Subject: [PATCH 1/3] [fix] Add unicode support Since `btoa` interprets the code points of its input string as byte values, calling `btoa` on a string will cause a "Character Out Of Range" exception if a character's code point exceeds 0xff. This patch replaces the `btoa` with the recommended solution from MDN, which encodes the Unicode string to the single-byte representation before passing it to `btoa`. Reference: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem --- extension/background.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extension/background.js b/extension/background.js index 67b886e..df90989 100644 --- a/extension/background.js +++ b/extension/background.js @@ -19,6 +19,12 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { return true }) +function unicodeToBase64(text){ + const bytes = new TextEncoder().encode(text) + const binString = String.fromCodePoint(...bytes); + return btoa(binString); +} + function downloadTranscript() { chrome.storage.local.get(["transcript", "meetingTitle", "meetingStartTimeStamp"], function (result) { if (result.transcript) { @@ -47,7 +53,7 @@ function downloadTranscript() { // Create a download // Use Chrome Download API chrome.downloads.download({ - url: 'data:text/plain;base64,' + btoa(textContent), + url: 'data:text/plain;base64,' + unicodeToBase64(textContent), filename: fileName, conflictAction: 'uniquify' // Automatically rename the file if it already exists }).then(() => { @@ -65,4 +71,4 @@ function downloadTranscript() { else console.log("No transcript found") }) -} \ No newline at end of file +} From ebd5d0ae25dc4f4eebc6d0f9e3b8ac366643846e Mon Sep 17 00:00:00 2001 From: Vivek G Date: Wed, 21 Feb 2024 10:32:40 +0530 Subject: [PATCH 2/3] Copy encoding fix for invalid file name download and refactor code --- extension/background.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/extension/background.js b/extension/background.js index df90989..c3780d6 100644 --- a/extension/background.js +++ b/extension/background.js @@ -19,12 +19,6 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { return true }) -function unicodeToBase64(text){ - const bytes = new TextEncoder().encode(text) - const binString = String.fromCodePoint(...bytes); - return btoa(binString); -} - function downloadTranscript() { chrome.storage.local.get(["transcript", "meetingTitle", "meetingStartTimeStamp"], function (result) { if (result.transcript) { @@ -53,7 +47,7 @@ function downloadTranscript() { // Create a download // Use Chrome Download API chrome.downloads.download({ - url: 'data:text/plain;base64,' + unicodeToBase64(textContent), + url: 'data:text/plain;base64,' + encodeUnicodeString(textContent), filename: fileName, conflictAction: 'uniquify' // Automatically rename the file if it already exists }).then(() => { @@ -61,7 +55,7 @@ function downloadTranscript() { }).catch((error) => { console.log(error) chrome.downloads.download({ - url: 'data:text/plain;base64,' + btoa(textContent), + url: 'data:text/plain;base64,' + encodeUnicodeString(textContent), filename: "TranscripTonic/Transcript.txt", conflictAction: 'uniquify' // Automatically rename the file if it already exists }) @@ -72,3 +66,10 @@ function downloadTranscript() { console.log("No transcript found") }) } + +// Thanks to @ifTNT(https://github.com/vivek-nexus/transcriptonic/pull/4) +function encodeUnicodeString(text) { + const utf8Bytes = new TextEncoder().encode(text) + const binaryString = String.fromCodePoint(...utf8Bytes); + return btoa(binaryString); +} From c56716ada757cc5281025bc5e2d6c180409d8443 Mon Sep 17 00:00:00 2001 From: Vivek G Date: Wed, 21 Feb 2024 10:36:03 +0530 Subject: [PATCH 3/3] Bump version --- extension/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/manifest.json b/extension/manifest.json index ef0369c..7358b7b 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,6 +1,6 @@ { "name": "TranscripTonic", - "version": "2.0.0", + "version": "2.0.1", "manifest_version": 3, "description": "Simple Google Meet transcripts. Private and open source.", "action": {