Skip to content

Instantly share code, notes, and snippets.

@rawnly
Created July 3, 2021 18:08
Show Gist options
  • Save rawnly/030b1387419b72e5e9996f6221595f6b to your computer and use it in GitHub Desktop.
Save rawnly/030b1387419b72e5e9996f6221595f6b to your computer and use it in GitHub Desktop.
Sometimes it works, sometimes not. Better than nothing :)
const genericButton = document.querySelector('[type="submit"]')
const password_input = document.querySelector('[type="password"]')
const button = document.createElement('button')
button.setAttribute('type', 'button')
button.innerText = 'Show Password'
button.style = "margin-top: 5px;"
if ( genericButton ) {
button.setAttribute('class', genericButton.getAttribute('class'))
}
button.onclick = (e) => {
e.preventDefault()
const el = document.getElementById(password_input.getAttribute('id'))
if ( el.getAttribute('type') === 'password' ) {
el.setAttribute('type', 'text')
button.innerText = 'Hide Password'
} else {
el.setAttribute('type', 'password')
button.innerText = 'Show Password'
}
}
genericButton.parentNode.appendChild(button)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment