arvidnilber / Better HBO Nordic player

// ==UserScript==
// @name         Better HBO Nordic player
// @namespace    http://tampermonkey.net/
// @version      0.3.4
// @description  Adds keyboard commands to HBO Nordics shitty video-js player
// @author       Arvid Nilber
// @match        https://*.hbonordic.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {

  function playPause(videoPlayer) {
    if (videoPlayer.paused()) {
      videoPlayer.play();
    }
    else {
      videoPlayer.pause();
    }

  }

  function handleFullscreen(videoPlayer) {
    if (!videoPlayer.isFullscreen()) {
      videoPlayer.requestFullscreen();
    }
    else {
      videoPlayer.exitFullscreen();
    }
  }

  function muteAudio(videoPlayer) {
    if (videoPlayer.volume === 0) {
      videoPlayer.volume = 0.8
    }
    else {
      videoPlayer.volume = 0
    }
  }

  document.addEventListener('keydown', handleKeyPress);

  function handleKeyPress(e) {
    const videoElements = document.getElementsByTagName("video");
    const video = videoElements[0];
    const videoPlayer = videojs(video.id);
    switch (e.code) {
      case "Space":
        playPause(videoPlayer);
        break;
      case "Enter":
        playPause(videoPlayer);
        break;
      case "ArrowUp":
        video.volume += 0.1;
        break;
      case "ArrowDown":
        video.volume -= 0.1;
        break;
      case "KeyF":
        handleFullscreen(videoPlayer);
        break;
      case "ArrowLeft":
        videoPlayer.currentTime(videoPlayer.currentTime() - 10);
        break;
      case "ArrowRight":
        videoPlayer.currentTime(videoPlayer.currentTime() + 10);
        break;
      case "KeyM":
        muteAudio(video);
        break;

    }
  }

})();