Created
July 6, 2021 19:02
-
-
Save groovecoder/70f1b5809353a8ab17bf31901e4a065a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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