mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
add config to disable floaters
This commit is contained in:
@@ -1358,6 +1358,59 @@
|
||||
$authentication.classList.add("open");
|
||||
}
|
||||
|
||||
function initFloaters() {
|
||||
const $floaters = document.getElementById("floaters"),
|
||||
colors = ["#8aadf4", "#c6a0f6", "#8bd5ca", "#91d7e3", "#b7bdf8"],
|
||||
count = Math.floor((window.outerHeight * window.outerWidth) / 98000);
|
||||
|
||||
function rand(a, b, rnd = false) {
|
||||
const num = Math.random() * (b - a) + a;
|
||||
|
||||
if (rnd) {
|
||||
return Math.floor(num);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
function place(el, init = false) {
|
||||
el.style.setProperty("--x", `${rand(0, 100).toFixed(4)}vw`);
|
||||
el.style.setProperty("--y", `${rand(0, 100).toFixed(4)}vh`);
|
||||
|
||||
if (init) {
|
||||
return;
|
||||
}
|
||||
|
||||
const time = rand(140, 160);
|
||||
|
||||
el.style.setProperty("--time", `${time.toFixed(2)}s`);
|
||||
|
||||
setTimeout(() => {
|
||||
place(el);
|
||||
}, time * 1000);
|
||||
}
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const el = document.createElement("div");
|
||||
|
||||
el.className = "floater";
|
||||
|
||||
el.style.setProperty("--size", `${rand(2, 4, true)}px`);
|
||||
el.style.setProperty("--color", colors[rand(0, colors.length, true)]);
|
||||
|
||||
$floaters.appendChild(el);
|
||||
|
||||
place(el, true);
|
||||
|
||||
setTimeout(
|
||||
() => {
|
||||
place(el);
|
||||
},
|
||||
rand(0, 1000, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const [_, data] = await Promise.all([connectDB(), json("/-/data")]);
|
||||
|
||||
@@ -1383,10 +1436,15 @@
|
||||
}
|
||||
|
||||
// update search availability
|
||||
searchAvailable = data.search;
|
||||
searchAvailable = data.config.search;
|
||||
|
||||
// initialize floaters (unless disabled)
|
||||
if (!data.config.motion) {
|
||||
initFloaters();
|
||||
}
|
||||
|
||||
// show login modal
|
||||
if (data.authentication && !data.authenticated) {
|
||||
if (data.config.authentication && !data.authenticated) {
|
||||
$authentication.classList.add("open");
|
||||
}
|
||||
|
||||
@@ -2022,56 +2080,3 @@
|
||||
document.body.classList.remove("loading");
|
||||
});
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const $floaters = document.getElementById("floaters"),
|
||||
colors = ["#8aadf4", "#c6a0f6", "#8bd5ca", "#91d7e3", "#b7bdf8"],
|
||||
count = Math.floor((window.outerHeight * window.outerWidth) / 98000);
|
||||
|
||||
function rand(a, b, rnd = false) {
|
||||
const num = Math.random() * (b - a) + a;
|
||||
|
||||
if (rnd) {
|
||||
return Math.floor(num);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
function place(el, init = false) {
|
||||
el.style.setProperty("--x", `${rand(0, 100).toFixed(4)}vw`);
|
||||
el.style.setProperty("--y", `${rand(0, 100).toFixed(4)}vh`);
|
||||
|
||||
if (init) {
|
||||
return;
|
||||
}
|
||||
|
||||
const time = rand(140, 160);
|
||||
|
||||
el.style.setProperty("--time", `${time.toFixed(2)}s`);
|
||||
|
||||
setTimeout(() => {
|
||||
place(el);
|
||||
}, time * 1000);
|
||||
}
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const el = document.createElement("div");
|
||||
|
||||
el.className = "floater";
|
||||
|
||||
el.style.setProperty("--size", `${rand(2, 4, true)}px`);
|
||||
el.style.setProperty("--color", colors[rand(0, colors.length, true)]);
|
||||
|
||||
$floaters.appendChild(el);
|
||||
|
||||
place(el, true);
|
||||
|
||||
setTimeout(
|
||||
() => {
|
||||
place(el);
|
||||
},
|
||||
rand(0, 1000, true)
|
||||
);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user