68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
(() => {
|
||
const links = new Map([...document.querySelectorAll(".settings-nav a")].map(link => [link.hash.slice(1), link]));
|
||
if (links.size === 0) {
|
||
return;
|
||
}
|
||
|
||
const lastId = [...links.keys()].at(-1);
|
||
const atBottom = () => window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 4;
|
||
const activate = id => {
|
||
links.forEach(link => link.classList.toggle("active", link === links.get(id)));
|
||
};
|
||
|
||
const observer = new IntersectionObserver(entries => {
|
||
if (atBottom()) {
|
||
activate(lastId);
|
||
return;
|
||
}
|
||
|
||
const visible = entries.find(entry => entry.isIntersecting);
|
||
if (visible) {
|
||
activate(visible.target.id);
|
||
}
|
||
}, { rootMargin: "-20% 0px -70% 0px" });
|
||
|
||
links.forEach((link, id) => {
|
||
const section = document.getElementById(id);
|
||
if (section) {
|
||
observer.observe(section);
|
||
}
|
||
|
||
link.addEventListener("click", () => activate(id));
|
||
});
|
||
|
||
window.addEventListener("scroll", () => {
|
||
if (atBottom()) {
|
||
activate(lastId);
|
||
}
|
||
}, { passive: true });
|
||
|
||
if (location.hash && links.has(location.hash.slice(1))) {
|
||
activate(location.hash.slice(1));
|
||
}
|
||
})();
|
||
|
||
(() => {
|
||
const value = id => Number.parseInt(document.getElementById(id)?.value ?? "", 10);
|
||
const output = document.getElementById("drip-bandwidth");
|
||
if (!output) {
|
||
return;
|
||
}
|
||
|
||
const update = () => {
|
||
const minDelay = value("drip-min-delay");
|
||
const maxDelay = value("drip-max-delay");
|
||
const minChunk = value("drip-min-chunk");
|
||
const maxChunk = value("drip-max-chunk");
|
||
const averageDelay = (minDelay + maxDelay) / 2000;
|
||
const bytesPerSecond = (minChunk + maxChunk) / 2 / averageDelay;
|
||
output.textContent = Number.isFinite(bytesPerSecond) && bytesPerSecond > 0
|
||
? bytesPerSecond.toLocaleString("de-DE", { maximumFractionDigits: bytesPerSecond < 10 ? 1 : 0 })
|
||
: "–";
|
||
};
|
||
|
||
for (const input of document.querySelectorAll("[data-bandwidth-input]")) {
|
||
input.addEventListener("input", update);
|
||
}
|
||
})();
|