~sircmpwn/himitsu-devel

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

tiosgz: 1
 content: ignore superfluous key pairs

 1 files changed, 11 insertions(+), 9 deletions(-)
#1313082 .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/54759/mbox | git am -3
Learn more about email & git

[PATCH himitsu-firefox] 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.
---
I still don't feel good about making no requirement on the number of
matches, but couldn't think of a universal solution. Any thoughts?

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

diff --git a/content/content.js b/content/content.js
index 73b657d..07fe75c 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 (bestForm === null || hits > bestHits) {
			bestForm = form;
		}
	}
	return null;
	return bestForm;
}

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

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

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

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