hotkeys.js: add 'c' for transcript
This commit is contained in:
parent
786d3eb445
commit
94ece08a1e
23
youtube/static/js/common.js
Normal file
23
youtube/static/js/common.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Q = document.querySelector.bind(document);
|
||||||
|
function text(msg) { return document.createTextNode(msg); }
|
||||||
|
function clearNode(node) { while (node.firstChild) node.removeChild(node.firstChild); }
|
||||||
|
function toMS(s) {
|
||||||
|
var s = Math.floor(s);
|
||||||
|
var m = Math.floor(s/60); var s = s % 60;
|
||||||
|
return `0${m}:`.slice(-3) + `0${s}`.slice(-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var cur_tt_idx = 0;
|
||||||
|
function getActiveTranscriptTrackIdx() {
|
||||||
|
let tts = Q("video").textTracks;
|
||||||
|
if (!tts.length) return;
|
||||||
|
for (let i=0; i < tts.length; i++) {
|
||||||
|
if (tts[i].mode == "showing") {
|
||||||
|
cur_tt_idx = i;
|
||||||
|
return cur_tt_idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cur_tt_idx;
|
||||||
|
}
|
||||||
|
function getActiveTranscriptTrack() { return Q("video").textTracks[getActiveTranscriptTrackIdx()]; }
|
@ -1,9 +1,7 @@
|
|||||||
Q = document.querySelector.bind(document);
|
|
||||||
|
|
||||||
function onKeyDown(e) {
|
function onKeyDown(e) {
|
||||||
if (['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) return false;
|
if (['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) return false;
|
||||||
|
|
||||||
console.log(e);
|
// console.log(e);
|
||||||
let v = Q("video");
|
let v = Q("video");
|
||||||
let c = e.key.toLowerCase();
|
let c = e.key.toLowerCase();
|
||||||
if (c == "k") {
|
if (c == "k") {
|
||||||
@ -25,6 +23,18 @@ function onKeyDown(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
v.currentTime = v.currentTime + 10;
|
v.currentTime = v.currentTime + 10;
|
||||||
}
|
}
|
||||||
|
else if (c == "f") {
|
||||||
|
e.preventDefault();
|
||||||
|
if (document.fullscreen) document.exitFullscreen();
|
||||||
|
else v.requestFullscreen();
|
||||||
|
}
|
||||||
|
else if (c == "c") {
|
||||||
|
e.preventDefault();
|
||||||
|
let tt = getActiveTranscriptTrack();
|
||||||
|
if (tt == null) return;
|
||||||
|
if (tt.mode == "showing") tt.mode = "disabled";
|
||||||
|
else tt.mode = "showing";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
window.addEventListener('DOMContentLoaded', function() {
|
||||||
|
@ -608,6 +608,8 @@ Reload without invidious (for usage of new identity button).</a>
|
|||||||
</details>
|
</details>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<script src="/youtube.com/static/js/common.js"></script>
|
||||||
{% if settings.use_video_hotkeys %}
|
{% if settings.use_video_hotkeys %}
|
||||||
<script src="/youtube.com/static/js/hotkeys.js"></script>
|
<script src="/youtube.com/static/js/hotkeys.js"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user