Last active
November 3, 2018 12:12
-
-
Save un1t/69a5be184141f52602e8abf1e1a8eb5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Youtube playback rate hotkeys: | |
Ctrl + UP | |
Ctrl + DONW | |
*/ | |
function createPlaybackRateDisplay() { | |
var elem = document.createElement('span'); | |
elem.style = 'position: fixed; left: 0; top: 0; z-index: 10000; background: #000; color: #fff; font-size: 32px;' | |
elem.setAttribute('id', 'paylbackRateDisplay') | |
elem.innerText = ''; | |
document.querySelector('body').appendChild(elem); | |
} | |
function destroyPlaybackRateDisplay() { | |
try { | |
document.querySelector('#paylbackRateDisplay').remove(); | |
} catch (err) { | |
} | |
} | |
function displayPlaybackRate() { | |
var rate = document.getElementsByTagName("video")[0].playbackRate | |
document.querySelector('#paylbackRateDisplay').innerText = Math.round(rate * 10) / 10; | |
} | |
function playbackRateChange(e) { | |
var video = document.getElementsByTagName("video")[0]; | |
var step = 0.2; | |
if (e.ctrlKey && e.keyCode == 38) { | |
video.playbackRate += step; | |
} | |
if (e.ctrlKey && e.keyCode == 40) { | |
video.playbackRate -= step; | |
} | |
displayPlaybackRate(); | |
} | |
destroyPlaybackRateDisplay(); | |
createPlaybackRateDisplay(); | |
displayPlaybackRate(); | |
document.addEventListener('keyup', playbackRateChange, false); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment