diff --git a/src/background.js b/src/background.js index 46a6d8a5..05164b54 100644 --- a/src/background.js +++ b/src/background.js @@ -106,12 +106,16 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { }); chrome.contextMenus.onClicked.addListener(function (info, tab) { - if (info.parentMenuItemId === 'copy-username' || info.parentMenuItemId === 'copy-password') { + if (info.parentMenuItemId === 'autofill' || info.parentMenuItemId === 'copy-username' || + info.parentMenuItemId === 'copy-password') { var id = info.menuItemId.split('_')[1]; siteService.getAllDecrypted().then(function (sites) { for (var i = 0; i < sites.length; i++) { if (sites[i].id == id) { - if (info.parentMenuItemId === 'copy-username') { + if (info.parentMenuItemId === 'autofill') { + autofillPage(sites[i]); + } + else if (info.parentMenuItemId === 'copy-username') { copyToClipboard(sites[i].username); } else if (info.parentMenuItemId === 'copy-password') { @@ -124,6 +128,37 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) { } }); +function autofillPage(site) { + chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + var tabId = null; + if (tabs.length > 0) { + tabId = tabs[0].id; + } + else { + return; + } + + if (!tabId) { + return; + } + + chrome.tabs.sendMessage(tabId, { command: 'collectPageDetails' }, function (pageDetails) { + var fillScript = null; + if (site && pageDetails) { + fillScript = autofillService.generateFillScript(pageDetails, site.username, site.password); + } + + if (tabId && fillScript) { + chrome.tabs.sendMessage(tabId, { + command: 'fillForm', + fillScript: fillScript + }); + } + }); + }); + +} + function sortSites(sites) { sites.sort(function (a, b) { var nameA = (a.name + '_' + a.username).toUpperCase(); diff --git a/src/popup/app/current/currentController.js b/src/popup/app/current/currentController.js index 7845e360..5ba5d39d 100644 --- a/src/popup/app/current/currentController.js +++ b/src/popup/app/current/currentController.js @@ -69,7 +69,7 @@ angular command: 'fillForm', fillScript: fillScript }, function () { - $window.close() + $window.close(); }); } else {