Skip to content

Instantly share code, notes, and snippets.

@kusaanko
Created February 17, 2019 02:51
Show Gist options
  • Save kusaanko/f1ab3fe6d2b5aac763fadd9ed904910f to your computer and use it in GitHub Desktop.
Save kusaanko/f1ab3fe6d2b5aac763fadd9ed904910f to your computer and use it in GitHub Desktop.
Display subtitle while pressing S key in YouTube.
// ==UserScript==
// @name Key to Subtitles
// @namespace https://github.com/kusaanko
// @version 0.1
// @description Display subtitle while pressing S key in YouTube.
// @author Kusaanko
// @match https://www.youtube.com/watch*
// @grant none
// @require https://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==
(function() {
document.onkeydown = function(e) {
if(document.activeElement.nodeName!='INPUT'&&e.keyCode==83&&$('.ytp-subtitles-button.ytp-button').attr('aria-pressed')=='false') {
$('.ytp-subtitles-button.ytp-button').click();
}
}
document.onkeyup = function(e) {
if(!document.activeElement.nodeName!='INPUT'&&e.keyCode==83&&$('.ytp-subtitles-button.ytp-button').attr('aria-pressed')=='true') {
$('.ytp-subtitles-button.ytp-button').click();
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment