bigly-chat/static/main.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-11-25 14:12:43 -05:00
async function formClick(ev) {
ev.preventDefault();
let { target } = ev;
let fetched = await fetch(target.action, {
'method': 'POST',
'body': new FormData(target)
});
let json = await fetched.json();
document.querySelector('.form-message').textContent = json.message;
if (json.redirect) {
setTimeout(function () {
window.location.href = json.redirect;
}, 2000);
}
}
2024-11-25 14:12:43 -05:00
function moveBar(e, bar, vid) {
let rect = bar.getBoundingClientRect();
let prog = ((e.pageX - rect.x) / rect.width);
2024-11-25 14:12:43 -05:00
2024-11-25 14:12:43 -05:00
vid.currentTime = prog * vid.duration;
}
function prog(vid, bar) {
bar.querySelector('div').style.width = `${vid.currentTime / vid.duration * 100}%`;
}
function controls(vid) {
2024-11-25 14:12:43 -05:00
let bar = vid.querySelector('.progressbar');
2024-11-25 14:12:43 -05:00
let video = vid.querySelector('video');
2024-11-25 14:12:43 -05:00
let play = vid.querySelector('.play');
video.onclick = play.onclick = () => {
play.querySelector('img').src = !video.paused ? '/static/img/play.svg' : '/static/img/stop.svg';
2024-11-25 14:12:43 -05:00
if (video.paused) {
video.play();
return;
}
video.pause();
}
bar.onclick = (e) => moveBar(e, bar, video);
video.addEventListener('timeupdate', () => prog(video,bar));
}
2024-11-25 14:12:43 -05:00
window.onload = function () {
document.addEventListener('submit', formClick);
2024-11-25 14:12:43 -05:00
for (let vid of document.querySelectorAll('.video-wrapper')) {
2024-11-25 14:12:43 -05:00
controls(vid);
}
2024-11-25 14:12:43 -05:00
}