mirror of https://github.com/zedeus/nitter
misc. changes
This commit is contained in:
parent
67156e56a8
commit
d7efa787b1
|
@ -5,18 +5,18 @@
|
|||
|
||||
const m3u8 = 'application/vnd.apple.mpegurl';
|
||||
const thresholds = [ 0.1, 0.9 ]; // check viewport at 10% and 90%
|
||||
const videoConfig = { controls: true, oldRatio: 0, visible: true };
|
||||
const videoConfig = { controls: true, oldRatio: 0, testViewport: true };
|
||||
|
||||
const observer = new IntersectionObserver(observeEntries, { threshold: thresholds });
|
||||
|
||||
function isMostlyInView(currRatio) {
|
||||
return (currRatio > thresholds[1]);
|
||||
}
|
||||
|
||||
function isLeavingView(currRatio, oldRatio) {
|
||||
return (oldRatio > currRatio);
|
||||
}
|
||||
|
||||
function isMostlyInView(currRatio) {
|
||||
return (currRatio > thresholds[1]);
|
||||
}
|
||||
|
||||
// is paused -> https://stackoverflow.com/questions/36803176
|
||||
function isVideoPaused(video) {
|
||||
return (video.paused || video.ended || video.readyState < video.HAVE_CURRENT_DATA);
|
||||
|
@ -36,7 +36,7 @@
|
|||
|
||||
if (inView && isPaused) video.play();
|
||||
else if (!inView && !isPaused && isLeavingView(entry.intersectionRatio, video.oldRatio)) {
|
||||
video.visible = false;
|
||||
video.testViewport = false;
|
||||
video.pause();
|
||||
}
|
||||
|
||||
|
@ -44,12 +44,12 @@
|
|||
});
|
||||
}
|
||||
|
||||
// we set the oldRatio to 0 on pauses, as we aren't observing where the viewport is
|
||||
// we set the oldRatio to 0 on manual pauses, as we don't know where the viewport will end up
|
||||
function observeVideo(video) {
|
||||
observer.observe(video);
|
||||
video.addEventListener('play', (evt) => observer.observe(video));
|
||||
video.addEventListener('pause', (evt) => {
|
||||
video.visible ? (observer.unobserve(video), video.oldRatio = 0) : (observer.observe(video), video.visible = true)
|
||||
video.testViewport ? (observer.unobserve(video), video.oldRatio = 0) : (observer.observe(video), video.testViewport = true)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@
|
|||
video.addEventListener('canplay', () => loadVideo(video));
|
||||
}
|
||||
|
||||
// export playVideo
|
||||
window.playVideo = function(overlay) {
|
||||
const video = overlay.parentElement.querySelector('video');
|
||||
const url = video.getAttribute('data-url');
|
||||
|
|
Loading…
Reference in New Issue