From 076cae05a3b190782cb76a4073b596353d739116 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 27 Jul 2022 10:51:07 +1000 Subject: fixing some bugs introduced in the previous commit. also corrected a typo --- content/contactFinder.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'content/contactFinder.js') diff --git a/content/contactFinder.js b/content/contactFinder.js index 6191afc..b7d95a0 100644 --- a/content/contactFinder.js +++ b/content/contactFinder.js @@ -51,7 +51,8 @@ debug("Injecting contact finder in %s", document.URL); * and by degree of certainty. */ const contactFrags = { - 'da': { + // TODO: remove lang, change things to regexp + 'de': { 'certain': [ '^[\\s]*Kontakt os[\\s]*$', '^[\\s]*Email Os[\\s]*$', @@ -136,8 +137,8 @@ function attempt(certaintyLvl, first = true) { for (const byLevel of Object.values(contactFrags)) { for (const frag of byLevel[certaintyLvl]) { if (!matched) { - const result = strUnderTest.match(new RegExp(frag, "g")).filter(x => typeof x == "string"); - if (result && typeof (result[0]) === "string") { + const result = (strUnderTest.match(new RegExp(frag, "g")) || []).filter(x => typeof x == "string"); + if (result.length) { if (first) { return { "fail": false, "result": link }; } else { @@ -150,7 +151,7 @@ function attempt(certaintyLvl, first = true) { } } } - return { "fail": notMatched, "result": matches }; + return { "fail": matches.length === 0, "result": matches }; } /** @@ -232,8 +233,8 @@ function main() { } // TODO: check this change is ok, i.e. if the result of match is null filter still works - const emails = document.documentElement.textContent.match(email_regex).filter(e => !!e); - if (emails && emails.length) { + const emails = (document.documentElement.textContent.match(email_regex) || []).filter(e => !!e); + if (emails.length) { addHTML("
Possible email addresses:
"); const list = contentDoc.createElement("ul"); for (const recipient of emails.slice(0, 10)) { -- cgit v1.2.3