-
Notifications
You must be signed in to change notification settings - Fork 0
/
adder.js
42 lines (35 loc) · 1.05 KB
/
adder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { render } from './render.js'
const addPosts = async (posts, div) => {
for (const post of posts) {
const rendered = await render(post)
if (div.firstChild) {
div.firstChild.before(rendered)
} else {
div.appendChild(rendered)
}
}
}
export const adder = (log, src, div) => {
if (log && log[0]) {
let index = 0
const reverse = log.slice().reverse()
let posts = reverse.slice(index, index + 25)
addPosts(posts, div)
index = index + 25
window.onscroll = () => {
if ((window.scrollX + window.scrollY == 0) && window.location.hash.substring(1) === src) {
posts = reverse.slice(index, index + 25)
index = index + 25
addPosts(posts, div)
}
}
const topChecker = setInterval(() => {
if (!posts.length) { clearInterval(topChecker)}
else if ((window.scrollX + window.scrollY == 0) && window.location.hash.substring(1) === src) {
posts = reverse.slice(index, index + 25)
index = index + 25
addPosts(posts, div)
}
}, 1000)
}
}