Skip to content

Instantly share code, notes, and snippets.

@vogler
Created June 13, 2018 20:07
Show Gist options
  • Save vogler/905e2ad27482eda60b1b8b0f0831e027 to your computer and use it in GitHub Desktop.
Save vogler/905e2ad27482eda60b1b8b0f0831e027 to your computer and use it in GitHub Desktop.
Tampermonkey: YouTube: scroll=seek in fullscreen
// ==UserScript==
// @name YouTube: scroll=seek in fullscreen
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Scrolling a youtube video in fullscreen seeks back/forward
// @author Ralf Vogler
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// seek back/forward `step` seconds
const step = 3;
// This should work for any video, so maybe generalize it...
// However, for performance reasons we should then abort if there's no video element and add/remove the wheel listener on fullscreenchange.
const v = document.getElementsByTagName('video')[0];
document.addEventListener('wheel', function(e){
// const dir = e.wheelDeltaY > 0 ? 'up' : 'down';
// console.log("wheel", dir);
if(document.webkitIsFullScreen) { // https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API#Prefixing
// console.log("fullscreen");
v.currentTime += step * Math.sign(e.wheelDeltaY);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment