mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
implement autofill functionality into context menu
This commit is contained in:
parent
78ec69a9c8
commit
f6849ed04c
@ -106,12 +106,16 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
chrome.contextMenus.onClicked.addListener(function (info, 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];
|
var id = info.menuItemId.split('_')[1];
|
||||||
siteService.getAllDecrypted().then(function (sites) {
|
siteService.getAllDecrypted().then(function (sites) {
|
||||||
for (var i = 0; i < sites.length; i++) {
|
for (var i = 0; i < sites.length; i++) {
|
||||||
if (sites[i].id == id) {
|
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);
|
copyToClipboard(sites[i].username);
|
||||||
}
|
}
|
||||||
else if (info.parentMenuItemId === 'copy-password') {
|
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) {
|
function sortSites(sites) {
|
||||||
sites.sort(function (a, b) {
|
sites.sort(function (a, b) {
|
||||||
var nameA = (a.name + '_' + a.username).toUpperCase();
|
var nameA = (a.name + '_' + a.username).toUpperCase();
|
||||||
|
@ -69,7 +69,7 @@ angular
|
|||||||
command: 'fillForm',
|
command: 'fillForm',
|
||||||
fillScript: fillScript
|
fillScript: fillScript
|
||||||
}, function () {
|
}, function () {
|
||||||
$window.close()
|
$window.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user