-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (29 loc) · 1020 Bytes
/
Copy pathbackground.js
File metadata and controls
32 lines (29 loc) · 1020 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
// YouTube Bookmark Extension - Background Service Worker
// Listens for tab updates and communicates with content scripts
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// Check if the tab has a URL and it's a YouTube video page
if (tab.url && tab.url.includes('youtube.com/watch')) {
try {
// Extract video ID from URL
const url = new URL(tab.url);
const videoId = url.searchParams.get('v');
if (videoId) {
// Send message to content script
chrome.tabs.sendMessage(tabId, {
type: 'NEW',
videoId: videoId
});
}
} catch (error) {
console.error('Error processing YouTube URL:', error);
}
}
});
// Handle installation - useful for future updates
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
console.log('YouTube Bookmarks Extension installed');
} else if (details.reason === 'update') {
console.log('YouTube Bookmarks Extension updated');
}
});