Last active
August 29, 2015 14:17
-
-
Save kalkun/ec3e3e033f640096bb5b to your computer and use it in GitHub Desktop.
Set highest possible quaility and let space control pause and play.
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
// ==UserScript== | |
// @name Youtube space handler | |
// @version 1.1 | |
// @description Also sets highest possible quality for the video | |
// @author Jesper Henrichsen | |
// @match https://www.youtube.com/* | |
// ==/UserScript== | |
window.onkeydown = function(event){ | |
var bodyIsFocus = document.activeElement == document.getElementsByTagName('body')[0] || document.getElementsByTagName('video')[0]; | |
if (event.keyCode === 32 && bodyIsFocus) { | |
if(event.preventDefault) { | |
event.preventDefault(); | |
if( document.getElementsByClassName('ytp-button-play').length ) { | |
document.getElementsByClassName('ytp-button-play')[0].click(); | |
} else if ( document.getElementsByClassName('ytp-button-pause').length ) { | |
document.getElementsByClassName('ytp-button-pause')[0].click(); | |
} | |
} | |
} else if (event.keyCode == 70 && bodyIsFocus) { | |
// pressed 'F' so going into fullscreen: | |
document.getElementsByClassName('ytp-button-fullscreen-enter')[0].click(); | |
} | |
}; | |
document.onreadystatechange = function() { | |
if (document.readyState =="complete") { | |
var t = document.getElementsByClassName('ytp-drop-down'), | |
q; | |
for (var i = 0; i < t.length; i++) { | |
if (t.item(i).getAttribute('aria-label') == 'Quality') { | |
q = t.item(i); | |
break; | |
} | |
}; | |
// the first is always the highest quality possible: | |
q.getElementsByClassName('ytp-button')[0].click(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment