Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to clear history for one item #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,30 @@ function readFromClipboard() {
*/
async function saveRecent(settings, login, remove = false) {
var ignoreInterval = 60000; // 60 seconds - don't increment counter twice within this window
var key = sha1(settings.origin + sha1(login.store.id + sha1(login.login)));

// save store timestamp
localStorage.setItem("recent:" + login.store.id, JSON.stringify(Date.now()));
if (remove) {
login.recent.count = 0;
if (settings.recent.hasOwnProperty(key)) {
delete settings.recent[key];
}
} else {
// save store timestamp
localStorage.setItem("recent:" + login.store.id, JSON.stringify(Date.now()));

// update login usage count & timestamp
if (Date.now() > login.recent.when + ignoreInterval) {
login.recent.count++;
// update login usage count & timestamp
if (Date.now() > login.recent.when + ignoreInterval) {
login.recent.count++;
}
login.recent.when = Date.now();
settings.recent[key] = login.recent;
}
login.recent.when = Date.now();
settings.recent[sha1(settings.origin + sha1(login.store.id + sha1(login.login)))] =
login.recent;

// save to local storage
localStorage.setItem("recent", JSON.stringify(settings.recent));

// a new entry was added to the popup matching list, need to refresh the count
if (!login.inCurrentHost && login.recent.count === 1) {
// an entry was added / removed to the popup matching list, need to refresh the count
if (!login.inCurrentHost) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we maybe use && login.recent.count < 2? in end end badge count changes only when you have just used a new entry, or when you removed it...

updateMatchingPasswordsCount(settings.tab.id, true);
}

Expand Down Expand Up @@ -846,6 +853,17 @@ async function handleMessage(settings, message, sendResponse) {
});
}
break;
case "clearRecent":
try {
await saveRecent(settings, message.login, true);
sendResponse({ status: "ok" });
} catch (e) {
sendResponse({
status: "error",
message: e.message,
});
}
break;
default:
sendResponse({
status: "error",
Expand Down
10 changes: 10 additions & 0 deletions src/popup/icon-eraser.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 81 additions & 59 deletions src/popup/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,69 +61,91 @@ function view(ctl, params) {
nodes.push(
m(
"div.logins",
this.results.map(function (result) {
const storeBgColor = result.store.bgColor || result.store.settings.bgColor;
const storeColor = result.store.color || result.store.settings.color;
this.results
.filter((result) => {
return !this.currentDomainOnly || result.inCurrentHost || result.recent.when;
})
.map(function (result) {
console.log(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably no need for keeping console.log 🙂

const storeBgColor = result.store.bgColor || result.store.settings.bgColor;
const storeColor = result.store.color || result.store.settings.color;

return m(
"div.part.login",
{
key: result.index,
tabindex: 0,
onclick: function (e) {
var action = e.target.getAttribute("action");
if (action) {
result.doAction(action);
} else {
result.doAction("fill");
}
return m(
"div.part.login",
{
key: result.index,
tabindex: 0,
onclick: function (e) {
var action = e.target.getAttribute("action");
if (action) {
result.doAction(action);
} else {
result.doAction("fill");
}
},
onkeydown: keyHandler.bind(result),
},
onkeydown: keyHandler.bind(result),
},
[
m("div.name", { title: "Fill username / password | <Enter>" }, [
m("div.line1", [
m(
"div.store.badge",
{
style: `background-color: ${storeBgColor};
[
m("div.name", { title: "Fill username / password | <Enter>" }, [
m("div.line1", [
m(
"div.store.badge",
{
style: `background-color: ${storeBgColor};
color: ${storeColor}`,
},
result.store.name
),
m("div.path", [m.trust(result.path)]),
result.recent.when > 0
? m("div.recent", {
title:
"Used here " +
result.recent.count +
" time" +
(result.recent.count > 1 ? "s" : "") +
", last " +
Moment(new Date(result.recent.when)).fromNow(),
})
: null,
},
result.store.name
),
m("div.path", [m.trust(result.path)]),
result.recent.when > 0
? [
m("div.recent", {
title:
"Used here " +
result.recent.count +
" time" +
(result.recent.count > 1 ? "s" : "") +
", last " +
Moment(
new Date(result.recent.when)
).fromNow(),
}),
m("div.clear-recent", {
title: "Forget recent usage here",
onclick: (e) => {
e.stopPropagation();
result.recent.when = 0;
document
.querySelector(
".part.search input[type='text']"
)
.dispatchEvent(new Event("input"));
result.doAction("clearRecent");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pressing on the "Clear usage" button for some reason requires me to touch Yubikey, not sure why, but it definitely shouldn't, as I am not intending to decrypt the password entry... And if I don't touch Yubikey, then the recent will not be cleared 🤔

},
}),
]
: null,
]),
m("div.line2", [m.trust(result.display)]),
]),
m("div.line2", [m.trust(result.display)]),
]),
m("div.action.copy-user", {
tabindex: 0,
title: "Copy username | <Ctrl+Shift+C>",
action: "copyUsername",
}),
m("div.action.copy-password", {
tabindex: 0,
title: "Copy password | <Ctrl+C>",
action: "copyPassword",
}),
m("div.action.details", {
tabindex: 0,
title: "Open Details | <Ctrl+O>",
action: "getDetails",
}),
]
);
})
m("div.action.copy-user", {
tabindex: 0,
title: "Copy username | <Ctrl+Shift+C>",
action: "copyUsername",
}),
m("div.action.copy-password", {
tabindex: 0,
title: "Copy password | <Ctrl+C>",
action: "copyPassword",
}),
m("div.action.details", {
tabindex: 0,
title: "Open Details | <Ctrl+O>",
action: "getDetails",
}),
]
);
})
)
);

Expand Down
14 changes: 11 additions & 3 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ async function withLogin(action) {
case "getDetails":
handleError("Loading entry details...", "notice");
break;
case "clearRecent":
// do nothing
break;
default:
handleError("Please wait...", "notice");
break;
Expand All @@ -131,9 +134,14 @@ async function withLogin(action) {
if (action === "getDetails") {
var details = new DetailsInterface(this.settings, response.login);
details.attach(document.body);
} else {
window.close();
}
} else
switch (action) {
case "clearRecent":
// don't close the popup
break;
default:
window.close();
}
}
} catch (e) {
handleError(e);
Expand Down
10 changes: 9 additions & 1 deletion src/popup/popup.less
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,22 @@ body {
flex-direction: row;
font-size: 12px;

.recent {
.recent,
.clear-recent {
background-image: url("/popup/icon-history.svg");
background-repeat: no-repeat;
background-size: contain;
margin-left: 8px;
width: 9.5px;
margin-top: 4px;
}

.clear-recent {
background-image: url("/popup/icon-eraser.svg");
margin-left: 4px;
margin-top: 2px;
width: 12px;
}
}

.line2 {
Expand Down