-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
43 lines (41 loc) · 1.24 KB
/
background.js
File metadata and controls
43 lines (41 loc) · 1.24 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
// background.js
chrome.action.onClicked.addListener((tab) => {
// Only act on YouTube video pages
if (!tab.url.includes("youtube.com/watch")) {
// Show notification for non-YouTube pages
chrome.notifications.create({
type: "basic",
title: "YouTube Transcript Extractor",
message:
"Please navigate to a YouTube video page to use the transcript feature.",
});
return;
}
// Send message to content script to toggle the dropdown
chrome.tabs.sendMessage(
tab.id,
{ action: "toggleTranscriptPanel" },
(response) => {
if (chrome.runtime.lastError) {
// Content script might not be loaded yet
console.error(
"Error sending message to content script:",
chrome.runtime.lastError.message
);
} else if (response) {
console.log("Content script responded:", response.status);
}
}
);
});
// Handle installation/update
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === "install") {
console.log("YouTube Transcript Extractor installed");
} else if (details.reason === "update") {
console.log(
"YouTube Transcript Extractor updated to version",
chrome.runtime.getManifest().version
);
}
});