Skip to content

Instantly share code, notes, and snippets.

@azu
Created December 13, 2015 05:07
Show Gist options
  • Save azu/8ae443ca2132ccdbc637 to your computer and use it in GitHub Desktop.
Save azu/8ae443ca2132ccdbc637 to your computer and use it in GitHub Desktop.
Youtube 書き起こしベースの早送り.user.js
// ==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)
});
@thienha1
Copy link

Can you make scripts that set a timer to automatically pause/stop on all Youtube embed videos? Like pause a video after X seconds!!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment