Skip to content

Commit

Permalink
Merge pull request #1 from vivek-nexus/v1.1.0
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
vivek-nexus authored Feb 10, 2024
2 parents b3c012d + c4bdc69 commit 02a655e
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 113 deletions.
72 changes: 66 additions & 6 deletions extension/background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
console.log(request.transcript)
chrome.storage.local.set({ transcript: request.transcript }, function () {
console.log("Saved transcript")
})
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.log(message.type)
if (message.type == "save_and_download") {
chrome.storage.local.set(
{
transcript: message.transcript,
meetingTitle: message.meetingTitle,
meetingStartTimeStamp: message.meetingStartTimeStamp
},
function () {
console.log("Saved transcript and meta data, downloading now if non empty")
if (message.transcript.length > 0)
downloadTranscript()
})
}
if (message.type == "download") {
downloadTranscript()
}
return true
})
})

function downloadTranscript() {
chrome.storage.local.get(["transcript", "meetingTitle", "meetingStartTimeStamp"], function (result) {
if (result.transcript) {
const fileName = result.meetingTitle && result.meetingStartTimeStamp ? `Transcripto/Transcript-${result.meetingTitle} at ${result.meetingStartTimeStamp}.txt` : `Transcripto/Transcript.txt`

// Create an array to store lines of the text file
const lines = [];

// Iterate through the transcript array and format each entry
result.transcript.forEach(entry => {
lines.push(entry.personName);
lines.push(entry.personTranscript);
lines.push(''); // Add an empty line between entries
});

lines.push("---")
lines.push("Transcript saved using Transcripto Chrome extension")

// Join the lines into a single string
const textContent = lines.join('\n');

// Create a Blob from the text content
const blob = new Blob([textContent], { type: 'text/plain' });

// Create a download
// Use Chrome Download API
chrome.downloads.download({
url: 'data:text/plain;base64,' + btoa(textContent),
filename: fileName,
conflictAction: 'uniquify' // Automatically rename the file if it already exists
}).then(() => {
console.log("Transcript downloaded to Transcripto directory")
}).catch((error) => {
console.log(error)
chrome.downloads.download({
url: 'data:text/plain;base64,' + btoa(textContent),
filename: "Transcripto/Transcript.txt",
conflictAction: 'uniquify' // Automatically rename the file if it already exists
})
console.log("Invalid file name. Transcript downloaded to Transcripto directory with simple file name.")
})
}
else
console.log("No transcript found")
})
}
146 changes: 78 additions & 68 deletions extension/content.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
let transcript = []
let personNameBuffer = "", transcriptTextBuffer = ""
let beforePersonName = "", beforeTranscriptText = ""
let meetingStartTimeStamp = new Date().toLocaleString()
const options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: true
};
let meetingStartTimeStamp = new Date().toLocaleString("default", options).replace(/[/:]/g, '-')
let meetingTitle = document.title
const extensionStatusJSON_bug = {
"status": 400,
"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>."
Expand All @@ -19,6 +28,11 @@ checkExtensionStatus().then(() => {
const captionsButton = contains(".material-icons-extended", "closed_caption_off")[0]

console.log("Meeting started")
setTimeout(() => {
// pick up meeting name after a delay
meetingTitle = updateMeetingTitle()
}, 5000);

chrome.storage.sync.get(["operationMode"], function (result) {
if (result.operationMode == "manual")
console.log("Manual mode selected, leaving transcript off")
Expand All @@ -36,7 +50,7 @@ checkExtensionStatus().then(() => {
observer.observe(targetNode, config)
chrome.storage.sync.get(["operationMode"], function (result) {
if (result.operationMode == "manual")
showNotification({ status: 400, message: "<strong>Transcripto is not running</strong> <br /> Turn on captions, if needed" })
showNotification({ status: 400, message: "<strong>Transcripto is not running</strong> <br /> Turn on captions using the CC icon, if needed" })
else
showNotification(extensionStatusJSON)
})
Expand All @@ -45,28 +59,27 @@ checkExtensionStatus().then(() => {
showNotification(extensionStatusJSON_bug)
}

window.addEventListener("beforeunload", beforeUnloadCallback)

contains(".google-material-icons", "call_end")[0].parentElement.addEventListener("click", () => {
if (personNameBuffer != "" || transcriptTextBuffer != "") {
transcript.push({
"personName": personNameBuffer,
"personTranscript": transcriptTextBuffer
})
chrome.storage.local.set({ transcript: transcript }, function () { })
}
window.removeEventListener("beforeunload", beforeUnloadCallback)
observer.disconnect();
console.log(`Transcript length ${transcript.length}`)
if (transcript.length > 0)
downloadTranscript()
})

window.addEventListener("beforeunload", function () {
transcript.push({
"personName": personNameBuffer,
"personTranscript": transcriptTextBuffer
})
chrome.runtime.sendMessage({ transcript: transcript }, function (response) {
console.log(response);
});
if ((personNameBuffer != "") && (transcriptTextBuffer != ""))
pushToTranscript()
chrome.storage.local.set(
{
transcript: transcript,
meetingTitle: meetingTitle,
meetingStartTimeStamp: meetingStartTimeStamp
},
function () {
console.log(`Transcript length ${transcript.length}`)
if (transcript.length > 0) {
chrome.runtime.sendMessage({ type: "download" }, function (response) {
console.log(response);
});
}
})
})
}
else {
Expand Down Expand Up @@ -160,41 +173,19 @@ const commonCSS = `background: rgb(255 255 255 / 25%);
box-shadow: rgba(0, 0, 0, 0.16) 0px 10px 36px 0px, rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;`;



function downloadTranscript() {
// Create an array to store lines of the text file
const lines = [];

// Iterate through the transcript array and format each entry
transcript.forEach(entry => {
lines.push(entry.personName);
lines.push(entry.personTranscript);
lines.push(''); // Add an empty line between entries
});

lines.push("---")
lines.push("Transcript generated using Transcripto Chrome extension")

// Join the lines into a single string
const textContent = lines.join('\n');

// Create a Blob from the text content
const blob = new Blob([textContent], { type: 'text/plain' });

// Create a download notification
let html = document.querySelector("html");
let obj = document.createElement("div");
let downloadLink = document.createElement("a")
downloadLink.setAttribute("id", "transcript-download-button")

obj.prepend(downloadLink)
if (html) {
html.append(obj)
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = `Transcript-${document.querySelector('div[data-meeting-title]') ? document.querySelector('div[data-meeting-title]').getAttribute("data-meeting-title") : document.title} ${meetingStartTimeStamp}.txt`;

downloadLink.click();
}
function beforeUnloadCallback() {
if ((personNameBuffer != "") && (transcriptTextBuffer != ""))
pushToTranscript()
chrome.runtime.sendMessage(
{
type: "save_and_download",
transcript: transcript,
meetingTitle: meetingTitle,
meetingStartTimeStamp: meetingStartTimeStamp,
},
function (response) {
console.log(response)
})
}

function transcriber(mutationsList, observer) {
Expand All @@ -215,11 +206,8 @@ function transcriber(mutationsList, observer) {
}
else {
if (personNameBuffer != currentPersonName) {
transcript.push({
"personName": personNameBuffer,
"personTranscript": transcriptTextBuffer
})
chrome.storage.local.set({ transcript: transcript }, function () { })
pushToTranscript()
overWriteChromeStorage()
beforeTranscriptText = currentTranscriptText
personNameBuffer = currentPersonName;
transcriptTextBuffer = currentTranscriptText;
Expand All @@ -233,23 +221,45 @@ function transcriber(mutationsList, observer) {
else {
console.log("No active transcript")
if ((personNameBuffer != "") && (transcriptTextBuffer != "")) {
transcript.push({
"personName": personNameBuffer,
"personTranscript": transcriptTextBuffer
})
chrome.storage.local.set({ transcript: transcript }, function () { })
pushToTranscript()
overWriteChromeStorage()
}
beforePersonName = ""
beforeTranscriptText = ""
personNameBuffer = ""
transcriptTextBuffer = ""
}
console.log(transcriptTextBuffer)
console.log(transcript)
// console.log(transcript)
})
}, 500);
}

function pushToTranscript() {
transcript.push({
"personName": personNameBuffer,
"personTranscript": transcriptTextBuffer
})
}

function overWriteChromeStorage() {
chrome.storage.local.set({
transcript: transcript,
meetingTitle: meetingTitle,
meetingStartTimeStamp: meetingStartTimeStamp
}, function () { })
}

function updateMeetingTitle() {
if (document.querySelector(".u6vdEc")) {
const title = document.querySelector(".u6vdEc").textContent
const invalidFilenameRegex = /[^\w\-_.() ]/g;
return title.replace(invalidFilenameRegex, '_')
}
else
return document.title
}

async function checkExtensionStatus() {
// Set default value as 200
chrome.storage.local.set({
Expand Down
5 changes: 3 additions & 2 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Transcripto",
"version": "1.0.0",
"version": "1.0.1",
"manifest_version": 3,
"description": "Simple Google Meet transcripts. Private and open source.",
"action": {
Expand Down Expand Up @@ -28,7 +28,8 @@
}
],
"permissions": [
"storage"
"storage",
"downloads"
],
"host_permissions": [
"https://meet.google.com/*"
Expand Down
45 changes: 8 additions & 37 deletions extension/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,20 @@ window.onload = function () {
manualModeRadio.checked = true
})

autoModeRadio.addEventListener('change', function () {
autoModeRadio.addEventListener("change", function () {
chrome.storage.sync.set({ operationMode: "auto" }, function () { })
})
manualModeRadio.addEventListener('change', function () {
manualModeRadio.addEventListener("change", function () {
chrome.storage.sync.set({ operationMode: "manual" }, function () { })
})
lastMeetingTranscriptLink.addEventListener("click", () => {
chrome.storage.local.get(["transcript"], function (result) {
if (!result.transcript)
if (result.transcript)
chrome.runtime.sendMessage({ type: "download" }, function (response) {
console.log(response);
});
else
alert("Couldn't find the last meeting's transcript. May be attend one?")
})
})
}

downloadTranscript()

function downloadTranscript() {
const lastMeetingTranscriptLink = document.querySelector("#last-meeting-transcript")
// Create an array to store lines of the text file
const lines = [];
let transcript = []

chrome.storage.local.get(["transcript"], function (result) {
if (result.transcript) {
transcript = result.transcript
// Iterate through the transcript array and format each entry
transcript.forEach(entry => {
lines.push(entry.personName);
lines.push(entry.personTranscript);
lines.push(''); // Add an empty line between entries
});

lines.push("---")
lines.push("Transcript generated using Transcripto Chrome extension")

// Join the lines into a single string
const textContent = lines.join('\n');

// Create a Blob from the text content
const blob = new Blob([textContent], { type: 'text/plain' });

lastMeetingTranscriptLink.href = URL.createObjectURL(blob);
lastMeetingTranscriptLink.download = `Transcript.txt`;
}
})
}
}

0 comments on commit 02a655e

Please sign in to comment.