diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 71a1ecd8..b921355f 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -186,6 +186,14 @@ "message": "&QR code from link", "description": "The context menu entry shown for generating QR codes from a selected link with an access key." }, + "contextMenuItemConvertPageURL": { + "message": "Generate QR Code for this Page", + "description": "Context menu item title for generating a QR code for the current page URL." + }, + "contextMenuItemConvertPageURLAccessKey": { + "message": "&Generate QR Code for this Page", + "description": "Context menu item title for generating a QR code for the current page URL with an access key." + }, "contextMenuSaveImageCanvas": { "message": "Save QR code as an imageā€¦", "description": "The context menu entry shown for saving PNG images (from a canvas) in the popup." diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index 605d74df..b0726442 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -4,6 +4,7 @@ import { createMenu } from "/common/modules/ContextMenu.js"; const CONVERT_TEXT_SELECTION = "qr-convert-text-selection"; const CONVERT_LINK_TEXT_SELECTION = "qr-convert-link-text-selection"; const OPEN_OPTIONS = "qr-open-options"; +const CONVERT_PAGE_URL = "qr-convert-page-url"; const MESSAGE_RESENT_TIMEOUT = 200; // ms const MESSAGE_RESENT_MAX = 9; @@ -55,12 +56,17 @@ function createItems() { contexts: ["link"] }); + const pageMenu = createMenu("contextMenuItemConvertPageURL", { + id: CONVERT_PAGE_URL, + contexts: ["page"] + }); + browser.menus.refresh(); // if listener is set, because items were hidden -> remove it browser.menus.onHidden.removeListener(createItems); - return Promise.all([selectionMenu, linkMenu]); + return Promise.all([selectionMenu, linkMenu, pageMenu]); } /** @@ -88,6 +94,13 @@ function menuClicked(event) { sendQrCodeText(event.linkUrl); }); break; + case CONVERT_PAGE_URL: + browser.browserAction.openPopup().then(() => { + messageResentCount = 0; + // Send the current page URL to the popup + sendQrCodeText(event.pageUrl); + }); + break; case OPEN_OPTIONS: browser.runtime.openOptionsPage(); break;