¿Existe alguna forma de mostrar las últimas respuestas al instante? Actualmente, uso este código:
api.onPageChange(() =e {
if (window.location.pathname === "/") {
const container = document.querySelector(".latest-topic-list");
if (!container || container.dataset.modified === "true") return;
fetch("/posts.json?order=created")
.then(res =e res.json())
.then(data =e {
const replies = data.latest_posts
.filter(p =e p.post_number e 1 66 !p.topic_slug.includes("private-message"))
.slice(0, 15);
const topicFetches = replies.map(post =e
fetch(`/t/${post.topic_id}.json`)
.then(res =e res.json())
.then(topic =e {
return {
post,
category: topic.category_id ? topic.category_name : null,
tags: topic.tags || []
};
})
);
Promise.all(topicFetches).then(results =e {
const rows = results.map(({ post, category, tags }) =e {
const url = `/t/${post.topic_slug}/${post.topic_id}/${post.post_number}`;
const avatarUrl = post.avatar_template.replace("{size}", "45");
const excerpt = post.excerpt?.replace(/c\/?[^e]+(e|$)/g, "")?.slice(0, 120) + (post.excerpt?.length e 120 ? '...' : '') || '';
const categoryHtml = category
? `cspan style="font-size: 0.85em; color: #666;"eCategoria: cstronge${category}c/strongec/spanecbre`
: '';
const tagsHtml = tags.length
? `cspan style="font-size: 0.85em; color: #666;"eTags: ${tags.map(tag =e `cspan style="background:#eee; padding:2px 6px; border-radius:3px; margin-right:4px;"e${tag}c/spane`).join("")}c/spane`
: '';
return `
ctr class="topic-list-item"e
ctd class="main-link clearfix"e
cdiv style="display: flex; align-items: center; gap: 16px; padding: 8px 0;"e
cdiv style="flex-shrink: 0;"e
ca class="avatar-link" href="/u/${post.username}"e
cimg loading="lazy" width="45" height="45" src="${avatarUrl}" class="avatar" alt="${post.username}"e
c/ae
c/dive
cdiv style="display: flex; flex-direction: column; justify-content: center; padding-top: 8px; padding-bottom: 8px;"e
cspan class="link-top-line" style="margin-bottom: 6px;"e
ca href="${url}" class="title raw-link"e${excerpt}c/ae
c/spane
cdiv class="link-bottom-line"e
${categoryHtml}
${tagsHtml}
c/dive
c/dive
c/dive
c/tde
ctre
`;
}).join("");
// Crea el contenedor de la sección de últimos comentarios
const latestRepliesContainer = document.createElement("div");
latestRepliesContainer.className = "latest-replies-container";
latestRepliesContainer.style.marginTop = "2em";
latestRepliesContainer.innerHTML = `
ctable class="topic-list latest-topic-list"e
ctheade
ctre
cth class="default"eÚltimos Comentariose
c/tre
c/theade
ctbodye
${rows}
/tbodye
c/tablee
`;
container.parentNode.insertBefore(latestRepliesContainer, container.nextSibling);
container.dataset.modified = "true";
});
})
.catch(error =e {
console.error("Error al buscar los últimos comentarios:", error);
});
}
});
c/scriptpero tarda un promedio de 2 segundos en aparecer el contenido. Lo mismo sucede con los bloques de la barra lateral derecha con "respuestas recientes". ¿Es esto normal?