EventTimer and Double Tap

by Chris

HTML

<p id='main'></p>
<iframe width="400" height="400" src="https://www.youtube.com/embed/BZPdi9SNGEM" title="Freddie Dredd - Suffer" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

JavaScript

var previous_time = window.performance.timeOrigin
var previous_key;
var delay;
var interval;
function whenKeyIsPressed(ev) {
  let k = ev.key
  delay = Date.now() - previous_time;
  previous_time = Date.now();
  valid_delay = delay <= 300 ? true : false;
  console.log("delay: ", delay);
  console.log("Constraints: ", valid_delay)
  if (k == "x" && valid_delay == true) {
    interval = setInterval(() => timestampManager, 3000)
    console.log("Delay was less than 300 and previous key was x")
    alert("test")
  }
	if (k == "c" && valid_delay == true) {
		clearInterval(interval)
	}
  previous_key = k
}
document.addEventListener("keydown", whenKeyIsPressed)

var count = 0
function timestampManager() {
  goToDuration(timestamps_rounded[++count])
  if (timestamps_rounded.length >= count) {
    count = 0
  }
}

var timestamps_rounded = JSON.parse(localStorage.getItem("ts_key")).map((e) => Math.floor(e * 10) / 10).sort((a, b) => a - b)

document.querySelector("p").innerHTML = 'key'

function timestampManager() {
  goToDuration(timestamps_rounded[++count])
}
if (timestamps_rounded.length >= count) {
  count = 0
}

var timestamp_arr = [
  609.275133, 609.782755, 616.008102, 625.397308, 634.153309, 658.131372,
  684.967107, 693.090255, 703.627355, 735.415784, 748.367227, 784.026223,
  793.168436, 814.411698, 834.700957, 855.510203, 869.09078, 14.479936,
  21.787051, 27.713006, 33.973211, 43.314559, 49.613221, 57.260222, 65.267354,
  72.089609, 76.86334, 84.821175, 93.288593, 100.315383, 116.963783, 130.938153,
  140.71487, 150.637874, 164.477357, 179.514318, 185.216038, 190.534012,
  198.239788, 204.037381, 211.193285, 221.677994, 229.155556, 245.993634,
  272.466407, 280.881742, 291.122417, 300.996218, 324.283599, 330.066792,
  379.204857, 387.540323, 394.272237, 400.010462, 402.875107, 407.417925,
  413.236083, 422.922237, 446.82736, 450.469134, 506.242077, 523.402873,
  609.82778, 616.019982, 625.744904, 634.867318,...