Skip to content

Commit 02a655e

Browse files
authored
Merge pull request #1 from vivek-nexus/v1.1.0
v1.1.0
2 parents b3c012d + c4bdc69 commit 02a655e

4 files changed

Lines changed: 155 additions & 113 deletions

File tree

extension/background.js

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,67 @@
1-
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
2-
console.log(request.transcript)
3-
chrome.storage.local.set({ transcript: request.transcript }, function () {
4-
console.log("Saved transcript")
5-
})
1+
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
2+
console.log(message.type)
3+
if (message.type == "save_and_download") {
4+
chrome.storage.local.set(
5+
{
6+
transcript: message.transcript,
7+
meetingTitle: message.meetingTitle,
8+
meetingStartTimeStamp: message.meetingStartTimeStamp
9+
},
10+
function () {
11+
console.log("Saved transcript and meta data, downloading now if non empty")
12+
if (message.transcript.length > 0)
13+
downloadTranscript()
14+
})
15+
}
16+
if (message.type == "download") {
17+
downloadTranscript()
18+
}
619
return true
7-
})
20+
})
21+
22+
function downloadTranscript() {
23+
chrome.storage.local.get(["transcript", "meetingTitle", "meetingStartTimeStamp"], function (result) {
24+
if (result.transcript) {
25+
const fileName = result.meetingTitle && result.meetingStartTimeStamp ? `Transcripto/Transcript-${result.meetingTitle} at ${result.meetingStartTimeStamp}.txt` : `Transcripto/Transcript.txt`
26+
27+
// Create an array to store lines of the text file
28+
const lines = [];
29+
30+
// Iterate through the transcript array and format each entry
31+
result.transcript.forEach(entry => {
32+
lines.push(entry.personName);
33+
lines.push(entry.personTranscript);
34+
lines.push(''); // Add an empty line between entries
35+
});
36+
37+
lines.push("---")
38+
lines.push("Transcript saved using Transcripto Chrome extension")
39+
40+
// Join the lines into a single string
41+
const textContent = lines.join('\n');
42+
43+
// Create a Blob from the text content
44+
const blob = new Blob([textContent], { type: 'text/plain' });
45+
46+
// Create a download
47+
// Use Chrome Download API
48+
chrome.downloads.download({
49+
url: 'data:text/plain;base64,' + btoa(textContent),
50+
filename: fileName,
51+
conflictAction: 'uniquify' // Automatically rename the file if it already exists
52+
}).then(() => {
53+
console.log("Transcript downloaded to Transcripto directory")
54+
}).catch((error) => {
55+
console.log(error)
56+
chrome.downloads.download({
57+
url: 'data:text/plain;base64,' + btoa(textContent),
58+
filename: "Transcripto/Transcript.txt",
59+
conflictAction: 'uniquify' // Automatically rename the file if it already exists
60+
})
61+
console.log("Invalid file name. Transcript downloaded to Transcripto directory with simple file name.")
62+
})
63+
}
64+
else
65+
console.log("No transcript found")
66+
})
67+
}

extension/content.js

Lines changed: 78 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
let transcript = []
22
let personNameBuffer = "", transcriptTextBuffer = ""
33
let beforePersonName = "", beforeTranscriptText = ""
4-
let meetingStartTimeStamp = new Date().toLocaleString()
4+
const options = {
5+
year: 'numeric',
6+
month: '2-digit',
7+
day: '2-digit',
8+
hour: '2-digit',
9+
minute: '2-digit',
10+
hour12: true
11+
};
12+
let meetingStartTimeStamp = new Date().toLocaleString("default", options).replace(/[/:]/g, '-')
13+
let meetingTitle = document.title
514
const extensionStatusJSON_bug = {
615
"status": 400,
716
"message": "<strong>Transcripto seems to have an error</strong> <br /> Please report it <a href='https://github.com/vivek-nexus/transcripto/issues' target='_blank'>here</a>."
@@ -19,6 +28,11 @@ checkExtensionStatus().then(() => {
1928
const captionsButton = contains(".material-icons-extended", "closed_caption_off")[0]
2029

2130
console.log("Meeting started")
31+
setTimeout(() => {
32+
// pick up meeting name after a delay
33+
meetingTitle = updateMeetingTitle()
34+
}, 5000);
35+
2236
chrome.storage.sync.get(["operationMode"], function (result) {
2337
if (result.operationMode == "manual")
2438
console.log("Manual mode selected, leaving transcript off")
@@ -36,7 +50,7 @@ checkExtensionStatus().then(() => {
3650
observer.observe(targetNode, config)
3751
chrome.storage.sync.get(["operationMode"], function (result) {
3852
if (result.operationMode == "manual")
39-
showNotification({ status: 400, message: "<strong>Transcripto is not running</strong> <br /> Turn on captions, if needed" })
53+
showNotification({ status: 400, message: "<strong>Transcripto is not running</strong> <br /> Turn on captions using the CC icon, if needed" })
4054
else
4155
showNotification(extensionStatusJSON)
4256
})
@@ -45,28 +59,27 @@ checkExtensionStatus().then(() => {
4559
showNotification(extensionStatusJSON_bug)
4660
}
4761

62+
window.addEventListener("beforeunload", beforeUnloadCallback)
63+
4864
contains(".google-material-icons", "call_end")[0].parentElement.addEventListener("click", () => {
49-
if (personNameBuffer != "" || transcriptTextBuffer != "") {
50-
transcript.push({
51-
"personName": personNameBuffer,
52-
"personTranscript": transcriptTextBuffer
53-
})
54-
chrome.storage.local.set({ transcript: transcript }, function () { })
55-
}
65+
window.removeEventListener("beforeunload", beforeUnloadCallback)
5666
observer.disconnect();
57-
console.log(`Transcript length ${transcript.length}`)
58-
if (transcript.length > 0)
59-
downloadTranscript()
60-
})
61-
62-
window.addEventListener("beforeunload", function () {
63-
transcript.push({
64-
"personName": personNameBuffer,
65-
"personTranscript": transcriptTextBuffer
66-
})
67-
chrome.runtime.sendMessage({ transcript: transcript }, function (response) {
68-
console.log(response);
69-
});
67+
if ((personNameBuffer != "") && (transcriptTextBuffer != ""))
68+
pushToTranscript()
69+
chrome.storage.local.set(
70+
{
71+
transcript: transcript,
72+
meetingTitle: meetingTitle,
73+
meetingStartTimeStamp: meetingStartTimeStamp
74+
},
75+
function () {
76+
console.log(`Transcript length ${transcript.length}`)
77+
if (transcript.length > 0) {
78+
chrome.runtime.sendMessage({ type: "download" }, function (response) {
79+
console.log(response);
80+
});
81+
}
82+
})
7083
})
7184
}
7285
else {
@@ -160,41 +173,19 @@ const commonCSS = `background: rgb(255 255 255 / 25%);
160173
box-shadow: rgba(0, 0, 0, 0.16) 0px 10px 36px 0px, rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;`;
161174

162175

163-
164-
function downloadTranscript() {
165-
// Create an array to store lines of the text file
166-
const lines = [];
167-
168-
// Iterate through the transcript array and format each entry
169-
transcript.forEach(entry => {
170-
lines.push(entry.personName);
171-
lines.push(entry.personTranscript);
172-
lines.push(''); // Add an empty line between entries
173-
});
174-
175-
lines.push("---")
176-
lines.push("Transcript generated using Transcripto Chrome extension")
177-
178-
// Join the lines into a single string
179-
const textContent = lines.join('\n');
180-
181-
// Create a Blob from the text content
182-
const blob = new Blob([textContent], { type: 'text/plain' });
183-
184-
// Create a download notification
185-
let html = document.querySelector("html");
186-
let obj = document.createElement("div");
187-
let downloadLink = document.createElement("a")
188-
downloadLink.setAttribute("id", "transcript-download-button")
189-
190-
obj.prepend(downloadLink)
191-
if (html) {
192-
html.append(obj)
193-
downloadLink.href = URL.createObjectURL(blob);
194-
downloadLink.download = `Transcript-${document.querySelector('div[data-meeting-title]') ? document.querySelector('div[data-meeting-title]').getAttribute("data-meeting-title") : document.title} ${meetingStartTimeStamp}.txt`;
195-
196-
downloadLink.click();
197-
}
176+
function beforeUnloadCallback() {
177+
if ((personNameBuffer != "") && (transcriptTextBuffer != ""))
178+
pushToTranscript()
179+
chrome.runtime.sendMessage(
180+
{
181+
type: "save_and_download",
182+
transcript: transcript,
183+
meetingTitle: meetingTitle,
184+
meetingStartTimeStamp: meetingStartTimeStamp,
185+
},
186+
function (response) {
187+
console.log(response)
188+
})
198189
}
199190

200191
function transcriber(mutationsList, observer) {
@@ -215,11 +206,8 @@ function transcriber(mutationsList, observer) {
215206
}
216207
else {
217208
if (personNameBuffer != currentPersonName) {
218-
transcript.push({
219-
"personName": personNameBuffer,
220-
"personTranscript": transcriptTextBuffer
221-
})
222-
chrome.storage.local.set({ transcript: transcript }, function () { })
209+
pushToTranscript()
210+
overWriteChromeStorage()
223211
beforeTranscriptText = currentTranscriptText
224212
personNameBuffer = currentPersonName;
225213
transcriptTextBuffer = currentTranscriptText;
@@ -233,23 +221,45 @@ function transcriber(mutationsList, observer) {
233221
else {
234222
console.log("No active transcript")
235223
if ((personNameBuffer != "") && (transcriptTextBuffer != "")) {
236-
transcript.push({
237-
"personName": personNameBuffer,
238-
"personTranscript": transcriptTextBuffer
239-
})
240-
chrome.storage.local.set({ transcript: transcript }, function () { })
224+
pushToTranscript()
225+
overWriteChromeStorage()
241226
}
242227
beforePersonName = ""
243228
beforeTranscriptText = ""
244229
personNameBuffer = ""
245230
transcriptTextBuffer = ""
246231
}
247232
console.log(transcriptTextBuffer)
248-
console.log(transcript)
233+
// console.log(transcript)
249234
})
250235
}, 500);
251236
}
252237

238+
function pushToTranscript() {
239+
transcript.push({
240+
"personName": personNameBuffer,
241+
"personTranscript": transcriptTextBuffer
242+
})
243+
}
244+
245+
function overWriteChromeStorage() {
246+
chrome.storage.local.set({
247+
transcript: transcript,
248+
meetingTitle: meetingTitle,
249+
meetingStartTimeStamp: meetingStartTimeStamp
250+
}, function () { })
251+
}
252+
253+
function updateMeetingTitle() {
254+
if (document.querySelector(".u6vdEc")) {
255+
const title = document.querySelector(".u6vdEc").textContent
256+
const invalidFilenameRegex = /[^\w\-_.() ]/g;
257+
return title.replace(invalidFilenameRegex, '_')
258+
}
259+
else
260+
return document.title
261+
}
262+
253263
async function checkExtensionStatus() {
254264
// Set default value as 200
255265
chrome.storage.local.set({

extension/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Transcripto",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"manifest_version": 3,
55
"description": "Simple Google Meet transcripts. Private and open source.",
66
"action": {
@@ -28,7 +28,8 @@
2828
}
2929
],
3030
"permissions": [
31-
"storage"
31+
"storage",
32+
"downloads"
3233
],
3334
"host_permissions": [
3435
"https://meet.google.com/*"

extension/popup.js

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,20 @@ window.onload = function () {
1212
manualModeRadio.checked = true
1313
})
1414

15-
autoModeRadio.addEventListener('change', function () {
15+
autoModeRadio.addEventListener("change", function () {
1616
chrome.storage.sync.set({ operationMode: "auto" }, function () { })
1717
})
18-
manualModeRadio.addEventListener('change', function () {
18+
manualModeRadio.addEventListener("change", function () {
1919
chrome.storage.sync.set({ operationMode: "manual" }, function () { })
2020
})
2121
lastMeetingTranscriptLink.addEventListener("click", () => {
2222
chrome.storage.local.get(["transcript"], function (result) {
23-
if (!result.transcript)
23+
if (result.transcript)
24+
chrome.runtime.sendMessage({ type: "download" }, function (response) {
25+
console.log(response);
26+
});
27+
else
2428
alert("Couldn't find the last meeting's transcript. May be attend one?")
2529
})
2630
})
27-
}
28-
29-
downloadTranscript()
30-
31-
function downloadTranscript() {
32-
const lastMeetingTranscriptLink = document.querySelector("#last-meeting-transcript")
33-
// Create an array to store lines of the text file
34-
const lines = [];
35-
let transcript = []
36-
37-
chrome.storage.local.get(["transcript"], function (result) {
38-
if (result.transcript) {
39-
transcript = result.transcript
40-
// Iterate through the transcript array and format each entry
41-
transcript.forEach(entry => {
42-
lines.push(entry.personName);
43-
lines.push(entry.personTranscript);
44-
lines.push(''); // Add an empty line between entries
45-
});
46-
47-
lines.push("---")
48-
lines.push("Transcript generated using Transcripto Chrome extension")
49-
50-
// Join the lines into a single string
51-
const textContent = lines.join('\n');
52-
53-
// Create a Blob from the text content
54-
const blob = new Blob([textContent], { type: 'text/plain' });
55-
56-
lastMeetingTranscriptLink.href = URL.createObjectURL(blob);
57-
lastMeetingTranscriptLink.download = `Transcript.txt`;
58-
}
59-
})
60-
}
31+
}

0 commit comments

Comments
 (0)