add: expand infinite scrolling to stacks and profiles

This commit is contained in:
trisua 2025-06-17 14:28:18 -04:00
parent 2b253c811c
commit 3027b679db
16 changed files with 226 additions and 288 deletions

View file

@ -25,10 +25,10 @@ function media_theme_pref() {
}
}
function set_theme(theme) {
window.set_theme = (theme) => {
window.localStorage.setItem("tetratto:theme", theme);
document.documentElement.className = theme;
}
};
media_theme_pref();
@ -91,7 +91,7 @@ media_theme_pref();
self.define("rel_date", (_, date) => {
// stolen and slightly modified because js dates suck
const diff = Math.abs((new Date().getTime() - date.getTime()) / 1000);
const diff = Math.abs((Date.now() - date.getTime()) / 1000);
const day_diff = Math.floor(diff / 86400);
if (Number.isNaN(day_diff) || day_diff < 0 || day_diff >= 31) {
@ -396,7 +396,7 @@ media_theme_pref();
counter.innerText = `${target.value.length}/${target.getAttribute("maxlength")}`;
});
self.define("hooks::character_counter.init", (_, event) => {
self.define("hooks::character_counter.init", (_) => {
for (const element of Array.from(
document.querySelectorAll("[hook=counter]") || [],
)) {
@ -413,7 +413,7 @@ media_theme_pref();
element.innerHTML = full_text;
});
self.define("hooks::long_text.init", (_, event) => {
self.define("hooks::long_text.init", (_) => {
for (const element of Array.from(
document.querySelectorAll("[hook=long]") || [],
)) {
@ -493,13 +493,13 @@ media_theme_pref();
});
self.define("last_seen_just_now", (_, last_seen) => {
const now = new Date().getTime();
const now = Date.now();
const maximum_time_to_be_considered_online = 60000 * 2; // 2 minutes
return now - last_seen <= maximum_time_to_be_considered_online;
});
self.define("last_seen_recently", (_, last_seen) => {
const now = new Date().getTime();
const now = Date.now();
const maximum_time_to_be_considered_idle = 60000 * 5; // 5 minutes
return now - last_seen <= maximum_time_to_be_considered_idle;
});
@ -585,8 +585,8 @@ media_theme_pref();
self.define(
"hooks::attach_to_partial",
({ $ }, partial, full, attach, wrapper, page, run_on_load) => {
return new Promise((resolve, reject) => {
({ $ }, partial, full, attach, wrapper, page) => {
return new Promise((resolve, _) => {
async function load_partial() {
const url = `${partial}${partial.includes("?") ? "&" : "?"}page=${page}`;
history.replaceState(
@ -1148,6 +1148,8 @@ ${option.input_element_type === "textarea" ? `${option.value}</textarea>` : ""}
"[ui_ident=io_data_load]",
);
self.IO_HTML_TMPL = document.getElementById("loading_skeleton");
if (!self.IO_DATA_ELEMENT || !self.IO_DATA_MARKER) {
console.warn(
"ui::io_data_load called, but required elements don't exist",
@ -1167,14 +1169,19 @@ ${option.input_element_type === "textarea" ? `${option.value}</textarea>` : ""}
self.IO_DATA_PAGE += 1;
console.log("load page", self.IO_DATA_PAGE);
// show loading component
const loading = self.IO_HTML_TMPL.content.cloneNode(true);
self.IO_DATA_ELEMENT.appendChild(loading);
// ...
const text = await (
await fetch(`${self.IO_DATA_TMPL}${self.IO_DATA_PAGE}`)
).text();
self.IO_DATA_ELEMENT.querySelector("[ui_ident=loading_skel]").remove();
if (
text.includes(
`That's a wrap!<!-- observer_disconnect_${window.BUILD_CODE} -->`,
)
text.includes(`!<!-- observer_disconnect_${window.BUILD_CODE} -->`)
) {
console.log("io_data_end; disconnect");
self.IO_DATA_OBSERVER.disconnect();
@ -1251,7 +1258,7 @@ ${option.input_element_type === "textarea" ? `${option.value}</textarea>` : ""}
self.define(
"open",
async ({ $ }, warning_id, warning_hash, warning_page = "") => {
async (_, warning_id, warning_hash, warning_page = "") => {
// check localStorage for this warning_id
if (accepted_warnings[warning_id] !== undefined) {
// check hash
@ -1272,7 +1279,7 @@ ${option.input_element_type === "textarea" ? `${option.value}</textarea>` : ""}
},
);
self.define("accept", ({ _ }, warning_id, warning_hash) => {
self.define("accept", (_, warning_id, warning_hash) => {
accepted_warnings[warning_id] = warning_hash;
window.localStorage.setItem(