bigly-chat/static/main.js

82 lines
2 KiB
JavaScript
Raw Normal View History

2024-11-25 14:12:43 -05:00
async function formClick(ev) {
ev.preventDefault();
let { target } = ev;
2024-11-25 14:12:43 -05:00
let fData = new FormData(target);
2024-11-25 14:12:43 -05:00
let file = target.querySelector('input[type=file]');
if (file)
file.value = null;
2024-11-25 14:12:43 -05:00
2024-11-25 14:12:43 -05:00
let fetched = await fetch(target.action, {
'method': 'POST',
2024-11-25 14:12:43 -05:00
'body': fData
2024-11-25 14:12:43 -05:00
});
let json = await fetched.json();
2024-11-25 14:12:44 -05:00
let c = target.querySelector('.captcha');
if (c) c.src += '&a=b';
2024-11-25 14:12:44 -05:00
2024-11-25 14:12:43 -05:00
target.querySelector('.form-message').textContent = json.message;
2024-11-25 14:12:43 -05:00
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 isFull = false;
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');
2024-11-25 14:12:44 -05:00
let h = document.querySelector('.header');
2024-11-25 14:12:43 -05:00
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();
}
2024-11-25 14:12:43 -05:00
vid.querySelector('.full').onclick = (e) => {
isFull = !isFull;
e.target.src = isFull ? '/static/img/tiny.svg' : '/static/img/full.svg';
if (isFull) {
2024-11-25 14:12:44 -05:00
vid.classList.add('full');
h.classList.add('full');
2024-11-25 14:12:43 -05:00
} else {
2024-11-25 14:12:44 -05:00
vid.classList.remove('full');
h.classList.remove('full');
2024-11-25 14:12:43 -05:00
}
}
2024-11-25 14:12:43 -05:00
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
}