Skip to content

Commit

Permalink
Add context-menu item for generating QR code for the current page (ru…
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoudhusam committed Oct 14, 2024
1 parent 549ab33 commit 1074bd8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
15 changes: 14 additions & 1 deletion src/background/modules/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1074bd8

Please sign in to comment.