-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
34 lines (30 loc) · 1019 Bytes
/
background.js
File metadata and controls
34 lines (30 loc) · 1019 Bytes
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
// YouTube → Claude Transcriber — Background Service Worker
let ytcClaudeTabId = null;
// Open options page when extension icon is clicked
chrome.action.onClicked.addListener(() => {
chrome.runtime.openOptionsPage();
});
// Keyboard shortcut handler
chrome.commands.onCommand.addListener((command) => {
if (command === 'transcribe') {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]?.url?.includes('youtube.com/watch')) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'triggerTranscribe' });
}
});
}
});
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.action === 'openClaude') {
chrome.storage.local.set({ ytcPrompt: msg.prompt }, () => {
chrome.tabs.create({ url: 'https://claude.ai/new' }, (tab) => {
ytcClaudeTabId = tab.id;
});
});
}
if (msg.action === 'isYtcTab') {
sendResponse({ isYtcTab: sender.tab?.id === ytcClaudeTabId });
return false;
}
return false;
});