1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 22:33:35 +00:00

context menu option when no matching sites

This commit is contained in:
Kyle Spearrin
2016-09-21 23:59:53 -04:00
parent 714328d13a
commit 2432f5bab2

View File

@@ -32,17 +32,17 @@ function buildContextMenu() {
title: 'Copy Password' title: 'Copy Password'
}); });
chrome.contextMenus.create({ //chrome.contextMenus.create({
type: 'separator', // type: 'separator',
contexts: ['all'] // contexts: ['all']
}); //});
chrome.contextMenus.create({ //chrome.contextMenus.create({
type: 'normal', // type: 'normal',
id: 'generate-password', // id: 'generate-password',
contexts: ['all'], // contexts: ['all'],
title: 'Generate Password' // title: 'Generate Password'
}); //});
} }
chrome.tabs.onActivated.addListener(function (activeInfo) { chrome.tabs.onActivated.addListener(function (activeInfo) {
@@ -88,7 +88,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
for (var i = 0; i < sites.length; i++) { for (var i = 0; i < sites.length; i++) {
if (sites[i].domain && tabDomain === sites[i].domain) { if (sites[i].domain && tabDomain === sites[i].domain) {
count++; count++;
loadContextMenuOptions(sites[i]); loadSiteContextMenuOptions(sites[i]);
} }
} }
@@ -105,6 +105,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
}); });
} }
else { else {
loadNoSitesContextMenuOptions();
chrome.browserAction.setBadgeText({ chrome.browserAction.setBadgeText({
text: null, text: null,
tabId: tabId tabId: tabId
@@ -117,6 +118,10 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.parentMenuItemId === 'autofill' || info.parentMenuItemId === 'copy-username' || 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') {
return;
}
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) {
@@ -182,7 +187,7 @@ function autofillPage(site) {
fillScript = autofillService.generateFillScript(pageDetails, site.username, site.password); fillScript = autofillService.generateFillScript(pageDetails, site.username, site.password);
} }
if (tabId && fillScript) { if (tabId && fillScript && fillScript.script) {
chrome.tabs.sendMessage(tabId, { chrome.tabs.sendMessage(tabId, {
command: 'fillForm', command: 'fillForm',
fillScript: fillScript fillScript: fillScript
@@ -216,20 +221,37 @@ function buildContextMenuOptions(url) {
} }
siteService.getAllDecrypted().then(function (sites) { siteService.getAllDecrypted().then(function (sites) {
sortSites(sites); var count = 0;
for (var i = 0; i < sites.length; i++) { if (sites && sites.length) {
if (sites[i].domain && tabDomain === sites[i].domain) { sortSites(sites);
loadContextMenuOptions(sites[i]); for (var i = 0; i < sites.length; i++) {
if (sites[i].domain && tabDomain === sites[i].domain) {
count++;
loadSiteContextMenuOptions(sites[i]);
}
} }
} }
if (!count) {
loadNoSitesContextMenuOptions();
}
}); });
} }
function loadContextMenuOptions(site) { function loadSiteContextMenuOptions(site) {
var title = site.name + ' (' + site.username + ')'; var title = site.name + ' (' + site.username + ')';
loadContextMenuOptions(title, site.id);
}
function loadNoSitesContextMenuOptions() {
var title = 'No matching sites.';
loadContextMenuOptions(title, 'noop');
}
function loadContextMenuOptions(title, idSuffix) {
chrome.contextMenus.create({ chrome.contextMenus.create({
type: 'normal', type: 'normal',
id: 'autofill_' + site.id, id: 'autofill_' + idSuffix,
parentId: 'autofill', parentId: 'autofill',
contexts: ['all'], contexts: ['all'],
title: title title: title
@@ -237,7 +259,7 @@ function loadContextMenuOptions(site) {
chrome.contextMenus.create({ chrome.contextMenus.create({
type: 'normal', type: 'normal',
id: 'copy-username_' + site.id, id: 'copy-username_' + idSuffix,
parentId: 'copy-username', parentId: 'copy-username',
contexts: ['all'], contexts: ['all'],
title: title title: title
@@ -245,7 +267,7 @@ function loadContextMenuOptions(site) {
chrome.contextMenus.create({ chrome.contextMenus.create({
type: 'normal', type: 'normal',
id: 'copy-password_' + site.id, id: 'copy-password_' + idSuffix,
parentId: 'copy-password', parentId: 'copy-password',
contexts: ['all'], contexts: ['all'],
title: title title: title