added: password manager

This commit is contained in:
quenousimporte 2024-01-08 16:28:47 +01:00
parent aa8a8d1bbc
commit 00bb99c0c0
1 changed files with 65 additions and 0 deletions

65
main.js
View File

@ -271,6 +271,14 @@ var commands = [
{
hint: "Browse bookmarks",
action: browsebookmarks
},
{
hint: "Show passwords list",
action: passwordslist
},
{
hint: "Add password",
action: addpassword
}];
var snippets = [
@ -322,6 +330,51 @@ function getbookmarks()
return JSON.parse(note.content);
}
function getpasswords()
{
var note = getnote("passwords") || {title: "passwords", content: "[]"};
return JSON.parse(note.content);
}
function addpassword()
{
var note = getnote("passwords");
if (!note)
{
note = {title: "passwords", content: "[]"};
localdata.unshift(note);
}
var newentry = {
name: prompt("Name:"),
user: prompt("User:"),
password: prompt("Password:")
};
var passwords = getpasswords();
passwords.unshift(newentry);
note.content = JSON.stringify(passwords, null, " ");
datachanged();
}
function passwordslist()
{
var passwords = getpasswords();
searchinlist(passwords.map(p => ({text: p.name, suffix: [p.user]})))
.then( (item) =>
{
copypassword(item.text);
});
}
function copypassword(name)
{
var passwords = getpasswords();
navigator.clipboard.writeText(passwords.find(p => p.name == name).password);
}
function browsebookmarks()
{
searchinlist(getbookmarks().map(b => b.title))
@ -1675,6 +1728,14 @@ function commandpalette()
prefix: "open bookmark ",
text: b.title
};
}))
.concat(getpasswords().map(p =>
{
return {
prefix: "copy password ",
suffix: [p.user],
text: p.name
};
})))
.then(selected =>
{
@ -1696,6 +1757,10 @@ function commandpalette()
{
openbookmark(selected.text);
}
else if (selected.prefix == "copy password ")
{
copypassword(selected.text);
}
else
{
var command = commands.find(c => c.hint == selected.text);