2024-12-10 22:20:13 +04:00
|
|
|
document.getElementById("instruction").classList.remove("hidden");
|
|
|
|
|
2022-06-28 05:02:10 +04:00
|
|
|
//// OVERLAY FOR VIEWING MEDIA FILES
|
|
|
|
|
2022-07-25 21:10:35 +04:00
|
|
|
const video_formats = ["webm", "mp4", "mov"];
|
2022-06-27 23:44:53 +04:00
|
|
|
const audio_formats = ["mp3", "flac", "opus", "ogg", "m4a"];
|
|
|
|
const image_formats = ["jpg", "jpeg", "gif", "png", "bmp", "webp"];
|
|
|
|
|
|
|
|
const overlay = document.getElementById("overlay");
|
2024-12-10 01:17:09 +04:00
|
|
|
const overlay_content = overlay.children[1];
|
|
|
|
const overlay_label = overlay.children[2];
|
2022-06-28 05:18:38 +04:00
|
|
|
|
2022-10-31 01:39:55 +04:00
|
|
|
const g_tbody = document.getElementsByTagName('tbody')[0];
|
2022-10-31 03:23:08 +04:00
|
|
|
let g_first_row = g_tbody.firstChild;
|
|
|
|
let g_last_row = g_tbody.lastChild;
|
2022-10-31 01:39:55 +04:00
|
|
|
const g_back_row = document.getElementsByTagName("tr")[1];
|
2022-06-27 23:44:53 +04:00
|
|
|
|
2022-10-31 01:39:55 +04:00
|
|
|
let g_scale = 1;
|
2024-12-10 01:17:09 +04:00
|
|
|
let g_oc_offset = [0, 0];
|
|
|
|
let g_oc_translate = [0, 0];
|
2022-10-31 01:39:55 +04:00
|
|
|
let g_current_row = g_back_row;
|
2022-09-20 03:39:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (localStorage.getItem('audio_volume') == null)
|
|
|
|
localStorage['audio_volume'] = 0.5;
|
|
|
|
|
2022-09-20 04:28:29 +04:00
|
|
|
function overlay_close() {
|
2024-12-10 01:17:09 +04:00
|
|
|
overlay_content.firstChild.remove();
|
2022-09-20 04:28:29 +04:00
|
|
|
overlay.style.visibility = "hidden";
|
|
|
|
g_scale = 1;
|
2024-12-10 01:17:09 +04:00
|
|
|
g_oc_offset = g_oc_translate = [0, 0];
|
2022-09-20 04:28:29 +04:00
|
|
|
}
|
|
|
|
|
2024-12-10 01:17:09 +04:00
|
|
|
overlay_content.addEventListener("wheel", e => {
|
|
|
|
e.preventDefault();
|
|
|
|
g_scale = Math.min(Math.max(0.25, g_scale + (e.deltaY * -0.001)), 4);
|
|
|
|
e.target.style.transform =
|
|
|
|
`translate(${g_oc_translate[0]}px, ${g_oc_translate[1]}px) scale(${g_scale})`;
|
|
|
|
});
|
|
|
|
|
2022-09-20 03:39:42 +04:00
|
|
|
overlay.addEventListener("mouseup", e => {
|
2024-12-10 01:17:09 +04:00
|
|
|
if (e.target.tagName === "DIV" && e.button === 0) overlay_close(); });
|
|
|
|
|
|
|
|
overlay_content.addEventListener("mousedown", e => {
|
|
|
|
if (e.buttons !== 1) return;
|
|
|
|
e.preventDefault();
|
|
|
|
g_oc_offset = [e.offsetX, e.offsetY];
|
|
|
|
});
|
|
|
|
|
|
|
|
overlay_content.addEventListener("mousemove", e => {
|
|
|
|
if (e.buttons !== 1) return;
|
|
|
|
e.preventDefault();
|
|
|
|
g_oc_translate[0] = e.clientX - e.target.x - g_oc_offset[0];
|
|
|
|
g_oc_translate[1] = e.clientY - e.target.y - g_oc_offset[1];
|
|
|
|
e.target.style.transform = `translate(${g_oc_translate[0]}px, ${g_oc_translate[1]}px) scale(${g_scale})`;
|
|
|
|
});
|
2022-09-20 03:39:42 +04:00
|
|
|
|
2024-12-10 22:20:39 +04:00
|
|
|
overlay_autoplay = document.getElementsByName("autoplay")[0];
|
|
|
|
|
|
|
|
overlay_autoplay.addEventListener("change", e => {
|
|
|
|
if (e.target.checked && overlay_content.firstChild !== undefined)
|
|
|
|
if (overlay_content.firstChild.tagName === "AUDIO" || overlay_content.firstChild.tagName === "VIDEO")
|
|
|
|
if (overlay_content.firstChild.ended)
|
|
|
|
b_next.click();
|
|
|
|
});
|
|
|
|
|
2022-09-20 03:39:42 +04:00
|
|
|
|
|
|
|
function determine_media_element(path) {
|
|
|
|
path = path.toLowerCase();
|
|
|
|
if (video_formats.some(ext => path.endsWith(ext)))
|
|
|
|
return "video";
|
|
|
|
else if (audio_formats.some(ext => path.endsWith(ext)))
|
|
|
|
return "audio";
|
|
|
|
else if (image_formats.some(ext => path.endsWith(ext)))
|
|
|
|
return "img";
|
|
|
|
return undefined;
|
2022-06-27 23:44:53 +04:00
|
|
|
}
|
|
|
|
|
2022-09-20 03:39:42 +04:00
|
|
|
function send_to_overlay(pathname, media_type_element) {
|
|
|
|
if (media_type_element === undefined)
|
|
|
|
return false;
|
2024-12-10 01:17:09 +04:00
|
|
|
if (overlay_content.children.length != 0) {
|
|
|
|
g_oc_offset = g_oc_translate = [0, 0];
|
|
|
|
g_scale = 1;
|
|
|
|
}
|
2022-09-20 03:39:42 +04:00
|
|
|
|
|
|
|
const media_element = document.createElement(media_type_element);
|
|
|
|
media_element.src = pathname;
|
|
|
|
|
|
|
|
if (media_type_element !== "img") {
|
|
|
|
media_element.autoplay = media_element.controls = true;
|
|
|
|
media_element.addEventListener("volumechange", e => {
|
|
|
|
localStorage['audio_volume'] = e.target.volume; });
|
|
|
|
media_element.volume = localStorage["audio_volume"];
|
2024-12-10 22:20:39 +04:00
|
|
|
media_element.addEventListener("ended", e => { if (overlay_autoplay.checked) b_next.click(); });
|
2022-09-20 03:39:42 +04:00
|
|
|
}
|
|
|
|
|
2024-12-10 01:17:09 +04:00
|
|
|
overlay_label.textContent = decodeURI(pathname.substr(pathname.lastIndexOf("/") + 1));
|
|
|
|
|
|
|
|
overlay_content.replaceChildren(media_element);
|
|
|
|
|
2022-09-20 03:39:42 +04:00
|
|
|
overlay.style.visibility = "visible";
|
|
|
|
|
|
|
|
return true;
|
2022-06-27 23:44:53 +04:00
|
|
|
}
|
|
|
|
|
2022-10-31 01:39:55 +04:00
|
|
|
function getSibling(isNext = true, upDown = false) {
|
|
|
|
if (upDown && g_current_row == g_back_row)
|
|
|
|
g_current_row = isNext ? g_first_row : g_last_row;
|
|
|
|
else
|
|
|
|
g_current_row = isNext ?
|
|
|
|
( (g_current_row.nextSibling === null) ?
|
|
|
|
(upDown ? g_back_row : g_first_row) : g_current_row.nextSibling )
|
|
|
|
: ( (g_current_row.previousSibling === null) ?
|
|
|
|
(upDown ? g_back_row : g_last_row) : g_current_row.previousSibling );
|
|
|
|
return g_current_row;
|
|
|
|
}
|
2022-09-20 03:39:42 +04:00
|
|
|
|
|
|
|
const [b_prev, b_next] = overlay.getElementsByTagName("button");
|
|
|
|
|
|
|
|
b_prev.addEventListener("click", e => {
|
|
|
|
do {
|
2022-10-31 01:39:55 +04:00
|
|
|
getSibling(false, false);
|
2022-10-18 22:22:04 +04:00
|
|
|
} while (g_current_row.classList.contains("hidden")
|
|
|
|
|| !send_to_overlay(g_current_row.firstChild.firstChild.pathname,
|
|
|
|
determine_media_element(g_current_row.firstChild.firstChild.pathname)));
|
2022-10-31 01:39:55 +04:00
|
|
|
g_current_row.firstChild.firstChild.focus();
|
2022-09-20 03:39:42 +04:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2022-10-31 01:39:55 +04:00
|
|
|
b_next.addEventListener("click", e => {
|
2022-09-20 03:39:42 +04:00
|
|
|
do {
|
2022-10-31 01:39:55 +04:00
|
|
|
getSibling(true, false);
|
2022-10-18 22:22:04 +04:00
|
|
|
} while (g_current_row.classList.contains("hidden")
|
|
|
|
|| !send_to_overlay(g_current_row.firstChild.firstChild.pathname,
|
|
|
|
determine_media_element(g_current_row.firstChild.firstChild.pathname)));
|
2022-10-31 01:39:55 +04:00
|
|
|
g_current_row.firstChild.firstChild.focus();
|
|
|
|
e.preventDefault();
|
2022-06-27 23:44:53 +04:00
|
|
|
});
|
|
|
|
|
2024-12-10 01:17:09 +04:00
|
|
|
Array.from(g_tbody.children)
|
|
|
|
.forEach(v => {
|
|
|
|
if (v.lastChild.innerHTML === "DIR") return;
|
|
|
|
v.firstChild.firstChild.addEventListener("click", e => {
|
|
|
|
g_current_row = e.target.parentNode.parentNode;
|
|
|
|
if (send_to_overlay(e.target.pathname, determine_media_element(e.target.pathname)))
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2022-10-31 01:44:27 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
//// KEYBOARD HANDLING
|
|
|
|
|
2022-09-20 03:39:42 +04:00
|
|
|
window.addEventListener("keydown", e => {
|
2022-10-31 01:39:55 +04:00
|
|
|
if (e.isComposing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (overlay.style.visibility === "hidden" || overlay.style.visibility === "") {
|
|
|
|
switch (e.code) {
|
|
|
|
case "Backspace": if (e.ctrlKey) window.location = "../"; break;
|
|
|
|
case "Home": g_current_row = g_back_row; g_back_row.firstChild.firstChild.focus(); break;
|
|
|
|
case "End": g_current_row = g_last_row; g_last_row.firstChild.firstChild.focus(); break;
|
|
|
|
case "ArrowUp":
|
2024-12-08 04:13:57 +04:00
|
|
|
case "ArrowLeft":
|
2022-10-31 01:39:55 +04:00
|
|
|
e.preventDefault();
|
|
|
|
getSibling(false, true);
|
|
|
|
g_current_row.firstChild.firstChild.focus();
|
|
|
|
break;
|
|
|
|
case "ArrowDown":
|
2024-12-08 04:13:57 +04:00
|
|
|
case "ArrowRight":
|
2022-10-31 01:39:55 +04:00
|
|
|
e.preventDefault();
|
|
|
|
getSibling(true, true);
|
|
|
|
g_current_row.firstChild.firstChild.focus();
|
|
|
|
break;
|
|
|
|
}
|
2022-09-20 03:39:42 +04:00
|
|
|
return;
|
2022-10-31 01:39:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (e.code) {
|
2024-12-08 04:13:57 +04:00
|
|
|
case "ArrowUp":
|
|
|
|
case "ArrowLeft":
|
|
|
|
e.preventDefault();
|
|
|
|
b_prev.click();
|
|
|
|
break;
|
|
|
|
case "ArrowDown":
|
|
|
|
case "ArrowRight":
|
|
|
|
e.preventDefault();
|
|
|
|
b_next.click();
|
|
|
|
break;
|
2022-10-31 01:39:55 +04:00
|
|
|
case "Escape": overlay_close(); break;
|
|
|
|
case "Space":
|
|
|
|
e.preventDefault();
|
|
|
|
const el = overlay_content.firstChild;
|
|
|
|
if (el.paused !== undefined)
|
|
|
|
el.paused ? el.play() : el.pause();
|
|
|
|
}
|
2022-09-20 03:39:42 +04:00
|
|
|
});
|
|
|
|
|
2022-10-18 22:21:31 +04:00
|
|
|
//// FILTERING
|
|
|
|
|
2022-10-31 01:39:55 +04:00
|
|
|
|
|
|
|
document.getElementsByName("filter")[0].classList.remove("hidden");
|
2022-10-18 22:21:31 +04:00
|
|
|
function filter(sub) {
|
2022-10-31 01:39:55 +04:00
|
|
|
const table = g_tbody.children;
|
2022-10-18 22:21:31 +04:00
|
|
|
for (let j = 0; j < table.length; ++j)
|
2022-10-31 01:39:55 +04:00
|
|
|
table[j].classList.toggle("hidden",
|
|
|
|
!(sub === "" || table[j].firstChild.firstChild.innerText.toLowerCase().indexOf(sub) != -1));
|
2022-10-18 22:21:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementsByName("filter")[0].addEventListener("input", e => filter(e.target.value.toLowerCase()));
|
|
|
|
|
2022-06-28 05:02:10 +04:00
|
|
|
//// SORT BY COLUMN
|
2022-06-28 04:21:46 +04:00
|
|
|
|
2022-10-31 01:39:55 +04:00
|
|
|
const units = {"B": 0, "KiB": 1, "MiB": 2, "GiB": 3, "TiB": 4};
|
2022-06-28 04:21:46 +04:00
|
|
|
const [thead_name, thead_date, thead_size] = document.getElementsByTagName('thead')[0]
|
2022-09-20 03:39:42 +04:00
|
|
|
.children[0].children;
|
2022-06-28 04:21:46 +04:00
|
|
|
|
|
|
|
let g_sort_reverse = false;
|
|
|
|
|
|
|
|
thead_name.classList.toggle("clickable");
|
|
|
|
thead_name.addEventListener('click', e => {
|
2022-09-20 03:39:42 +04:00
|
|
|
e.preventDefault();
|
|
|
|
sortTable((a,b) => {
|
|
|
|
const a_name = a.children[0].textContent.toLowerCase();
|
|
|
|
const b_name = b.children[0].textContent.toLowerCase();
|
|
|
|
return a_name < b_name ? -1 : a_name > b_name ? 1 : 0;
|
|
|
|
}, null, null, thead_name, [thead_date, thead_size]);
|
2022-10-31 03:23:08 +04:00
|
|
|
g_first_row = g_tbody.firstChild;
|
|
|
|
g_last_row = g_tbody.lastChild;
|
2022-06-28 04:21:46 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
thead_date.classList.toggle("clickable");
|
|
|
|
thead_date.addEventListener('click', e => {
|
2022-09-20 03:39:42 +04:00
|
|
|
e.preventDefault();
|
|
|
|
sortTable((a,b) => {
|
|
|
|
const a_date = new Date(a.children[1].textContent.slice(0, -4));
|
|
|
|
const b_date = new Date(b.children[1].textContent.slice(0, -4));
|
|
|
|
return a_date - b_date;
|
|
|
|
}, null, null, thead_date, [thead_name, thead_size]);
|
2022-10-31 03:23:08 +04:00
|
|
|
g_first_row = g_tbody.firstChild;
|
|
|
|
g_last_row = g_tbody.lastChild;
|
2022-06-28 04:21:46 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function sizeToBytes(size, unit) {
|
2022-09-20 03:39:42 +04:00
|
|
|
if (units[unit] == 0) return size;
|
|
|
|
for (let i = 0; i <= units[unit]; ++i) size *= 1024;
|
|
|
|
return size;
|
2022-06-28 04:21:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
thead_size.classList.toggle("clickable");
|
|
|
|
thead_size.addEventListener('click', e => {
|
2022-09-20 03:39:42 +04:00
|
|
|
e.preventDefault();
|
|
|
|
sortTable(
|
|
|
|
(a,b) => {
|
|
|
|
if (a.textContent == "DIR")
|
|
|
|
return 1;
|
|
|
|
let [a_size, a_unit] = a.children[2].textContent.split(" ");
|
|
|
|
let [b_size, b_unit] = b.children[2].textContent.split(" ");
|
|
|
|
return sizeToBytes(+a_size, a_unit) - sizeToBytes(+b_size, b_unit);
|
|
|
|
},
|
|
|
|
e => e.children[2].textContent == "DIR",
|
|
|
|
e => e.children[2].textContent != "DIR",
|
|
|
|
thead_size, [thead_name, thead_date]);
|
2022-10-31 03:23:08 +04:00
|
|
|
g_first_row = g_tbody.firstChild;
|
|
|
|
g_last_row = g_tbody.lastChild;
|
2022-06-28 04:21:46 +04:00
|
|
|
});
|
|
|
|
|
2022-06-28 04:59:01 +04:00
|
|
|
function sortTable(compareFn, filterFn, filterNegFn, target, other) {
|
2022-10-31 01:39:55 +04:00
|
|
|
let records = Array.from(g_tbody.children);
|
2022-09-20 03:39:42 +04:00
|
|
|
|
|
|
|
let dirs = [];
|
|
|
|
if (filterFn != null) {
|
|
|
|
dirs = records.filter(filterFn);
|
|
|
|
records = records.filter(filterNegFn);
|
|
|
|
}
|
|
|
|
|
|
|
|
records.sort(compareFn);
|
|
|
|
|
2022-10-31 01:39:55 +04:00
|
|
|
g_tbody.textContent = "";
|
2022-09-20 03:39:42 +04:00
|
|
|
|
|
|
|
other.forEach(v => {
|
|
|
|
v.classList.remove("sort-up");
|
|
|
|
v.classList.remove("sort-down");
|
|
|
|
});
|
|
|
|
|
|
|
|
if (filterFn != null)
|
2022-10-31 01:39:55 +04:00
|
|
|
g_tbody.append(...dirs);
|
2022-09-20 03:39:42 +04:00
|
|
|
|
|
|
|
if (g_sort_reverse) {
|
2022-10-31 01:39:55 +04:00
|
|
|
g_tbody.append(...records.reverse());
|
2022-09-20 03:39:42 +04:00
|
|
|
target.classList.add("sort-up");
|
|
|
|
target.classList.remove("sort-down");
|
|
|
|
} else {
|
2022-10-31 01:39:55 +04:00
|
|
|
g_tbody.append(...records);
|
2022-09-20 03:39:42 +04:00
|
|
|
target.classList.add("sort-down");
|
|
|
|
target.classList.remove("sort-up");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_sort_reverse = !g_sort_reverse;
|
2022-06-28 04:21:46 +04:00
|
|
|
}
|