From e671f35193db69212711b3e7ff42ec4ad7d70feb Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 8 Oct 2016 18:09:38 -0400 Subject: [PATCH] Added generate password option to context menu --- src/background.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/background.js b/src/background.js index 63c0eada53..d324dab52a 100644 --- a/src/background.js +++ b/src/background.js @@ -13,6 +13,10 @@ var appIdService = new AppIdService(); chrome.commands.onCommand.addListener(function (command) { if (command === 'generate_password') { + ga('send', { + hitType: 'event', + eventAction: 'Generated Password From Command' + }); passwordGenerationService.getOptions().then(function (options) { var password = passwordGenerationService.generatePassword(options); copyToClipboard(password); @@ -88,6 +92,17 @@ function buildContextMenu() { contexts: ['all'], title: 'Copy Password' }); + + chrome.contextMenus.create({ + type: 'separator' + }); + + chrome.contextMenus.create({ + type: 'normal', + id: 'generate-password', + contexts: ['all'], + title: 'Generate Password (copied)' + }); } chrome.tabs.onActivated.addListener(function (activeInfo) { @@ -175,7 +190,17 @@ function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) { } chrome.contextMenus.onClicked.addListener(function (info, tab) { - if (info.parentMenuItemId === 'autofill' || info.parentMenuItemId === 'copy-username' || + if (info.menuItemId === 'generate-password') { + ga('send', { + hitType: 'event', + eventAction: 'Generated Password From Context Menu' + }); + passwordGenerationService.getOptions().then(function (options) { + var password = passwordGenerationService.generatePassword(options); + copyToClipboard(password); + }); + } + else if (info.parentMenuItemId === 'autofill' || info.parentMenuItemId === 'copy-username' || info.parentMenuItemId === 'copy-password') { var id = info.menuItemId.split('_')[1]; if (id === 'noop') {