-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,60 @@ | ||
const setLoadingState = () => { | ||
document.getElementById("transcribeBtn").innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: none; display: block; shape-rendering: auto;" width="50px" height="50px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"> <path fill="none" stroke="#5dbea3" stroke-width="8" stroke-dasharray="42.76482137044271 42.76482137044271" d="M24.3 30C11.4 30 5 43.3 5 50s6.4 20 19.3 20c19.3 0 32.1-40 51.4-40 C88.6 30 95 43.3 95 50s-6.4 20-19.3 20C56.4 70 43.6 30 24.3 30z" stroke-linecap="round"> <animate attributeName="stroke-dashoffset" repeatCount="indefinite" dur="1s" keyTimes="0;1" values="0;256.58892822265625"></animate> </path></svg>'; | ||
document.getElementById("transcribeBtn").classList.remove("btn-transcribe"); | ||
document.getElementById("transcribeBtn").classList.add("btn-transcribe-loading"); | ||
} | ||
document.getElementById("transcribeBtn").innerHTML = | ||
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: none; display: block; shape-rendering: auto;" width="50px" height="50px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"> <path fill="none" stroke="#5dbea3" stroke-width="8" stroke-dasharray="42.76482137044271 42.76482137044271" d="M24.3 30C11.4 30 5 43.3 5 50s6.4 20 19.3 20c19.3 0 32.1-40 51.4-40 C88.6 30 95 43.3 95 50s-6.4 20-19.3 20C56.4 70 43.6 30 24.3 30z" stroke-linecap="round"> <animate attributeName="stroke-dashoffset" repeatCount="indefinite" dur="1s" keyTimes="0;1" values="0;256.58892822265625"></animate> </path></svg>'; | ||
document.getElementById("transcribeBtn").classList.remove("btn-transcribe"); | ||
document | ||
.getElementById("transcribeBtn") | ||
.classList.add("btn-transcribe-loading"); | ||
}; | ||
|
||
const removeLoadingState = () => { | ||
document.getElementById("transcribeBtn").innerHTML = "Transcribe!" | ||
document.getElementById("transcribeBtn").classList.remove("btn-transcribe-loading"); | ||
document.getElementById("transcribeBtn").classList.add("btn-transcribe"); | ||
} | ||
document.getElementById("transcribeBtn").innerHTML = "Transcribe!"; | ||
document | ||
.getElementById("transcribeBtn") | ||
.classList.remove("btn-transcribe-loading"); | ||
document.getElementById("transcribeBtn").classList.add("btn-transcribe"); | ||
}; | ||
|
||
const getTranscription = () => { | ||
// Get the url of the currently open link. | ||
chrome.tabs.query( | ||
{ active: true, currentWindow: true }, | ||
async function (tabs) { | ||
setLoadingState(); | ||
|
||
let link = tabs[0].url; | ||
let isFiltered = document.getElementById("filterProfanities").checked; | ||
|
||
// Call the AssemblyAI api to transcribe video. | ||
try { | ||
let response = await fetch("http://localhost:3000", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
link: link, | ||
isFiltered: isFiltered, | ||
}), | ||
}); | ||
|
||
let data = await response.json(); | ||
|
||
// Download the text received as a text file. | ||
let blob = new Blob([data.text], {type: "text/plain"}); | ||
let url = URL.createObjectURL(blob); | ||
chrome.downloads.download({ | ||
url: url | ||
}) | ||
} catch (e) { | ||
console.log(e); | ||
|
||
} finally { | ||
removeLoadingState(); | ||
} | ||
} | ||
); | ||
// Get the url of the currently open link. | ||
chrome.tabs.query( | ||
{ active: true, currentWindow: true }, | ||
async function (tabs) { | ||
setLoadingState(); | ||
|
||
let link = tabs[0].url; | ||
let isFiltered = document.getElementById("filterProfanities").checked; | ||
|
||
// Call the AssemblyAI api to transcribe video. | ||
try { | ||
let response = await fetch("http://localhost:3000", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
link: link, | ||
isFiltered: isFiltered, | ||
}), | ||
}); | ||
|
||
let data = await response.json(); | ||
|
||
// Download the text received as a text file. | ||
let blob = new Blob([data.text], { type: "text/plain" }); | ||
let url = URL.createObjectURL(blob); | ||
chrome.downloads.download({ | ||
url: url, | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
} finally { | ||
removeLoadingState(); | ||
} | ||
} | ||
); | ||
}; | ||
|
||
|
||
document | ||
.getElementById("transcribeBtn") | ||
.addEventListener("click", getTranscription); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters