Allow admin password to be revealed

This commit is contained in:
Tom Wiesing 2023-04-12 14:05:24 +02:00
parent 85c63f24a9
commit 34db2e1923
No known key found for this signature in database
10 changed files with 117 additions and 19 deletions

View file

@ -1 +1,2 @@
import "~/src/lib/copy"
import "~/src/lib/copy"
import "~/src/lib/reveal"

View file

@ -0,0 +1,43 @@
document.querySelectorAll('span').forEach((elem: Element) => {
if (!elem.hasAttribute('data-reveal')) return
addReveal(elem as HTMLSpanElement, 10000);
})
export function addReveal(span: HTMLSpanElement, hideDelay: number) {
const content = span.getAttribute("data-reveal") ?? '(no content)'
let isHidden = true
// handler to hide the element
const hide = () => {
isHidden = true
span.innerText = "(click to reveal)"
}
hide()
const reveal = () => {
isHidden = false
const code = document.createElement('code')
code.append(content)
code.addEventListener('click', (evt) => {
evt.preventDefault()
if (!navigator.clipboard) return
navigator.clipboard.writeText(content)
})
code.style.userSelect = "all";
span.innerHTML = ""
span.append(code)
}
span.addEventListener("click", (evt) => {
evt.preventDefault()
if (!isHidden) return
reveal()
setTimeout(hide, hideDelay) // hide again after 1 second
})
}