Enhanced Invidious Player

Adds hotkeys and more to invidious player.

// ==UserScript==
// @name Enhanced Invidious Player
// @version 1.3.0
// @author NotYou
// @description Adds hotkeys and more to invidious player.
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAKaElEQVRo3r1aSWwb5xX+/n/ImeFiStZCLRTlRaIoUYutOHbs2LJTJwUKI20kk0KDJDaQQ3vJoTkk3Y8p0LTopT0VQVAgQOwspNXWByOHprYWO0ZtRQ7pkWHYsSSSokRS1EJRIjXD/+/Blmpbiy1x0ncZgPP+9973vjf/8n4S6CidnZ0CACvnvOjBU3rwKkcImSeEzBFC5nt6ejS9fJJCBnu9XprP5+0AWimlzxqNxhZJknZIklQmSZJFEAQjAOTzeXVpaWkhm81O5XK5UVVVQ4yxawC+EQRhMhAIsP8rAK/Xa2aMPScIQte2bdu+V1lZWed0Ok01NTUoKyuDzWaDLMsQBAGEEGiahlwuh7m5OSSTSUSjUYyNjWUnJibupdPpi5qm9VBKrwQCgfnvFIDP5zPl8/mXJEn6aXV19dHW1lZbS0sLHA4HzGYzKKUrupzzRx0RsvJkjGFhYQHj4+MIhUIIBoPz0Wi0P5vNfiAIwhd+vz+jK4DTp0+T+fn5PQaD4edOp/NHhw8ftrS3t6OkpASEEHDOVwX8RMeErIydmZnB0NAQBgYGFkZHRy+oqvq+yWS69vHHHz/R6BMBdHd3y/l8/vT27dt/ffjw4R0vvPACysrKthT0k8CkUin09vair68vmkql3qeUfvj5558vbDRW2Oilz+crBfDe7t27f/Pqq6+WHT16FBaLRbfAHxbOOUwmE9xuN2pra22JROL49PR0pcfj+Y+iKOuW1LoAfD5fJaX0z3v27Hnz1KlTYn19ve5Bryd2ux1ut9swMzPzzOTkpKupqemyoihzTw3A5/OVU0r/sn///h+//vrrp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9/om1dNdtfiuKkvF4PBfj8bjh7t27e202m2i323U7/K8ly5d+oVAIZ86cWRweHv4r5/wXfr9/cr0xG3bvFUXJtrS09KZSqbFbt261pNPpkuXzrp4nK0IIKKVIJpO4cOECzp8/PzI+Pv5bSumf/H7/3IZjn9bJyZMnmwVBeMfhcJw8dOiQbd++fSgrKwOltOBr1qmpKQwODuLKlSvz4XD4n5qm/dFqtd746KOPCr9mfVh8Pp+Uz+ePiaL4k8rKypeam5uLW1tb4XQ6YbFYIAj/I3S9i27g/sYuk8kgEokgFAohFArNxmKxi7lc7gNBEL70+/2LT52ITaXtgXi9Xpkxto9S+orVan2poqLC5XA4rDU1NSgvL0dRURFkWV5Z1DRNQzabxdzcHBKJBKLRKCKRSGZycvLu/Pz8v/L5/N8ppdcCgcDCZmMpqJC7u7uJpmmlnHMPIeQZo9HYJoriTkmSykVRND/0Zw9NVdWFXC6XzOVyI6qqfsM5HySEKIIgJPx+/5anN117HJ2dnRSAmXO+jXNuBrC8r9AIIYuEkDQhJNPT06Pbne1/Acmz+r5w/zPmAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE5LTA0LTE0VDEzOjEwOjM5LTA0OjAwzYrzKwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOS0wNC0xNFQxMzoxMDozOS0wNDowMLzXS5cAAAAASUVORK5CYII=
// @namespace -
// @include *invidious.snopyta.org/watch?v=*
// @include *yewtu.be/watch?v=*
// @include *uptime.invidious.io/784257752watch?v=*
// @include *invidious.kavin.rocks/watch?v=*
// @include *vid.puffyan.us/watch?v=*
// @include *invidious.namazso.eu/watch?v=*
// @include *inv.riverside.rocks/watch?v=*
// @include *invidious.osi.kr/watch?v=*
// @include *youtube.076.ne.jp/watch?v=*
// @include *yt.artemislena.eu/watch?v=*
// @include *tube.cthd.icu/watch?v=*
// @include *invidious.flokinet.to/watch?v=*
// @include *invidious.weblibre.org/watch?v=*
// @include *invidious.esmailelbob.xyz/watch?v=*
// @include *invidious.lunar.icu/watch?v=*
// @include *invidious.mutahar.rocks/watch?v=*
// @include *inv.bp.projectsegfau.lt/watch?v=*
// @include *y.com.sb/watch?v=*
// @include *invidious.sethforprivacy.com/watch?v=*
// @include *invidious.tiekoetter.com/watch?v=*
// @license GPL-3.0-or-later
// @run-at document-end
// @grant none
// ==/UserScript==

let vid = document.querySelector('video'),
    par = document.querySelector('#contents'),
    diff = 0.021,
    skip = 60

vid.focus()

// SCROLL //

vid.addEventListener('mouseenter', () => {
	vid.focus()
  document.documentElement.style.overflow = 'hidden'
})

vid.addEventListener('mouseleave', () => {
  document.documentElement.style.overflow = 'unset'
})

vid.addEventListener('wheel', e => {
	if (e.deltaY >= 0) {
  	vid.volume >= 0
    	? vid.volume -= diff
    	: vid.volume = 0
  } else if (e.deltaY < 0) {
    if (vid.muted === true) vid.muted = false
    vid.volume < 1
    	? vid.volume += diff
    	: vid.volume = 1
  }
})

// HOTKEYS //

vid.addEventListener('keydown', e => {
  if (e.key === 'm') vid.muted = vid.muted === false ? true : false
  if (e.key === 'r') vid.loop = vid.loop === false ? true : false
  if (e.key === 't') par.style.width = par.style.width === '' ? '100%' : ''
  if (e.key === 'c') {
    if (e.ctrlKey === true) navigator.clipboard.writeText(vid.currentSrc)
    else navigator.clipboard.writeText(JSON.parse(document.querySelector('#player_data').textContent.replaceAll('\n', '')).title)
  }
  if (e.key === 'ArrowRight') if (e.ctrlkey === true) if (vid.currentTime+skip < vid.duration) vid.currentTime += skip
  if (e.key === 'ArrowLeft') if (e.ctrlkey === true) if (vid.currentTime-skip > 0) vid.currentTime -= skip
  if (e.key === 'f') {
    let el = document.querySelector('div#player') || vid
  	if (el.requestFullscreen) el.requestFullscreen()
  	else if (el.webkitRequestFullscreen) el.webkitRequestFullscreen()
  	else if (el.msRequestFullscreen) el.msRequestFullscreen()
  }
  if (e.code === 'Numpad0' || e.code === 'Numpad1') rateTo(1)
  if (e.code === 'Numpad2') rateTo(2)
  if (e.code === 'Numpad3') rateTo(2.5)
  if (e.code === 'Numpad4') rateTo(3)
})

// FUNCS

function rateTo(n) {
  vid.playbackRate = n
}