summaryrefslogtreecommitdiff
path: root/static/kys-link-info.js
blob: 18a0a2329ed3d94486601b249ce83ea872d35198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const kysLink = document.getElementById("kysLink")
kysLink.onclick = () => {
    const link = kysLink.innerHTML
    navigator.clipboard.writeText(link)
    const linkInfo = document.createElement("div")
    linkInfo.className = 'kysInfo'
    const linkText = document.createTextNode( 
            "Linkki " + link + " on kopioitu leikepöydälle." )
    linkInfo.appendChild( linkText )
    document.documentElement.lastChild.append(linkInfo)
}

setInterval( () => {
    Array.from(document.getElementsByClassName('kysInfo')).forEach( (a)=>{
        a.addEventListener('click', (event) => { event.target.remove() } )
        if ( a.state == undefined ) a.state = 0
        if (a.state == 4) {
            a.style.transition = "opacity 1s"
            a.style.opacity = 0
        }
        if (a.state == 5) a.remove()
        a.state += 1
    } )
}, 1000)