forked from Vashistht/HackMit_PersonaLearn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
31 lines (28 loc) · 1.11 KB
/
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
28
29
30
31
async function handleSubmit() {
let queryOptions = { active: true, currentWindow: true };
let tabs = await chrome.tabs.query(queryOptions);
// Get comprehension points
chrome.tabs.sendMessage(tabs[0].id, { type: "get-comprehension-points" }, function (comprehensionPoints) {
// Get video id
chrome.tabs.get(tabs[0].id, (tab) => {
if (tab.url && tab.url.includes("youtube.com/watch")) {
const queryParameters = tab.url.split("?")[1];
const urlParameters = new URLSearchParams(queryParameters);
// Open new tab with comprehension information
const videoId = urlParameters.get("v");
const stringifiedData = JSON.stringify({
videoId,
comprehensionPoints,
});
const encodedData = encodeURIComponent(stringifiedData);
const url = `supplementary.html?data=${encodedData}`;
chrome.tabs.create({ url });
}
});
});
}
// Wait for the webpage to stop loading
onDocumentReady(() => {
const submitDataButton = document.getElementById("submit-data");
submitDataButton.addEventListener("click", handleSubmit);
});