<commit_before># Pull-in the Mousetrap lib.
require './../../lib/mousetrap/mousetrap'

EyeJS = require '/Users/josh/work/eyejs'

eyejs = new EyeJS()

vscroll = require 'vscroll'

_ = require 'lodash'

recorder = require '/Users/josh/Dropbox/eyejs-trial/recorder/dist/recorder-client'

recordEyeEvent = (type, e) ->
  msg =
    event:   type
    element: recorder.serializeNode e
  recorder.send msg

eyejs.on 'blink', (e) ->
  recordEyeEvent 'blink', e

eyejs.on 'fixation', (e) ->
  recordEyeEvent 'fixation', e

eyejs.on 'fixationend', (e) ->
  recordEyeEvent 'fixationend', e

eyejs.on 'gaze', (e) ->
  e.event = 'gaze'
  e.el    = recorder.serializeNode e.el
  recorder.send e


# Scroller
# window.addEventListener 'load', ->
#
#   eyejs.on 'gaze', _.throttle (e) ->
#     MAX_VELOCITY = 900
#     THRESHOLD = 150
#     EDGE_FUZZ = 30
#     if e.y >= -EDGE_FUZZ and e.y < THRESHOLD
#       q = (THRESHOLD - e.y) / THRESHOLD
#       v = q * MAX_VELOCITY
#       vscroll.velocity 0, -v
#     else if e.y > window.innerHeight - THRESHOLD and e.y < window.innerHeight + EDGE_FUZZ
#       q = (e.y - window.innerHeight + THRESHOLD) / THRESHOLD
#       v = q * MAX_VELOCITY
#       vscroll.velocity 0, v
#     else
#       vscroll.velocity 0, 0
#   , 200


chrome.storage.local.get 'config', (storage = {}) ->
  config  = storage.config
  enabled = if config.enabled? then config.enabled else eyejs.enabled
  size    = if config.size?    then config.size    else eyejs.indicator.size
  opacity = if config.opacity? then config.opacity else eyejs.indicator.opacity()

  if enabled then eyejs.enable()
  eyejs.indicator.resize size
  eyejs.indicator.opacity opacity


getStatus = ->
  return {
    enabled:  eyejs.enabled
    size:     eyejs.indicator.size
    opacity:  eyejs.indicator.opacity()
  }


updateSettings = ->
  chrome.storage.local.set 'config': getStatus()



forwardBackShowTimer = null

showForwardBackButtons = (e) ->
  if e.x >= 10 and e.x <= window.innerWidth - 10 then return
  back = document.getElementById('eyejs-back')
  forward = document.getElementById('eyejs-forward')
  if !back or !forward then return
  if e.x < 10
    back.classList.add('eyejs-show')
  else if e.x > window.innerWidth - 10
    forward.classList.add('eyejs-show')
  resetForwardBackButtonTimer()

hideForwardBackButtons = ->
  back = document.getElementById('eyejs-back')
  forward = document.getElementById('eyejs-forward')
  if !back or !forward then return
  back.classList.remove('eyejs-show')
  forward.classList.remove('eyejs-show')

resetForwardBackButtonTimer = ->
  clearTimeout forwardBackShowTimer
  forwardBackShowTimer = setTimeout hideForwardBackButtons, 2000

addForwardBackButtons = ->
  fwd  = document.createElement 'div'
  back = document.createElement 'div'
  fwd.id = 'eyejs-forward'
  back.id = 'eyejs-back'
  fwd.setAttribute 'data-eyejs-snap', ''
  back.setAttribute 'data-eyejs-snap', ''
  document.body.appendChild fwd
  document.body.appendChild back
  fwd.addEventListener 'gaze', resetForwardBackButtonTimer
  back.addEventListener 'gaze', resetForwardBackButtonTimer
  fwd.addEventListener 'click', -> window.history.forward()
  back.addEventListener 'click', -> window.history.back()
  eyejs.on 'gaze', showForwardBackButtons

window.addEventListener 'load', addForwardBackButtons




scrollBarShowTimer = null

showScrollBars = (e) ->
  if e.y > 10 and e.y <= window.innerHeight - 10 then return
  up = document.getElementById('eyejs-scroll-up')
  down = document.getElementById('eyejs-scroll-down')
  if !up or !down then return
  if e.y < 10<commit_msg>- Changed zIndex of forward and back buttons.<commit_after># Pull-in the Mousetrap lib.
require './../../lib/mousetrap/mousetrap'

EyeJS = require '/Users/josh/work/eyejs'

eyejs = new EyeJS()

vscroll = require 'vscroll'

_ = require 'lodash'

recorder = require '/Users/josh/Dropbox/eyejs-trial/recorder/dist/recorder-client'

recordEyeEvent = (type, e) ->
  msg =
    event:   type
    element: recorder.serializeNode e
  recorder.send msg

eyejs.on 'blink', (e) ->
  recordEyeEvent 'blink', e

eyejs.on 'fixation', (e) ->
  recordEyeEvent 'fixation', e

eyejs.on 'fixationend', (e) ->
  recordEyeEvent 'fixationend', e

eyejs.on 'gaze', (e) ->
  e.event = 'gaze'
  e.el    = recorder.serializeNode e.el
  recorder.send e


# Scroller
# window.addEventListener 'load', ->
#
#   eyejs.on 'gaze', _.throttle (e) ->
#     MAX_VELOCITY = 900
#     THRESHOLD = 150
#     EDGE_FUZZ = 30
#     if e.y >= -EDGE_FUZZ and e.y < THRESHOLD
#       q = (THRESHOLD - e.y) / THRESHOLD
#       v = q * MAX_VELOCITY
#       vscroll.velocity 0, -v
#     else if e.y > window.innerHeight - THRESHOLD and e.y < window.innerHeight + EDGE_FUZZ
#       q = (e.y - window.innerHeight + THRESHOLD) / THRESHOLD
#       v = q * MAX_VELOCITY
#       vscroll.velocity 0, v
#     else
#       vscroll.velocity 0, 0
#   , 200


chrome.storage.local.get 'config', (storage = {}) ->
  config  = storage.config
  enabled = if config.enabled? then config.enabled else eyejs.enabled
  size    = if config.size?    then config.size    else eyejs.indicator.size
  opacity = if config.opacity? then config.opacity else eyejs.indicator.opacity()

  if enabled then eyejs.enable()
  eyejs.indicator.resize size
  eyejs.indicator.opacity opacity


getStatus = ->
  return {
    enabled:  eyejs.enabled
    size:     eyejs.indicator.size
    opacity:  eyejs.indicator.opacity()
  }


updateSettings = ->
  chrome.storage.local.set 'config': getStatus()



forwardBackShowTimer = null

showForwardBackButtons = (e) ->
  if e.x >= 10 and e.x <= window.innerWidth - 10 then return
  back = document.getElementById('eyejs-back')
  forward = document.getElementById('eyejs-forward')
  if !back or !forward then return
  if e.x < 10
    back.classList.add('eyejs-show')
  else if e.x > window.innerWidth - 10
    forward.classList.add('eyejs-show')
  resetForwardBackButtonTimer()

hideForwardBackButtons = ->
  back = document.getElementById('eyejs-back')
  forward = document.getElementById('eyejs-forward')
  if !back or !forward then return
  back.classList.remove('eyejs-show')
  forward.classList.remove('eyejs-show')

resetForwardBackButtonTimer = ->
  clearTimeout forwardBackShowTimer
  forwardBackShowTimer = setTimeout hideForwardBackButtons, 2000

addForwardBackButtons = ->
  fwd  = document.createElement 'div'
  back = document.createElement 'div'
  fwd.id = 'eyejs-forward'
  back.id = 'eyejs-back'
  fwd.setAttribute 'data-eyejs-snap', ''
  back.setAttribute 'data-eyejs-snap', ''
  fwd.style.zIndex = 1000000
  back.style.zIndex = 1000000
  document.body.appendChild fwd
  document.body.appendChild back
  fwd.addEventListener 'gaze', resetForwardBackButtonTimer
  back.addEventListener 'gaze', resetForwardBackButtonTimer
  fwd.addEventListener 'click', -> window.history.forward()
  back.addEventListener 'click', -> window.history.back()
  eyejs.on 'gaze', showForwardBackButtons

window.addEventListener 'load', addForwardBackButtons




scrollBarShowTimer = null

showScrollBars = (e) ->
  if e.y > 10 and e.y <= window.innerHeight - 10 then return
  up = document.getElementById('eyejs-scroll-up')
  down = document.getElementById('eyejs-scroll-down')
  if !up or !down then return
  if e.y < 10
{'fraction_non_alphanumeric': 0.1251550654720882, 'fraction_numerical': 0.011026878015161957, 'mean_word_length': 3.457002457002457, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '220549', 'n_tokens_mistral': 2587, 'n_tokens_neox': 2445, 'n_words': 564}