Skip to content

Instantly share code, notes, and snippets.

@pfgithub
Last active January 30, 2020 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfgithub/295841cc1bb742ce08cd7178eb253746 to your computer and use it in GitHub Desktop.
Save pfgithub/295841cc1bb742ce08cd7178eb253746 to your computer and use it in GitHub Desktop.
let video = document.querySelector("video");
let frameTime = 0.01;
let timeElem = document.createElement("div");
let q = document.createTextNode("---");
timeElem.style.position = "fixed";
timeElem.style.top = "0";
timeElem.style.right = "0";
timeElem.style.padding = "10px";
timeElem.style.fontSize = "24pt";
timeElem.style.backgroundColor = "#fff";
timeElem.style.color = "#000";
timeElem.appendChild(q);
document.body.appendChild(timeElem);
setInterval(() => (q.nodeValue = video.currentTime.toFixed(2)), 100);
window.addEventListener("keypress", function(evt) {
console.log(evt.key);
if (evt.key === ",") {
video.pause();
video.currentTime = Math.max(0, video.currentTime - frameTime);
} else if (evt.key === ".") {
video.pause();
video.currentTime = Math.min(video.duration, video.currentTime + frameTime);
} else if (evt.key === "k") {
if(video.paused) video.play(); else video.pause();
} else if (evt.key === "d") {
video.pause();
video.currentTime = Math.min(video.duration, video.currentTime + frameTime * 10);
} else if (evt.key === "a") {
video.pause();
video.currentTime = Math.max(0, video.currentTime - frameTime * 10);
} else if (evt.key === "l") {
video.pause();
video.currentTime = Math.min(video.duration, video.currentTime + frameTime * 100);
} else if (evt.key === "j") {
video.pause();
video.currentTime = Math.max(0, video.currentTime - frameTime * 100);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment