Skip to content

Instantly share code, notes, and snippets.

@colinaaa
Last active April 7, 2020 08:31
Show Gist options
  • Save colinaaa/096b82b0f15c0836efb49cd58756e3c6 to your computer and use it in GitHub Desktop.
Save colinaaa/096b82b0f15c0836efb49cd58756e3c6 to your computer and use it in GitHub Desktop.
const config = {
rate: 1, // playing rate
interval: 1 // the interval for check video ended
}
const play = () => {
const video = document.querySelector('video');
if (video && video.ended) {
console.log('AutoXuetangx now change to play next video.');
const list = document.querySelector('ul.active');
const current = Array.from(list.children).filter((i) =>
i.querySelector('li.active')
);
if (current.length === 0) {
$($('h2')[1]).html(
$($('h2')[1]).html() +
'<br><small> 没有下一个视频了 - AutoXuetangX </small>'
);
console.log('AutoXuetangx cannot found next video.');
return;
}
const next = current[0].nextElementSibling;
next.querySelector('span').click();
} else {
console.log('AutoXuetangx is waiting for video ended.');
}
video.muted = true;
video.playbackRate = config.rate;
video.play();
}
const clear = setInterval(() => play(), 1000 * config.interval);
const pause = () => clearInterval(clear);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment