Skip to content

Instantly share code, notes, and snippets.

@fregante
Created February 9, 2017 07:47
Show Gist options
  • Save fregante/24ac48e7d6dfe86a885393080a26471b to your computer and use it in GitHub Desktop.
Save fregante/24ac48e7d6dfe86a885393080a26471b to your computer and use it in GitHub Desktop.
Copy saved password bookmarklet
// Get non-empty, visible password fields
var fields = [...document.querySelectorAll('[type=password]')].filter(f => f.value && f.offsetParent);
var cpy = field => {
field.type = '';
field.select();
document.execCommand('copy');
field.type = 'password';
}
if (fields.length === 1) {
cpy(fields[0]);
} else {
document.body.addEventListener('click', e => {
cpy(e.target);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment