Skip to content

Commit

Permalink
fix profanity filter
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-ang committed Oct 16, 2022
1 parent 18b03e8 commit 30368be
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 53 deletions.
97 changes: 50 additions & 47 deletions browser_index.js
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);
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
/>
</div>

<button class="btn btn-transcribe" id="transcribeBtn">
Transcribe!</button>
<button class="btn btn-transcribe" id="transcribeBtn">Transcribe!</button>
</div>
<script src="browser_index.js"></script>
</body>
</body>
</html>
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const assembly = axios.create({
// POST method route
app.post("/", async (req, res) => {
audioSource = req.body.link;
profanityFilter = req.body.profanityFilter;
profanityFilter = req.body.isFiltered;
ytdl(audioSource, { filter: "audioonly" })
.pipe(fs.createWriteStream(audioFile))
.on("finish", () => {
Expand Down
3 changes: 1 addition & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const assembly = axios.create({
// POST method route
app.post("/", async (req, res) => {
audioSource = req.body.link;
profanityFilter = req.body.profanityFilter;

profanityFilter = req.body.isFiltered;
ytdl(audioSource, { filter: "audioonly" })
.pipe(fs.createWriteStream(audioFile))
.on("finish", () => {
Expand Down

0 comments on commit 30368be

Please sign in to comment.