-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
56 lines (47 loc) · 1.73 KB
/
popup.js
File metadata and controls
56 lines (47 loc) · 1.73 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
document.addEventListener("DOMContentLoaded", function () {
const showBtn = document.getElementById("showBtn");
const statusDiv = document.getElementById("status");
showBtn.addEventListener("click", async function () {
const totalCues = document.getElementById("totalCues").value;
const delay = document.getElementById("delay").value;
statusDiv.style.display = "block";
statusDiv.textContent = "Showing transcript...";
statusDiv.style.backgroundColor = "#e8f0fe";
try {
// Get the current active tab
const [tab] = await chrome.tabs.query({
active: true,
currentWindow: true,
});
// Execute the content script on the active tab
await chrome.scripting.executeScript({
target: { tabId: tab.id },
function: injectShowTranscript,
args: [parseInt(totalCues), parseInt(delay)],
});
statusDiv.textContent = "Transcript viewer activated!";
statusDiv.style.backgroundColor = "#d4edda";
// Close the popup after a short delay
setTimeout(() => window.close(), 1500);
} catch (error) {
console.error(error);
statusDiv.textContent = "Error: " + error.message;
statusDiv.style.backgroundColor = "#f8d7da";
}
});
// This function will be injected into the page
function injectShowTranscript(totalCues, delay) {
// If there's a global function to show transcript, use it
if (typeof findVideoAndShowTranscript === "function") {
findVideoAndShowTranscript(totalCues, delay);
return true;
}
// Otherwise, we'll trigger the content script via message
chrome.runtime.sendMessage({
action: "showTranscript",
totalCues: totalCues,
delay: delay,
});
return true;
}
});