Skip to content

Instantly share code, notes, and snippets.

@cpthgli
Last active May 20, 2019 17:08
Show Gist options
  • Save cpthgli/d9f6b0be8aa9c6ead0cadcc5844561c5 to your computer and use it in GitHub Desktop.
Save cpthgli/d9f6b0be8aa9c6ead0cadcc5844561c5 to your computer and use it in GitHub Desktop.
User.js
// ==UserScript==
// @name openrec_add_seek_button
// @namespace https://gist.github.com/cpthgli/d9f6b0be8aa9c6ead0cadcc5844561c5
// @version 0.3.2
// @description OPENRECのコントロールバーにシークボタンを追加します。また、いくつかのショートカットキーも追加します。
// @author cpthgli
// @match https://www.openrec.tv/live/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
function add_seek(element, value) {
element.setAttribute("onclick", "getElementById('openrec-video-player_Viblast_api').currentTime+=" + value.toString());
}
function add_style(element) {
element.setAttribute("onmouseover", "this.style.textShadow='0em 0em 1em white'");
element.setAttribute("onmouseout", "this.style.textShadow='none'");
element.style.cursor = "pointer";
}
var pre1m = document.createElement("button");
var pre10s = document.createElement("button");
var pre5s = document.createElement("button");
var nxt5s = document.createElement("button");
var nxt10s = document.createElement("button");
var nxt1m = document.createElement("button");
var elements = [pre1m, pre10s, pre5s, nxt5s, nxt10s, nxt1m];
var names = ["-1m", "-10s", "-5s", "+5s", "+10s", "+1m"];
var values = [-60, -10, -5, 5, 10, 60];
var bar = document.getElementsByClassName("vjs-control-bar")[0];
var volume = document.getElementsByClassName("vjs-volume-menu-button")[0];
for (var i in elements) {
elements[i].textContent = names[i];
add_seek(elements[i], values[i]);
add_style(elements[i]);
bar.insertBefore(elements[i], volume);
}
var video = document.getElementById('openrec-video-player_Viblast_api');
window.onkeydown = function (e) {
if (!e) e = window.event;
var key_code = e.keyCode;
var shift_key = e.shiftKey;
var ctrl_key = e.ctrlKey;
var alt_key = e.altKey;
var v;
switch (key_code) {
case 32: // space
if (video.paused) {
video.play();
} else {
video.pause();
}
return false;
case 37: // ←
if (shift_key && !ctrl_key && !alt_key) {
v = values[0];
console.log(v);
video.currentTime += v;
} else if (!shift_key && ctrl_key && !alt_key) {
v = values[parseInt(values.length / 4)];
console.log(v);
video.currentTime += v;
} else if (!shift_key && !ctrl_key && alt_key) {
v = values[parseInt(values.length / 2 - 1)];
console.log(v);
video.currentTime += v;
} else {
v = values[parseInt(values.length / 4)];
console.log(v);
video.currentTime += v;
}
return false;
case 39: // →
if (shift_key && !ctrl_key && !alt_key) {
v = values[values.length - 1];
console.log(v);
video.currentTime += v;
} else if (!shift_key && ctrl_key && !alt_key) {
v = values[parseInt(values.length / 2 + Math.floor(values.length / 4))];
console.log(v);
video.currentTime += v;
} else if (!shift_key && !ctrl_key && alt_key) {
v = values[parseInt(values.length / 2)];
console.log(v);
video.currentTime += v;
} else {
v = values[parseInt(values.length / 2 + Math.floor(values.length / 4))];
console.log(v);
video.currentTime += v;
}
return false;
default:
console.log(key_code);
}
};
})();

ショートカットキー

キー 機能
-10s
shift + ← - 1m
ctrl + ← -10s
alt + ← - 5s
+10s
shift + → + 1m
ctrl + → +10s
alt + → + 5s
space play/pause
@Stalloni
Copy link

@linglung
Copy link

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