-
Notifications
You must be signed in to change notification settings - Fork 13
/
popup.js
27 lines (23 loc) · 1014 Bytes
/
popup.js
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
SummaryButton = document.getElementById('Summarize');
SummaryButton.onclick = e => {
e.preventDefault();
chrome.tabs.query({active: true, currentWindow: true}, tabs => {
let url = tabs[0].url.split("&")[0];
var expression = /https?:\/\/(www\.)?youtube.com\/watch\b([v?=].*)/g
var regex = new RegExp(expression);
if(!url.match(regex))
return;
chrome.tabs.sendMessage(tabs[0].id, {action:"Load Summary"});
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState == 4){
if(xhr.status == 200){
chrome.tabs.sendMessage(tabs[0].id, {"video_url": url, action:"print Summary", summary: JSON.parse(xhr.response)});
}
}
}
// the api
xhr.open("GET", 'https://2450-2401-4900-1f3c-4f48-fe17-4f79-96a2-8bf5.ngrok.io/api/summarize?youtube_url=' + url, true);
xhr.send();
});
};