From 2a662c77ea566e71b4e34a2fcd53ba8a2b6eeb62 Mon Sep 17 00:00:00 2001 From: nanocortex <40443396+nanocortex@users.noreply.github.com> Date: Wed, 12 Aug 2026 21:52:35 +0200 Subject: [PATCH] Respect One-Click Mode in context menu and keyboard shortcut --- CHANGELOG.md | 5 +++++ README.md | 4 +++- src/background.js | 43 ++++++++++++++++++++++--------------------- src/popup/popup.js | 7 +------ 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a398f56..343ff1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased +- The context menu and keyboard shortcut no longer send the download before you can react. With One-Click Mode disabled they now open the popup pre-filled with the target URL, so quality, folder and other options can be adjusted first ([#18](https://github.com/nanocortex/metube-firefox-addon/issues/18)). +- With One-Click Mode enabled, all four entry points queue the download immediately without opening the popup. +- Right-clicking a link now carries that link's URL into the popup instead of the URL of the page you are on. + ## 1.8.1 - 2026-08-12 - Default folder and custom name prefix now support variables: `%HOSTNAME%`, `%DOMAIN%`, `%DATE%`, `%YEAR%`, `%MONTH%`, `%DAY%`. For example, a folder of `videos/%DOMAIN%` files a YouTube download under `videos/youtube.com`, so downloads can be categorized by site automatically ([#26](https://github.com/nanocortex/metube-firefox-addon/issues/26)). - Variables are resolved against the URL actually being sent, so right-clicking a link uses that link's host rather than the host of the page you're on. diff --git a/README.md b/README.md index 82e74c2..8f2f7f8 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ See the [CHANGELOG](CHANGELOG.md) for version history and release notes. - Right-click on a video link and select "Send to MeTube" - Right-click on the page itself and select "Send page to MeTube" +All four methods behave the same way, controlled by **One-Click Mode**. When it is disabled (the default), the popup opens pre-filled with the target URL so you can adjust quality, folder or any other option before sending. When it is enabled, the download is queued immediately without opening the popup. + ### Keyboard Shortcuts The extension supports the following keyboard shortcut: @@ -114,7 +116,7 @@ The **Default Folder** and **Custom Name Prefix** settings accept variables that | **Show Context Menu on Links** | Show "Send to MeTube" when right-clicking links | `true` | | **Show Context Menu on Page** | Show "Send page to MeTube" when right-clicking the page | `true` | | **Auto Start** | Automatically start downloads when ready | `true` | -| **One-Click Mode** | Send current page to MeTube with one click | `false` | +| **One-Click Mode** | Queue downloads immediately instead of opening the popup. Applies to the toolbar icon, the keyboard shortcut and both context menu entries | `false` | | **Strict Playlist Mode** | Only download playlists when URL explicitly points to one (prevents downloading YouTube Mixes when you only want the current video) | `false` | | **Send Custom Headers** | Enable inclusion of custom headers when queueing | `false` | | **Custom Headers** | Specify custom header names and values for authentication or other purposes | `[]` (empty) | diff --git a/src/background.js b/src/background.js index 1675c85..1393b90 100644 --- a/src/background.js +++ b/src/background.js @@ -247,30 +247,35 @@ async function sendToMeTube(itemUrl, options) { } } -function triggerSendWithLoading(url) { - setTimeout(async () => { - try { - await browser.runtime.sendMessage({ command: 'showLoading' }); - } catch (error) { - console.error("Failed to send showLoading message:", error); - } +async function openPopupWithUrl(url) { + browser.browserAction.setPopup({ + popup: `popup/popup.html?url=${encodeURIComponent(url)}` + }); - const options = await getDefaultSendOptions(); - await sendToMeTube(url, options); - }, 100); + try { + await browser.browserAction.openPopup(); + } catch (error) { + console.error("Failed to open popup:", error); + } finally { + // Only affects later openings; the popup opened above keeps its url. + browser.browserAction.setPopup({ popup: "popup/popup.html" }); + } } -async function sendWithLoadingIndicator(url) { - browser.browserAction.setPopup({ popup: "popup/popup.html" }); - browser.browserAction.openPopup(); - triggerSendWithLoading(url); +async function startSendFlow(url) { + if (await getOneClickMode()) { + await sendToMeTube(url, await getDefaultSendOptions()); + return; + } + + await openPopupWithUrl(url); } browser.menus.onClicked.addListener(async function(info, tab) { if (info.menuItemId === "send-to-metube" && info.linkUrl) { - await sendWithLoadingIndicator(info.linkUrl); + await startSendFlow(info.linkUrl); } else if (info.menuItemId === "send-to-metube-page") { - await sendWithLoadingIndicator(tab.url); + await startSendFlow(tab.url); } }); @@ -301,11 +306,7 @@ updateBrowserActionPopup(); browser.commands.onCommand.addListener(async (command) => { if (command === "send-to-metube") { - browser.browserAction.setPopup({ popup: "popup/popup.html" }); - browser.browserAction.openPopup(); - - const url = await getCurrentUrl(); - triggerSendWithLoading(url); + await startSendFlow(await getCurrentUrl()); } }); diff --git a/src/popup/popup.js b/src/popup/popup.js index 342de3e..0bd7b98 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -74,11 +74,6 @@ function hideLoadingState() { } browser.runtime.onMessage.addListener(async (message) => { - if (message.command === "showLoading") { - showLoadingState(); - return; - } - hideLoadingState(); if (message.command === "errorOccurred") { @@ -122,7 +117,7 @@ function getPopupSelects() { } addEventListener('DOMContentLoaded', async (event) => { - let url = await getCurrentUrl(); + let url = new URLSearchParams(location.search).get('url') || await getCurrentUrl(); if (url && url.indexOf("://") === -1) url = ""; document.getElementById('urlInput').value = url || "";