-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
41 lines (37 loc) · 1.2 KB
/
background.js
File metadata and controls
41 lines (37 loc) · 1.2 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
// Background script for Video Transcript Viewer extension
console.log("Video Transcript Viewer background script loaded");
// Listen for installation
chrome.runtime.onInstalled.addListener(() => {
console.log("Video Transcript Viewer extension installed");
});
// Context menu functionality
chrome.contextMenus.create({
id: "showTranscript",
title: "Show Video Transcript",
contexts: ["page", "video"],
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "showTranscript") {
chrome.tabs.sendMessage(tab.id, {
action: "showTranscript",
totalCues: 500, // Default to a higher number for context menu
delay: 200,
});
}
});
// Listen for messages from the content script or popup
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "showTranscript") {
// Forward the message to the active tab
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]) {
chrome.tabs.sendMessage(tabs[0].id, {
action: "showTranscript",
totalCues: request.totalCues || 500,
delay: request.delay || 200,
});
}
});
return true;
}
});