(message,secondsLeft,cancelable,callback)
| 12 | style.textContent="p{font-size:1rem}" |
| 13 | document.head.appendChild(style) |
| 14 | const timer=(message,secondsLeft,cancelable,callback)=>{ |
| 15 | if(secondsLeft>=0) |
| 16 | { |
| 17 | const div=document.getElementById("timer"), |
| 18 | tid=setInterval(()=>{ |
| 19 | secondsLeft-- |
| 20 | tick() |
| 21 | },1000), |
| 22 | p=div.querySelector("p"), |
| 23 | brws=(typeof browser=="undefined"?chrome:browser), |
| 24 | cancel=()=>{ |
| 25 | clearInterval(tid) |
| 26 | titleElm.textContent=title |
| 27 | div.classList.add("uk-hidden") |
| 28 | }, |
| 29 | tick=()=>{ |
| 30 | if(secondsLeft<=0) |
| 31 | { |
| 32 | cancel() |
| 33 | callback() |
| 34 | return |
| 35 | } |
| 36 | titleElm.textContent="("+secondsLeft+") "+title |
| 37 | if(secondsLeft==1) |
| 38 | { |
| 39 | p.textContent=brws.i18n.getMessage(message+"Singular")+" " |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | p.textContent=brws.i18n.getMessage(message).replace("%",secondsLeft)+" " |
| 44 | } |
| 45 | if(cancelable) |
| 46 | { |
| 47 | let a=document.createElement("a") |
| 48 | a.href="#" |
| 49 | a.onclick=cancel |
| 50 | a.textContent=brws.i18n.getMessage("cancel") |
| 51 | p.appendChild(a) |
| 52 | } |
| 53 | } |
| 54 | div.classList.remove("uk-hidden") |
| 55 | tick() |
| 56 | return tid |
| 57 | } |
| 58 | } |
no test coverage detected