Skip to content

Instantly share code, notes, and snippets.

@jay-w-opus
Created February 15, 2020 06:55
Show Gist options
  • Save jay-w-opus/ee8c2e644cd87e533edc39e5db27215c to your computer and use it in GitHub Desktop.
Save jay-w-opus/ee8c2e644cd87e533edc39e5db27215c to your computer and use it in GitHub Desktop.
Tempermoney: 2x or 3x while pressing down a key in Youtube
// ==UserScript==
// @name Speed up video
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.youtube.com/watch?*
// @grant none
// ==/UserScript==
(function() {
function getSpeed() { return document.getElementsByClassName('html5-main-video')[0].playbackRate };
function setSpeed(rate) { document.getElementsByClassName('html5-main-video')[0].playbackRate = rate };
var speed = getSpeed();
var prevSpeed = getSpeed();
var override = false;
document.onkeydown = function(e) {
if (e.which == 221){ // ']' key
if (!override) {
override = true;
console.log('KeyDown! Speed 2x');
prevSpeed = getSpeed();
setSpeed(2);
}
}
if (e.which == 220){ // '\' key
if (!override) {
override = true;
console.log('KeyDown! Speed 3x');
prevSpeed = getSpeed();
setSpeed(3);
}
}
}
document.onkeyup = function(e) {
if (e.which == 221 || e.which == 220) {
if (override) {
override = false;
console.log('Keyup! Resume prev speed');
setSpeed(prevSpeed);
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment