rcvd

A JS library and a KaiOS 2.5.x application for BLE-enabled Casio watch time synchronization
git clone git://git.luxferre.top/rcvd.git
Log | Files | Refs | README | LICENSE

app.js (1386B)


      1 addEventListener('DOMContentLoaded', _ => {
      2 
      3   var fmt2 = n => ('0'+n).slice(-2),
      4     tElem = document.getElementById('timeline'),
      5     dElem = document.getElementById('dateline'),
      6     sElem = document.getElementById('status'),
      7     upd = function() {
      8       var now = new Date()
      9       tElem.textContent = [now.getHours(), now.getMinutes(), now.getSeconds()].map(fmt2).join(':')
     10       dElem.textContent = [now.getFullYear()].concat([now.getMonth()+1, now.getDate()].map(fmt2)).join('-')
     11       setTimeout(upd, 1000)
     12     }, runSync = function() {
     13       sElem.textContent = 'Connecting...'
     14       RCVD.disconnect()
     15       RCVD.connect().then(mode => {
     16         var model = RCVD.getModel()
     17         console.log('Main setting mode:', mode)
     18         sElem.textContent = 'Syncing ' + model
     19         RCVD.sync().then(_ => {
     20           sElem.textContent = model + ' synced'
     21           RCVD.disconnect()
     22         }).catch(e => {console.error(e)})
     23       }).catch(e => {
     24         sElem.textContent = 'Failed, please retry!'
     25         console.error(e)
     26       })
     27     }
     28 
     29   addEventListener('keydown', e => {
     30     if(e.key === 'MicrophoneToggle')
     31       e.preventDefault()
     32     else if(e.key === 'Enter') {
     33       e.preventDefault()
     34       e.stopPropagation()
     35       runSync()
     36     }
     37   })
     38 
     39   addEventListener('click', e => {
     40     if(e.target.id === 'syncbtn') {
     41       e.preventDefault()
     42       runSync()
     43     }
     44   })
     45 
     46   upd()
     47 })