my eye

Lint javascript

Committed 09a00d

--- a/canopy/static/enliven.js
+++ b/canopy/static/enliven.js

-import { _, go, upgradeLink } from '/static/web.js'
+import { _, go, upgradeLink } from 'static/web.js'  // eslint-disable-line
 
 let mode = 'site'
 const konamiCode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13]
   }
   document.documentElement.className = currentColorMode
 
-  const navDiv = document.querySelector("body > nav div")
-  navDiv.innerHTML = `<button id=join>Join Room</button>` + navDiv.innerHTML
+  const navDiv = document.querySelector('body > nav div')
+  navDiv.innerHTML = '<button id=join>Join Room</button>' + navDiv.innerHTML
 
   search.innerHTML =
     `<svg id=colormode title="switch dark/light color mode" viewBox="-0.5 0 25 25"
         C20.5,16.6944204 16.6944204,20.5 12,20.5 Z"></path>
     </svg>
     <svg id=listen title=dictation viewBox="-0.5 0 25 25"
-      fill=none xmlns=http://www.w3.org/2000/svg></svg>`
-    + search.innerHTML
+      fill=none xmlns=http://www.w3.org/2000/svg></svg>` +
+    search.innerHTML
 
   microphoneStatus('off')
   colormode.onmouseup = toggleColorMode
   join.onmouseup = initChat
 
   _('a:not(.breakout)').each(upgradeLink)
-  history.pushState({scroll: 0}, 'title', window.location)
+  history.pushState({ scroll: 0 }, 'title', window.location)
   window.go = go
 
   const client = new WebTorrent()
     })
   })
 
-  if (Cookies.get('rhythm') == 'on') {
+  if (Cookies.get('rhythm') === 'on') {
     document.querySelector('body').style.backgroundImage = 'url(/static/measure.png)'
   }
   Cookies.set('mediasoup-demo.user', `{"displayName": "${userName}"}`)
 
   document.addEventListener('keydown', ev => {
-    if (mode == 'room') {
+    if (mode === 'room') {
       switch (ev.key) {
-        case 'w': break                              // w   TODO walk forward
-        case 'a': break                              // a   TODO strafe left
-        case 's': break                              // s   TODO walk backward
-        case 'd': break                              // d   TODO strafe right
-        case 'h': break                              // h   TODO pan left
-        case 'j': break                              // j   TODO scroll map down
-        case 'k': break                              // k   TODO scroll map up
-        case 'l': break                              // l   TODO pan right
+        case 'w': break // w   TODO walk forward
+        case 'a': break // a   TODO strafe left
+        case 's': break // s   TODO walk backward
+        case 'd': break // d   TODO strafe right
+        case 'h': break // h   TODO pan left
+        case 'j': break // j   TODO scroll map down
+        case 'k': break // k   TODO scroll map up
+        case 'l': break // l   TODO pan right
       }
       return
     }
-    if (ev.target.tagName == 'INPUT' || ev.target.tagName == 'TEXTAREA')
-      return
-    if (konamiCode.indexOf(ev.keyCode) != -1) {
+    if (ev.target.tagName === 'INPUT' || ev.target.tagName === 'TEXTAREA') { return }
+    if (konamiCode.indexOf(ev.keyCode) !== -1) {
       konamiCodeFIFO = konamiCodeFIFO.slice(1).concat(ev.keyCode)
-      if (JSON.stringify(konamiCodeFIFO) == konamiCodeJSON) {
+      if (JSON.stringify(konamiCodeFIFO) === konamiCodeJSON) {
         return
       }
     }
     if (following) {
-      if (ev.key == 'Escape') {
+      if (ev.key === 'Escape') {
         hideFollowLinks()
         return
       }
-      if (['Shift', 'Alt', 'Control', 'Tab'].indexOf(ev.key) != -1)
-        return
+      if (['Shift', 'Alt', 'Control', 'Tab'].indexOf(ev.key) != -1) { return }
       followQueue += ev.key.toLowerCase()
       if (followList.hasOwnProperty(followQueue)) {
         go(followList[followQueue])
       }
       return
     }
-    if (ev.altKey && ev.key == '.') {                // A-. toggle rhythm indicator
-      if (Cookies.get('rhythm') == 'on') {
+    if (ev.altKey && ev.key === '.') { // A-. toggle rhythm indicator
+      if (Cookies.get('rhythm') === 'on') {
         document.querySelector('body').style.backgroundImage = 'none'
         Cookies.set('rhythm', 'off')
       } else {
         document.querySelector('body').style.backgroundImage = 'url(/static/measure.png)'
         Cookies.set('rhythm', 'on')
       }
-    } else if (ev.altKey && ev.key == 'c') {         // A-c toggle color mode
+    } else if (ev.altKey && ev.key === 'c') { // A-c toggle color mode
       toggleColorMode()
     } else {
       switch (ev.key) {
-        case '?': showGuide(); break                 // ?   show the site guide
-        case 'q': focusQuery(ev); break              // q   focus query input
-        case 'f': showKeyboardFollowLinks(); break   // f   show "follow links"
-        case 'm': goHome(); break                    // m   go home
-        case 'd': close(); break                     // d   close page
-        case 'r': reload(); break                    // r   reload page
-        case 'h': goBack(); break                    // h   go back
-        case 'j': scrollDown(); break                // j   scroll down 3 EMs
-        case 'k': scrollUp(); break                  // k   scroll up 3 EMs
-        case 'l': goForward(); break                 // l   go forward
-        case 'u': goUp(); break                      // u   follow rel=up
-        case 'p': goPrevious(); break                // p   follow rel=prev
-        case 'n': goNext(); break                    // n   follow rel=next
-        case '[': pageUp(); break                    // [   scroll page up
-        case ']': pageDown(); break                  // ]   scroll page down
-        case '{': scrollTop(); break                 // {   scroll to top
-        case '}': scrollBottom(); break              // }   scroll to bottom
+        case '?': showGuide(); break // show the site guide
+        case 'q': focusQuery(ev); break // focus query input
+        case 'f': showKeyboardFollowLinks(); break // show "follow links"
+        case 'm': goHome(); break // go home
+        case 'd': close(); break // close page
+        case 'r': reload(); break // reload page
+        case 'h': goBack(); break // go back
+        case 'j': scrollDown(); break // scroll down 3 EMs
+        case 'k': scrollUp(); break // scroll up 3 EMs
+        case 'l': goForward(); break // go forward
+        case 'u': goUp(); break // follow rel=up
+        case 'p': goPrevious(); break // follow rel=prev
+        case 'n': goNext(); break // follow rel=next
+        case '[': pageUp(); break // scroll page up
+        case ']': pageDown(); break // scroll page down
+        case '{': scrollTop(); break // scroll to top
+        case '}': scrollBottom(); break // scroll to bottom
       }
     }
   }, false)
   document.querySelector('input[name=q]').focus()
   ev.preventDefault()
 }
-const goHome = () => { go(document.querySelector("a[rel=home]").href) }
+const goHome = () => { go(document.querySelector('a[rel=home]').href) }
 const close = () => { window.close() }
 const reload = () => { window.location.reload() }
-const goUp = () => { go(document.querySelector("a[rel=up]").href) }
-const goPrevious = () => { go(document.querySelector("a[rel=prev]").href) }
-const goNext = () => { go(document.querySelector("a[rel=next]").href) }
+const goUp = () => { go(document.querySelector('a[rel=up]').href) }
+const goPrevious = () => { go(document.querySelector('a[rel=prev]').href) }
+const goNext = () => { go(document.querySelector('a[rel=next]').href) }
 const goBack = () => { history.back() }
 const goForward = () => { history.forward() }
 const scrollDown = () => { document.documentElement.scrollTop += 3 * em }
     let combination = ''
     while (true) {
       combination = ''
-      for (let i = 0; i < combinationLength; i++)
-        combination += characters.charAt(Math.floor(Math.random() * characters.length))
+      for (let i = 0; i < combinationLength; i++) { combination += characters.charAt(Math.floor(Math.random() * characters.length)) }
       if (!followList.hasOwnProperty(combination)) break
     }
     followList[combination] = link.href
 
 const toggleColorMode = () => {
   mode = 'dark'
-  if (document.documentElement.className == 'dark')
-    mode = 'light'
+  if (document.documentElement.className === 'dark') { mode = 'light' }
   Cookies.set('colormode', mode)
   document.documentElement.className = mode
 }
   const recognizer = new model.KaldiRecognizer(sampleRate)
   recognizer.setWords(true)
 
-  let wakeWord = 'ghost'
-  let readyWord = 'Say "ghost help"'
+  const wakeWord = 'ghost'
+  const readyWord = 'Say "ghost help"'
   let state = 'asleep'
   microphoneStatus('on')
   partialContainer.innerHTML = readyWord
 
   recognizer.on('result', message => {
     let input = message.result.text
-    if (following && input != '') {
+    if (following && input !== '') {
       let number = input.replace(' ', '')
-      if (number == 'for') number = 'four'
+      if (number === 'for') number = 'four'
       go(followList[number])
       hideFollowLinks()
       state = 'asleep'
       partialContainer.innerHTML = readyWord
       return
     }
-    if (input.slice(0, wakeWord.length) != wakeWord) {
+    if (input.slice(0, wakeWord.length) !== wakeWord) {
       partialContainer.innerHTML = readyWord
       return
     }
       partialContainer.innerHTML = ''
       return
     }
-    if (input == 'help') showGuide()                 // help
-    else if (input.startsWith('query for')) {        // query for
+    if (input === 'help') showGuide() // help
+    else if (input.startsWith('query for')) { // query for
       const query = input.slice(10)
       document.querySelector('input[name=q]').value = query
       go(`/search?q=${query}`)
-    } else if (input.startsWith('go')) {             // go
+    } else if (input.startsWith('go')) { // go
       switch (input.slice(3)) {
-        case 'home': goHome(); break                 //    home
-        case 'up': goUp(); break                     //    up
-        case 'prev': goPrevious(); break             //    prev
-        case 'next': goNext(); break                 //    next
-        case 'back': goBack(); break                 //    back
-        case 'forward': goForward(); break           //    forward
+        case 'home': goHome(); break //    home
+        case 'up': goUp(); break //    up
+        case 'prev': goPrevious(); break //    prev
+        case 'next': goNext(); break //    next
+        case 'back': goBack(); break //    back
+        case 'forward': goForward(); break //    forward
       }
-    } else if (input.startsWith('follow')) {         // follow
+    } else if (input.startsWith('follow')) { // follow
       showVoiceFollowLinks()
-    } else if (input.startsWith('tell me')) {        // tell me
+    } else if (input.startsWith('tell me')) { // tell me
       const request = input.slice(8)
-      const response = fetch('/ai/assistant', {
-          method: 'POST',
-          headers: {
-            'Content-Type': 'application/json',
-          },
-          body: JSON.stringify({request: request}),
+      fetch('/ai/assistant', {
+        method: 'POST',
+        headers: {
+          'Content-Type': 'application/json'
+        },
+        body: JSON.stringify({ request })
       })
-      .then(response => response.blob())
-      .then(blob => {
-        const audio = new Audio(URL.createObjectURL(blob));
-        audio.addEventListener('canplaythrough', () => {
-          state = 'asleep'
-          microphoneStatus('on')
-          audio.play()
+        .then(response => response.blob())
+        .then(blob => {
+          const audio = new Audio(URL.createObjectURL(blob))
+          audio.addEventListener('canplaythrough', () => {
+            state = 'asleep'
+            microphoneStatus('on')
+            audio.play()
           // partialContainer.value = readyWord
+          })
         })
-      })
     }
     partialContainer.innerHTML = `${input}`
   })
   recognizer.on('partialresult', message => {
     const input = message.result.partial
-    if (input.slice(0, wakeWord.length) != wakeWord)
-      return
+    if (input.slice(0, wakeWord.length) !== wakeWord) { return }
     state = 'awake'
     microphoneStatus('active')
     partialContainer.innerHTML = input.slice(wakeWord.length)
       noiseSuppression: true,
       channelCount: 1,
       sampleRate
-    },
+    }
   })
 
   const audioContext = new AudioContext()
   )
   recognizerProcessor.port.postMessage(
     { action: 'init', recognizerId: recognizer.id },
-    [ channel.port2 ]
+    [channel.port2]
   )
   recognizerProcessor.connect(audioContext.destination)
 
   tag.src = '/chats/mediasoup-demo-app.js'
   document.getElementsByTagName('head')[0].appendChild(tag)
 
-  const autoMuter = setInterval(autoMute, 100)
   const autoMute = () => {
     if (typeof window.CLIENT !== 'undefined' && window.CLIENT._micProducer) {
       window.CLIENT.muteMic()
       clearInterval(autoMuter)
     }
   }
+  const autoMuter = setInterval(autoMute, 100)
 }
 
 const numberToWords = num => {
-  if (num === 0)
-    return 'zero'
+  if (num === 0) { return 'zero' }
   const units = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
   const teens = ['eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
   const tens = ['', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
       return ''
     } else if (n < 10) {
       return units[n - 1] + ' '
-    } else if (n == 10) {
+    } else if (n === 10) {
       return 'ten'
     } else if (n < 20) {
       return teens[n - 11] + ' '
     } else if (n < 100) {
       return tens[Math.floor(n / 10)] + ' ' + convert(n % 10)
     } else {
-      return units[Math.floor(n / 100)-1] + ' hundred ' + convert(n % 100)
+      return units[Math.floor(n / 100) - 1] + ' hundred ' + convert(n % 100)
     }
   }
   return convert(num).trim()
 const microphoneStatus = mode => {
   let color
   let icon
-  if (mode == 'on' || mode == 'active') {
-    if (mode == 'on')
-      color = 'dc322f'
-    else if (mode == 'active')
-      color = '268bd2'
+  if (mode === 'on' || mode === 'active') {
+    if (mode === 'on') { color = 'dc322f' } else if (mode === 'active') { color = '268bd2' }
     icon = `<path d="
               M7 7.40991C7 6.08383 7.52677 4.81207 8.46445 3.87439C9.40213 2.93671
               10.6739 2.40991 12 2.40991C13.3261 2.40991 14.5978 2.93671 15.5355
               14.3869 22.4099 12 22.4099C9.61305 22.4099 7.32384 21.4618 5.63602
               19.7739C3.94819 18.0861 3 15.7969 3 13.4099"
               stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>`
-  } else if (mode == 'off' || mode == 'loading') {
-    if (mode == 'off') {
+  } else if (mode === 'off' || mode === 'loading') {
+    if (mode === 'off') {
       color = '93a1a1'
-      if (Cookies.get('colormode') == 'dark')
-        color = '586e75'
-    } else if (mode == 'loading')
-      color = '6c71c4'
+      if (Cookies.get('colormode') === 'dark') { color = '586e75' }
+    } else if (mode === 'loading') { color = '6c71c4' }
     icon = `<path d="
               M17.0005 11.24V13C17.0005 14.3261 16.4737 15.5978 15.536
               16.5355C14.5983 17.4732 13.3266 18 12.0005 18C11.4846 17.9975
               stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>`
   }
   listen.innerHTML = icon
-  document.querySelectorAll('#listen path').forEach(el => el.style.stroke = `#${color}`)
+  document.querySelectorAll('#listen path').forEach(el => { el.style.stroke = `#${color}` })
 }