37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
(() => {
|
|
'use strict'
|
|
|
|
const tokenPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
const status = document.getElementById('invite-status')
|
|
const fingerprint = document.getElementById('token-fingerprint')
|
|
const error = document.getElementById('invite-error')
|
|
const openApp = document.getElementById('open-app')
|
|
const copyLink = document.getElementById('copy-link')
|
|
const token = new URLSearchParams(window.location.search).get('token')?.trim() ?? ''
|
|
|
|
if (!tokenPattern.test(token)) {
|
|
status.textContent = '사용할 수 없는 링크'
|
|
status.dataset.state = 'invalid'
|
|
error.textContent = '초대 링크가 없거나 형식이 올바르지 않아. 새 초대 링크를 요청해.'
|
|
error.hidden = false
|
|
return
|
|
}
|
|
|
|
status.textContent = '형식 검증 완료 · 서버 확인 대기'
|
|
status.dataset.state = 'valid'
|
|
fingerprint.textContent = `${token.slice(0, 8)}…${token.slice(-4)}`
|
|
openApp.href = `d3ro-voice://accept-invite?token=${encodeURIComponent(token)}`
|
|
openApp.removeAttribute('aria-disabled')
|
|
copyLink.disabled = false
|
|
|
|
copyLink.addEventListener('click', async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(window.location.href)
|
|
copyLink.textContent = '복사했어'
|
|
window.setTimeout(() => { copyLink.textContent = '초대 링크 복사' }, 1800)
|
|
} catch {
|
|
error.textContent = '브라우저가 복사를 허용하지 않았어. 주소 표시줄에서 링크를 직접 복사해.'
|
|
error.hidden = false
|
|
}
|
|
})
|
|
})()
|