Last active
February 11, 2025 19:55
-
-
Save Braunson/42daa1a0081b5a8b9b357fa41ab1987c to your computer and use it in GitHub Desktop.
Quickly generate a form filler bookmarklet!
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
// Save this as a bookmark in your browser for the next time you want to fill in the page form! | |
javascript:(function() { | |
const fillValues = { | |
// Paste the object in here from the previous command | |
} | |
function fillField(element, value) { | |
if (!element) return; | |
// Handle different input types | |
switch (element.tagName.toLowerCase()) { | |
case 'select': | |
// Find option with matching value or text | |
const option = Array.from(element.options).find(opt => | |
opt.value === value || opt.text === value | |
); | |
if (option) element.selectedIndex = option.index; | |
break; | |
case 'input': | |
switch (element.type.toLowerCase()) { | |
case 'checkbox': | |
case 'radio': | |
element.checked = value === true || value === 'true' || value === element.value; | |
break; | |
default: | |
element.value = value; | |
} | |
break; | |
default: | |
element.value = value; | |
} | |
// Trigger events | |
['input', 'change', 'blur'].forEach(eventType => { | |
element.dispatchEvent(new Event(eventType, { | |
bubbles: true | |
})); | |
}); | |
} | |
Object.entries(fillValues).forEach(([field, value]) => { | |
fillField(document.querySelector(`#${field}, [name="${field}"]`), value); | |
}); | |
})(); |
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
// Use this on the page you've filled in all fields for to grab the field names and values. Run this in your console or in the URL. | |
// This only includes input, select and textarea for now, expand as needed. | |
(function() { | |
let values = {}; | |
document.querySelectorAll('input, select, textarea').forEach(field => { | |
if (field.id || field.name) { | |
values[field.id || field.name] = field.value; | |
} | |
}); | |
console.log('Copy this for your bookmark:'); | |
console.log(JSON.stringify(values, null, 2)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment