feat(background): add context menu item for sending current page to MeTube
- Create a new context menu item 'metube-page' for page context - Update context menu URL patterns for YouTube and related sites in options - Modify context menu click handler to use page URL if link URL is not available - Ensure clicking context menu can send current page URL to MeTube and optionally switch tab
This commit is contained in:
parent
984c717e36
commit
55c3b548ca
|
|
@ -11,6 +11,12 @@ chrome.runtime.onInstalled.addListener(function () {
|
|||
],
|
||||
contexts: ['link'],
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
id: 'metube-page',
|
||||
title: "Send page to MeTube",
|
||||
contexts: ['page'],
|
||||
});
|
||||
});
|
||||
|
||||
function sendVideoUrlToMetube(videoUrl, metubeUrl, format, advancedSettings, callback) {
|
||||
|
|
@ -64,7 +70,8 @@ chrome.contextMenus.onClicked.addListener(function (item, tab) {
|
|||
|
||||
let needToSwitch = (data.contextMenuClickBehavior === 'context-menu-send-current-url-and-switch');
|
||||
|
||||
sendVideoUrlToMetube(item.linkUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
|
||||
let videoUrl = item.linkUrl || item.pageUrl;
|
||||
sendVideoUrlToMetube(videoUrl, data.metube, data.defaultFormat, data.advancedSettings, function () {
|
||||
if (needToSwitch) {
|
||||
openTab(data.metube, tab);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,18 @@ async function saveOptions() {
|
|||
}
|
||||
);
|
||||
|
||||
chrome.contextMenus.update(
|
||||
'metube-page',
|
||||
{
|
||||
documentUrlPatterns: [
|
||||
'https://www.youtube.com/*',
|
||||
'https://m.youtube.com/*',
|
||||
'https://youtu.be/*',
|
||||
...sites
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
async function restoreOptions() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue