implement autofill functionality into context menu

This commit is contained in:
Kyle Spearrin 2016-09-17 00:13:12 -04:00
parent 78ec69a9c8
commit f6849ed04c
2 changed files with 38 additions and 3 deletions

View File

@ -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();

View File

@ -69,7 +69,7 @@ angular
command: 'fillForm',
fillScript: fillScript
}, function () {
$window.close()
$window.close();
});
}
else {