~sircmpwn/himitsu-devel

himitsu-firefox: content: ignore superfluous key pairs v2 PROPOSED

tiosgz: 1
 content: ignore superfluous key pairs

 1 files changed, 11 insertions(+), 9 deletions(-)
#1313191 .build.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/himitsu-devel/patches/54761/mbox | git am -3
Learn more about email & git

[PATCH himitsu-firefox v2] content: ignore superfluous key pairs Export this patch

The code assumed some pairs could be optional, but as far as i can tell
this can only be specified when querying the database. Now instead look
for the form with most matching keys.

It may make sense to limit the match count to at least two to avoid
filling a completely unrelated form, but it is possible to have a
single-input form, so hopefully the on-demand nature of auto-filling is
enough.
---
Apologies, defaulting to first form was a leftover from an earlier
variant. Question still stands: any thoughts how to prevent filling an
unrelated form?

 content/content.js | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/content/content.js b/content/content.js
index 73b657d..1852843 100644
--- a/content/content.js
+++ b/content/content.js
@@ -16,6 +16,9 @@ function handleAutofill(msg) {
			return;
		};
		const input = findInput(form, pair.key);
		if (input === null) {
			return;
		}
		input.click();
		input.focus();
		input.value = pair.value;
@@ -30,26 +33,25 @@ function handleAutofill(msg) {

function findForm(key) {
	const forms = document.querySelectorAll("form");
	let bestForm = null;
	let bestHits = 0;
	for (let i = 0; i < forms.length; i++) {
		const form = forms[i];
		let valid = true;
		let hits = 0;
		key.map(pair => {
			if (pair.key === "proto" || pair.key === "host") {
				return;
			};
			if (pair.optional) {
				return;
			}
			const input = findInput(form, pair.key);
			if (input === null) {
				valid = false;
			if (input !== null) {
				hits++;
			}
		});
		if (valid) {
			return form;
		if (hits > bestHits) {
			bestForm = form;
		}
	}
	return null;
	return bestForm;
}

function findInput(elem, key) {
-- 
2.46.0
himitsu-firefox/patches/.build.yml: FAILED in 16s

[content: ignore superfluous key pairs][0] v2 from [tiosgz][1]

[0]: https://lists.sr.ht/~sircmpwn/himitsu-devel/patches/54761
[1]: mailto:alamica@protonmail.com

✗ #1313191 FAILED himitsu-firefox/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/1313191