Skip to content

Instantly share code, notes, and snippets.

@marijn
Created October 27, 2017 14:21
Show Gist options
  • Save marijn/2e4f0527dc9e32f2c67244d74e71a289 to your computer and use it in GitHub Desktop.
Save marijn/2e4f0527dc9e32f2c67244d74e71a289 to your computer and use it in GitHub Desktop.
Bookmarklet for filling out forms with placeholder data
javascript:(function%20()%20{%20function%20usePlaceholdersAsFormInput()%20{%20var%20fields%20=%20document.querySelectorAll('input[placeholder]');%20var%20cruft%20=%20/^E\.g\.\s+/;%20for%20(var%20i%20=%200,%20field;%20i%20<%20fields.length;%20i++)%20{%20field%20=%20fields.item(i);%20field.value%20=%20field.placeholder.replace(cruft,%20'');%20}%20}%20function%20selectFirstOptionFromMenus()%20{%20var%20menus%20=%20document.querySelectorAll('select');%20for%20(var%20i%20=%200,%20option;%20i%20<%20menus.length;%20i++)%20{%20option%20=%20menus.item(i).querySelector('option[value]');%20if%20(option)%20{%20option.selected%20=%20true;%20}%20}%20}%20usePlaceholdersAsFormInput();%20selectFirstOptionFromMenus();%20})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment