// background.js
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: 'copyYouTubeUrl',
title: 'Copy YouTube URL',
contexts: ['page'],
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === 'copyYouTubeUrl') {
chrome.tabs.sendMessage(tab.id, { action: 'getURL' }, (response) => {
const videoUrl = response.url;
if (videoUrl) {
navigator.clipboard.writeText(videoUrl).then(() => {
alert('URL copied to clipboard!');
});
}
});
}
});