24 lines
1.0 KiB
JavaScript
24 lines
1.0 KiB
JavaScript
let load = false;
|
|
(() => {
|
|
const posts = document.querySelector("#posts");
|
|
if(posts) {
|
|
document.addEventListener("wheel", e => {
|
|
if((((document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop + window.innerHeight) + 310
|
|
>= ((document.documentElement && document.documentElement.scrollHeight) || document.body.scrollHeight)) && !load) {
|
|
load = true;
|
|
fetch(`./api/p/${posts.dataset.last}`)
|
|
.then(res => res.json())
|
|
.then((msg, html = "") => {
|
|
for(let i = 0; i < msg.items.length; i++)
|
|
if(msg.items[i].id)
|
|
html += `<li class="post"><a href="./${msg.items[i].id}" title="${msg.items[i].mime}"><img class="thumb" src="./t/${msg.items[i].id}.png" onerror="this.onerror=null;this.src='/s/img/mp3.png';" /></a></li>\n`;
|
|
posts.insertAdjacentHTML("beforeend", html);
|
|
posts.dataset.last = msg.last;
|
|
load = false;
|
|
})
|
|
.catch(err => console.log(err));
|
|
}
|
|
});
|
|
}
|
|
})();
|