mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
32 lines
940 B
JavaScript
32 lines
940 B
JavaScript
function hasAudio (video) {
|
|
return video.mozHasAudio ||
|
|
Boolean(video.webkitAudioDecodedByteCount) ||
|
|
Boolean(video.audioTracks && video.audioTracks.length);
|
|
}
|
|
|
|
function setVideoInGIFMode(video) {
|
|
if (!hasAudio(video)) {
|
|
if (typeof video.loop == 'boolean' && video.duration <= 10.0) {
|
|
video.classList.add("video-gif-mode");
|
|
video.loop = true;
|
|
video.controls = false;
|
|
video.addEventListener("mouseover", () => {
|
|
video.play();
|
|
})
|
|
video.addEventListener("mouseleave", () => {
|
|
video.pause();
|
|
})
|
|
}
|
|
};
|
|
}
|
|
|
|
var items = document.getElementsByTagName("video")
|
|
for (var i = 0; i < items.length; i++) {
|
|
if (items[i].duration) {
|
|
setVideoInGIFMode(items[i]);
|
|
} else {
|
|
items[i].addEventListener("loadeddata", function() {
|
|
setVideoInGIFMode(this);
|
|
});
|
|
}
|
|
}
|