Skip to content

Instantly share code, notes, and snippets.

@groovecoder
Created July 6, 2021 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groovecoder/70f1b5809353a8ab17bf31901e4a065a to your computer and use it in GitHub Desktop.
Save groovecoder/70f1b5809353a8ab17bf31901e4a065a to your computer and use it in GitHub Desktop.
const email_detector_ruleset = ruleset([
// Inputs that could be email fields:
rule(dom("input[type=text],input[type=\"\"],input:not([type])").when(isVisible), type("email")),
// Look for exact matches of "email"-like keywords in some attributes of the <input>
rule(
type("email"),
score(fnode => attrsMatch(fnode.element, ["id", "name", "autocomplete"], emailRegexMatchLine)),
{name: "inputAttrsMatchEmailExactly"}
),
// Count matches of "email"-like keywords in some attributes of the <input>
rule(
type("email"),
score(fnode => attrsMatch(fnode.element, ["placeholder", "aria-label"], emailRegex)),
{name: "inputPlaceholderMatchesEmail"}
),
// If there's a corresponding <label> for this input, count its inner text matches for "email"-like keywords
rule(
type("email"),
score(fnode => labelForInputMatches(fnode.element, emailRegex)),
{name: "labelForInputMatchesEmail"}
),
rule(type("email"), out("email")),
],
new Map([
["inputAttrsMatchEmailExactly", 9.416913986206055],
["inputPlaceholderMatchesEmail", 6.740292072296143],
["labelForInputMatchesEmail", 10.197700500488281],
]),
[["email", -3.907843589782715]]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment