mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-03-20 15:41:40 -04:00
Add context menu with password generator (#541)
This commit is contained in:
@@ -2,6 +2,7 @@ import { Vault } from './types/webapi/Vault';
|
||||
import EncryptionUtility from './utils/EncryptionUtility';
|
||||
import SqliteClient from './utils/SqliteClient';
|
||||
import { WebApiService } from './utils/WebApiService';
|
||||
import { PasswordGenerator } from './generators/Password/PasswordGenerator';
|
||||
|
||||
let vaultState: {
|
||||
derivedKey: string | null;
|
||||
@@ -15,6 +16,58 @@ let vaultState: {
|
||||
vaultRevisionNumber: 0,
|
||||
};
|
||||
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
chrome.contextMenus.create({
|
||||
id: "aliasvault-root",
|
||||
title: "AliasVault",
|
||||
contexts: ["all"]
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
id: "aliasvault-generate-password",
|
||||
parentId: "aliasvault-root",
|
||||
title: "Generate Password (copy to clipboard)",
|
||||
contexts: ["all"]
|
||||
});
|
||||
});
|
||||
|
||||
chrome.contextMenus.onClicked.addListener((info, tab) => {
|
||||
if (info.menuItemId === "aliasvault-generate-password") {
|
||||
// Initialize password generator
|
||||
const passwordGenerator = new PasswordGenerator();
|
||||
const password = passwordGenerator.generateRandomPassword();
|
||||
|
||||
// Use chrome.scripting to write to clipboard from active tab
|
||||
if (tab?.id) {
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
func: (generatedPassword) => {
|
||||
// Write to clipboard
|
||||
navigator.clipboard.writeText(generatedPassword).then(() => {
|
||||
// Show notification
|
||||
const notification = document.createElement('div');
|
||||
notification.textContent = 'Password copied to clipboard';
|
||||
notification.style.cssText = `
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
padding: 16px;
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
z-index: 9999;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
||||
`;
|
||||
document.body.appendChild(notification);
|
||||
setTimeout(() => notification.remove(), 3000);
|
||||
});
|
||||
},
|
||||
args: [password]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Listen for messages from popup
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
switch (message.type) {
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';"
|
||||
},
|
||||
"action": {
|
||||
"default_popup": "index.html"
|
||||
"default_popup": "index.html",
|
||||
"default_title": "AliasVault"
|
||||
},
|
||||
"icons": {
|
||||
"16": "assets/icons/icon-16.png",
|
||||
@@ -23,7 +24,8 @@
|
||||
},
|
||||
"permissions": [
|
||||
"storage",
|
||||
"activeTab"
|
||||
"activeTab",
|
||||
"contextMenus"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user