Created
December 13, 2015 05:07
-
-
Save azu/8ae443ca2132ccdbc637 to your computer and use it in GitHub Desktop.
Youtube 書き起こしベースの早送り.user.js
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:floating transcript | |
// @namespace http://efcl.info/ | |
// @description apply panel floating | |
// @include https://www.youtube.com/watch?v=* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// Usage: Open Transcript panel | |
// -> next transcript | |
// <- prev transcript | |
function GM_addStyle(aCss) { | |
'use strict'; | |
let head = document.getElementsByTagName('head')[0]; | |
if (head) { | |
let style = document.createElement('style'); | |
style.setAttribute('type', 'text/css'); | |
style.textContent = aCss; | |
head.appendChild(style); | |
return style; | |
} | |
return null; | |
} | |
GM_addStyle(` | |
#watch-transcript-container { | |
position:fixed; | |
top: 100px; | |
right:0; | |
z-index:123456; | |
background-color: white; | |
padding: 1rem; | |
} | |
#watch-transcript-container{ | |
max-height: 32em; | |
} | |
#watch-transcript-container #transcript-scrollbox{ | |
max-height: 30em; | |
} | |
`); | |
var _cacheNext, _cachePrev; | |
function nextTranscript(){ | |
var currentTranscript = document.querySelector(".caption-line.caption-line-highlight"); | |
var next = currentTranscript.nextElementSibling; | |
if(next === _cacheNext){ | |
next = next.nextElementSibling; | |
} | |
_cacheNext=next; | |
next.click(); | |
} | |
function prevTranscript(){ | |
var currentTranscript = document.querySelector(".caption-line.caption-line-highlight"); | |
var prev = currentTranscript.prevElementSibiling; | |
if(prev === _cachePrev){ | |
prev = next.prevElementSibiling; | |
} | |
_cachePrev = prev; | |
prev.click(); | |
} | |
function onKeyCode(event, keyCode) { | |
switch (keyCode) { | |
case 38:// UP | |
event.preventDefault(); | |
prevTranscript(); | |
break; | |
case 40:// Down | |
event.preventDefault(); | |
nextTranscript(); | |
break; | |
case 39:// Right | |
event.preventDefault(); | |
nextTranscript(); | |
break; | |
case 37:// Left | |
event.preventDefault(); | |
prevTranscript(); | |
break; | |
} | |
} | |
document.addEventListener("keydown", (event) => { | |
onKeyCode(event, event.keyCode) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you make scripts that set a timer to automatically pause/stop on all Youtube embed videos? Like pause a video after X seconds!!?