Added generate password option to context menu

This commit is contained in:
Kyle Spearrin 2016-10-08 18:09:38 -04:00
parent 691d2625d7
commit e671f35193
1 changed files with 26 additions and 1 deletions

View File

@ -13,6 +13,10 @@ var appIdService = new AppIdService();
chrome.commands.onCommand.addListener(function (command) { chrome.commands.onCommand.addListener(function (command) {
if (command === 'generate_password') { if (command === 'generate_password') {
ga('send', {
hitType: 'event',
eventAction: 'Generated Password From Command'
});
passwordGenerationService.getOptions().then(function (options) { passwordGenerationService.getOptions().then(function (options) {
var password = passwordGenerationService.generatePassword(options); var password = passwordGenerationService.generatePassword(options);
copyToClipboard(password); copyToClipboard(password);
@ -88,6 +92,17 @@ function buildContextMenu() {
contexts: ['all'], contexts: ['all'],
title: 'Copy Password' 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) { chrome.tabs.onActivated.addListener(function (activeInfo) {
@ -175,7 +190,17 @@ function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) {
} }
chrome.contextMenus.onClicked.addListener(function (info, tab) { 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') { info.parentMenuItemId === 'copy-password') {
var id = info.menuItemId.split('_')[1]; var id = info.menuItemId.split('_')[1];
if (id === 'noop') { if (id === 'noop') {