mirror of https://codeberg.org/pzp/pzp-hub.git
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
let hasFocus = true
|
|
window.addEventListener('blur', () => {
|
|
hasFocus = false
|
|
})
|
|
window.addEventListener('focus', () => {
|
|
hasFocus = true
|
|
})
|
|
|
|
const inviteLinkElem = document.getElementById('invite')
|
|
const failureElem = document.getElementById('failure')
|
|
|
|
const hash = window.location.hash
|
|
if (hash) {
|
|
let uri = decodeURIComponent(hash.slice(1))
|
|
if (!uri.startsWith('pzp:')) uri = 'pzp://invite' + uri
|
|
inviteLinkElem.href = uri
|
|
|
|
// Autoredirect to the PZP URI as soon as possible
|
|
setTimeout(() => {
|
|
console.log(uri)
|
|
// window.location.replace(uri);
|
|
}, 100)
|
|
|
|
// Redirect to uri or show failure state
|
|
// FIXME:
|
|
// inviteLinkElem.onclick = function handleURI(ev) {
|
|
// ev.preventDefault();
|
|
// const uri = inviteLinkElem.href;
|
|
// inviteLinkElem.classList.remove('hidden');
|
|
// setTimeout(function () {
|
|
// if (hasFocus) {
|
|
// inviteLinkElem.classList.add('hidden');
|
|
// failureElem.classList.remove('hidden');
|
|
// }
|
|
// }, 5000);
|
|
// window.location.replace(uri);
|
|
// };
|
|
|
|
|
|
function copyText(text) {
|
|
const textArea = document.createElement("textarea")
|
|
textArea.value = text
|
|
|
|
textArea.style.position = "absolute"
|
|
textArea.style.left = "-999999px"
|
|
document.body.prepend(textArea)
|
|
|
|
textArea.select()
|
|
document.execCommand('copy')
|
|
|
|
textArea.remove()
|
|
}
|
|
|
|
const copyLinkElem = document.getElementById('copy')
|
|
copyLinkElem.onclick = function handleCopy(ev) {
|
|
copyText(uri);
|
|
copyLinkElem.innerHTML = copyLinkElem.innerHTML += '✓'
|
|
}
|
|
} else {
|
|
inviteLinkElem.classList.add('hidden')
|
|
failureElem.classList.remove('hidden')
|
|
}
|