Markussss / Youtube video binary search

// ==UserScript==
// @namespace       https://openuserjs.org/users/Markussss
// @name            Youtube video binary search
// @description     Allows you (probably just me) to perform a binary search in a Youtube video, in order to quickly find where in the video you (me) were before falling asleep. Controls: i => I haven't seen this, go back; o => I have seen this, go forward.
// @copyright       2018, Markussss (https://openuserjs.org/users/Markussss)
// @license         MIT
// @version         1
// @include         https://www.youtube.com/watch?*
// @grant none
// ==/UserScript==

// ==OpenUserJS==
// @author Markussss
// ==/OpenUserJS==

const video = document.querySelector('video')

var left = 0
var right = video.duration

document.addEventListener('keydown', e => {
  if (![73, 79].includes(e.keyCode)) {
    return
  }
  if (e.keyCode === 73) {
    right = video.currentTime
  }
  else if (e.keyCode === 79) {
    left = video.currentTime
  }
  video.currentTime = halfBetween(left, right)
})

function halfBetween(a, b) {
  if (a > b) {
    [a, b] = [b, a]
  }
  return a + ((b - a) / 2)
}