2021-09-09 04:12:32 +04:00
|
|
|
const video_formats = ["webm", "mp4"];
|
|
|
|
const audio_formats = ["mp3", "flac", "opus", "ogg", "m4a"];
|
2021-09-09 20:35:40 +04:00
|
|
|
const image_formats = ["jpg", "jpeg", "gif", "png", "bmp", "webp"];
|
2021-09-09 04:12:32 +04:00
|
|
|
|
2021-10-13 23:18:04 +04:00
|
|
|
const overlay = document.getElementById("overlay");
|
|
|
|
let scale = 1;
|
2021-09-09 04:12:32 +04:00
|
|
|
|
2021-09-09 20:35:40 +04:00
|
|
|
function mousescroll(e) {
|
|
|
|
e.preventDefault();
|
2021-10-13 23:18:04 +04:00
|
|
|
scale = Math.min(Math.max(0.25, scale + (e.deltaY * -0.001)), 4);
|
2021-09-09 20:35:40 +04:00
|
|
|
e.target.style.transform = `scale(${scale})`;
|
|
|
|
}
|
2021-09-09 04:12:32 +04:00
|
|
|
|
2021-10-13 23:18:04 +04:00
|
|
|
const ext_filter = (ext, pathname) => pathname.toLowerCase().endsWith(ext);
|
|
|
|
|
|
|
|
function to_overlay(eltyp, pathname) {
|
|
|
|
const el = document.createElement(eltyp);
|
|
|
|
if (eltyp !== "audio") el.addEventListener('wheel', mousescroll);
|
|
|
|
if (eltyp !== "img") el.autoplay = el.controls = true;
|
|
|
|
el.src = pathname;
|
|
|
|
overlay.appendChild(el);
|
|
|
|
overlay.style.visibility = "visible";
|
|
|
|
}
|
|
|
|
|
2021-09-16 15:30:19 +04:00
|
|
|
document.getElementById("overlay").addEventListener("click", e => {
|
2021-09-09 20:35:40 +04:00
|
|
|
e.target.firstChild.remove();
|
2021-09-09 20:46:21 +04:00
|
|
|
e.target.style.visibility = "hidden";
|
2021-09-09 20:48:18 +04:00
|
|
|
scale = 1;
|
2021-09-09 20:35:40 +04:00
|
|
|
});
|
|
|
|
|
2021-10-13 23:18:04 +04:00
|
|
|
const file_links = Array.from(document.getElementsByTagName('tr')).slice(2).filter(e => e.lastChild.innerHTML != "DIR").map(l => l.firstChild.firstChild);
|
2021-09-09 20:35:40 +04:00
|
|
|
|
|
|
|
file_links.forEach(f => f.addEventListener('click', e => {
|
2021-10-13 23:18:04 +04:00
|
|
|
const pathname = e.target.pathname;
|
|
|
|
if (video_formats.some(ext => ext_filter(ext, pathname)))
|
|
|
|
to_overlay("video", pathname);
|
|
|
|
else if (audio_formats.some(ext => ext_filter(ext, pathname)))
|
|
|
|
to_overlay("audio", pathname);
|
|
|
|
else if (image_formats.some(ext => ext_filter(ext, pathname)))
|
|
|
|
to_overlay("img", pathname);
|
|
|
|
if (overlay.firstChild != null)
|
2021-09-09 20:35:40 +04:00
|
|
|
e.preventDefault();
|
|
|
|
}));
|