-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPopup.js
More file actions
29 lines (29 loc) · 1.26 KB
/
Popup.js
File metadata and controls
29 lines (29 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
This script is responsible for the functionality of the Youtube Transcript Summarizer Chrome extension's popup.
When the "Summarize" button is clicked, it sends a request to the Flask server to fetch the summarized transcript
of the currently active YouTube video. The maximum length of the summary can be specified.
The summary is then displayed in the popup.
*/
const btn = document.getElementById("summarize");
btn.addEventListener("click", function() {
btn.disabled = true;
btn.innerHTML = "Summarizing...";
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var url = tabs[0].url;
var maxLength = document.getElementById("max_length").value || 150;
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://127.0.0.1:5000/summary?url=" + url + "&max_length=" + maxLength, true);
xhr.onload = function() {
var text = xhr.responseText;
const p = document.getElementById("output");
if (xhr.status === 404) {
p.innerHTML = "No subtitles available for this video";
} else {
p.innerHTML = text;
}
btn.disabled = false;
btn.innerHTML = "Summarize";
}
xhr.send();
});
});