parent
e5ef421277
commit
9f82f07ab2
@ -1,7 +1,12 @@
|
||||
body {
|
||||
margin:0px;
|
||||
}
|
||||
li {
|
||||
display:inline-block;
|
||||
border:1px solid black;
|
||||
list-style:none;
|
||||
}
|
||||
ul {
|
||||
padding:0
|
||||
padding:0;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
})
|
||||
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link href="/app.css" rel="stylesheet"></link>
|
||||
<script src="/app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<ul>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,23 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link href="/app.css" rel="stylesheet"></link>
|
||||
</head>
|
||||
<body>
|
||||
<ul>
|
||||
<%for(let i = 0; i < posts.length; i++){%>
|
||||
<li>
|
||||
<iframe id="reddit-embed" src="https://www.redditmedia.com/<%=posts[i].data.permalink%>?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>
|
||||
</li>
|
||||
<%}%>
|
||||
</ul>
|
||||
<nav>
|
||||
<%if(previous){%>
|
||||
<a href="/before/<%=previous%>">Previous</a>
|
||||
<%}%>
|
||||
<%if(next){%>
|
||||
<a href="/after/<%=next%>">Next</a>
|
||||
<%}%>
|
||||
</nav>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in new issue