You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
829 B
21 lines
829 B
let next;
|
|
const handleData = (data)=>{
|
|
if(data.posts.length > 0){
|
|
for(post of data.posts){
|
|
const li = document.createElement('li');
|
|
li.innerHTML = `<iframe id="reddit-embed" src="https://www.redditmedia.com/${post}?ref_source=embed&ref=share&embed=true" sandbox="allow-scripts allow-same-origin allow-popups" style="border: none;" scrolling="no" width="640" height="526"></iframe>`
|
|
document.querySelector('ul').appendChild(li)
|
|
next = data.next
|
|
}
|
|
}
|
|
}
|
|
|
|
window.addEventListener('DOMContentLoaded', (event) => {
|
|
fetch('/posts').then(response => response.json()).then(handleData);
|
|
});
|
|
document.addEventListener('scroll', (event)=>{
|
|
if(document.querySelector('body').scrollHeight == window.scrollY+window.innerHeight){
|
|
fetch('/posts/after/'+next).then(response => response.json()).then(handleData);
|
|
}
|
|
})
|