Skip to content

Commit

Permalink
Don't dbl-click for username if field has data
Browse files Browse the repository at this point in the history
Trying to avoid putting the dbl-click placeholder on an input field that isn't for a userid.  I also gave the variable a more descriptive name.
  • Loading branch information
alanhkarp committed Sep 20, 2024
1 parent f45e2a1 commit 11d2cbc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/findpw.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ function countpwid() {
var pwfields = [];
var found = -1;
var c = 0;
let firstVisible = null;
let maybeUsernameField = null;
let inputs = document.getElementsByTagName("input");
if (cpi.pwfields.length === 0 && inputs.length === 0) inputs = searchShadowRoots(document.body);
for (var i = 0; i < inputs.length; i++) {
visible = !isHidden(inputs[i]);
// I'm only interested in visible text and email fields,
// and splitting the condition makes it easier to debug
if (visible && inputs[i].type === "text" || inputs[i].type === "email") {
if (!firstVisible) firstVisible = inputs[i];
if (!maybeUsernameField) maybeUsernameField = inputs[i];
}
if (visible && inputs[i].type && (inputs[i].type.toLowerCase() === "password")) {
if (logging) console.log(document.URL, Date.now() - start, "findpw found password field", i, inputs[i], visible);
Expand Down Expand Up @@ -377,24 +377,23 @@ function countpwid() {
}
// Allow dbl click to fill in the username
// I already fill in the username if there are any password fields
if (c === 0 && firstVisible) {
let usernameField = firstVisible;
if (c === 0 && maybeUsernameField && !maybeUsernameField.value) {
// Using await spreads async all over the place
wakeup().then(() => {
chrome.runtime.sendMessage({ "cmd": "getUsername" }).then((response) => {
if (chrome.runtime.lastError) console.log(document.URL, Date.now() - start, "findpw getUsername error", chrome.runtime.lastError);
if (response) {
if (!usernameField.placeholder) usernameField.placeholder = insertUsername;
if (!usernameField.title) usernameField.title = insertUsername;
usernameField.ondblclick = async function () {
if (!maybeUsernameField.placeholder) maybeUsernameField.placeholder = insertUsername;
if (!maybeUsernameField.title) maybeUsernameField.title = insertUsername;
maybeUsernameField.ondblclick = async function () {
let mutations = mutationObserver.takeRecords();
fillfield(this, response);
let myMutations = mutationObserver.takeRecords();
if (logging) console.log(document.URL, Date.now() - start, "findpw got username", this, response, myMutations);
handleMutations(mutations);
}
} else {
usernameField.ondblclick = null;
maybeUsernameField.ondblclick = null;
}
});
});
Expand Down

0 comments on commit 11d2cbc

Please sign in to comment.