Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created September 6, 2019 02:44
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 a-eid/afa433d52d9859fb90d70c385251dd51 to your computer and use it in GitHub Desktop.
Save a-eid/afa433d52d9859fb90d70c385251dd51 to your computer and use it in GitHub Desktop.
const video = () => document.querySelector('video');
document.querySelector('progress').style.opacity = 0.35;
const codes = {
space: 32,
j: 74,
k: 75,
l: 76,
};
document.addEventListener('keydown', e => {
if (e.keyCode == codes.k) {
toggle();
}
if (e.keyCode == codes.l) forward();
if (e.keyCode == codes.j) backword();
});
function forward() {
video().currentTime = video().currentTime + 10;
}
function backword() {
video().currentTime = video().currentTime - 10;
}
function toggle() {
video().paused ? video().play() : video().pause();
}
//
const title = document.querySelector('.standard-title');
function run() {
const video = document.querySelector('video');
if (!video || video.paused) return;
const src = video.src;
const activeLi = document.querySelector(`[href='${src}']`).parentElement;
activeLi.style.backgroundColor = 'black';
const titleToBe =
activeLi.querySelector('.lessons-name') &&
activeLi.querySelector('.lessons-name').textContent;
const items = src.split('/');
// const titleToBe = items[items.length - 1];
if (titleToBe === title.textContent) return;
title.textContent = titleToBe || items[items.length - 1];
}
run();
setInterval(run, 20000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment