Last active
September 28, 2024 22:16
-
-
Save emlyn/979b2820eaa74fea01b8ddc1351a0f60 to your computer and use it in GitHub Desktop.
Show Passwords with double click
This file contains 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
// ==UserScript== | |
// @name Show Passwords | |
// @description Double click on password fields to show password | |
// @downloadURL https://gist.github.com/emlyn/979b2820eaa74fea01b8ddc1351a0f60/raw/show_password.user.js | |
// @updateURL https://gist.github.com/emlyn/979b2820eaa74fea01b8ddc1351a0f60/raw/show_password.user.js | |
// @namespace https://gist.github.com/emlyn | |
// @version 0.3 | |
// @author Emlyn Corrin | |
// @match http*://*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const KEY_ENTER = 13; | |
const updateEl = function(el) { | |
el.addEventListener('dblclick', () => { | |
if (el.type === 'password') { | |
el.type = 'text'; | |
} else { | |
el.type = 'password'; | |
} | |
}, false); | |
el.addEventListener('blur', () => { | |
el.type = 'password'; | |
}, false); | |
el.addEventListener('keydown', e => { | |
if (e.keyCode === KEY_ENTER) { | |
el.type = 'password'; | |
} | |
}, false); | |
}; | |
const done = new WeakSet(); | |
const updateAll = function() { | |
document.querySelectorAll('input[type=password]').forEach(el => { | |
if (!done.has(el)) { | |
updateEl(el); | |
done.add(el); | |
} | |
}); | |
}; | |
updateAll(); | |
const observer = new MutationObserver(updateAll); | |
observer.observe(document.documentElement, { | |
childList: true, | |
subtree: true, | |
// In case element added as text then changed to password: | |
attributes: true, | |
attributeFilter: ['type'] | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment