Skip to content

Instantly share code, notes, and snippets.

@agu-z
Created July 7, 2020 00:36
Show Gist options
  • Save agu-z/1c716f2dab269a60bd4c317f1ca86250 to your computer and use it in GitHub Desktop.
Save agu-z/1c716f2dab269a60bd4c317f1ca86250 to your computer and use it in GitHub Desktop.
/*
* This rough script generates elm-ui attributes for autofill from the whatwg spec.
*
* Steps:
*
* 1) Go to https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill
* 2) Open the console
* 3) Run the following code
* 4) Copy the printed string and paste it after the "on" binding in UI/TextBox/Autofill.elm
* 5) Remove the module declaration at the top
* 6) Run elm-format and let it generates the exposing clause for you ;)
* 7) Add a line break between some of the exposed entries and run elm-format again
* 8) Remove "autocomplete" from the exposing list
* 9) Change Main to UI.TextBox.Autofill
*/
const fields = $$("table dfn[id^=attr-fe-autocomplete]");
const attributes = fields
.map(element => {
const name = element.innerText;
const elmName = name.replace(/-./g, c => c.toUpperCase()[1]);
const siblings = element.parentElement.parentElement.children;
const doc = siblings[siblings[0].className === "non-rectangular-cell-indentation" ? 2 : 1].innerText;
return `{-| ${doc}\n-}\n${elmName} : Attribute msg\n${elmName} =\n autocomplete "${element.innerText}"`;
})
.join("\n\n");
console.log(attributes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment