forked from Freakybob-Team/Freakybob.site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pikidiary.html
91 lines (77 loc) · 3.42 KB
/
pikidiary.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/article-frame.css">
<script src="js/fittext.js" defer></script>
</head>
<body>
<div class="article-cont">
<!-- Posts will be dynamically inserted here -->
</div>
<div id="fillSpace" class="fill-space">
<p>You're all caught up!</p>
<p>code completely stolen from <a href="https://graybox.lol/frames/web">https://graybox.lol/frames/web</a> :3</p>
</div>
<script>
async function fetchPosts() {
try {
const response = await fetch('https://pikidiary.lol/api/posts/freakybob');
const posts = await response.json();
renderPosts(posts);
} catch (error) {
console.error('Error fetching posts:', error);
}
}
function stripLinks(content) {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = content;
const links = tempDiv.getElementsByTagName('a');
while (links.length > 0) {
const link = links[0];
link.replaceWith(link.textContent);
}
return tempDiv.innerHTML;
}
function renderPosts(posts) {
const articleCont = document.querySelector('.article-cont');
posts.forEach(post => {
const articleCard = document.createElement('div');
articleCard.className = 'article-card';
articleCard.style.height = 'fit-content';
const cleanedContent = stripLinks(post.content);
const articleCol = `
<div class="article-col" style="width: 160px; grid-template-rows: auto auto 1fr; cursor: pointer;" onclick="window.open('https://pikidiary.lol/posts/${post.id}', '_blank')">
<div style="grid-column: 1 / -1; grid-row: 1;">
${cleanedContent}
</div>
<div style="grid-column: 1 / -1; grid-row: 2;">
<div class="divider" style="width: 100%; height: 16px;"></div>
</div>
<div style="grid-column: 1 / 3; grid-row: 3;">
<div class="divider" style="width: 100%; height: 8px;"></div>
</div>
<div style="grid-column: 3 / -1; grid-row: 3; position: relative;">
<span style="font-size: 11px; position: absolute; bottom: 0; right: 0; color: #CCC;">${post.created_at} ◂◂</span>
</div>
</div>
`;
articleCard.innerHTML = articleCol;
articleCont.appendChild(articleCard);
});
checkFillSpace();
}
function checkFillSpace() {
const fillSpace = document.getElementById('fillSpace');
if (document.body.scrollHeight > window.innerHeight) {
fillSpace.classList.add('bottom');
} else {
fillSpace.style.height = (window.innerHeight - document.body.scrollHeight) + 'px';
}
}
window.onload = fetchPosts;
</script>
<!-- this was completely stolen from https://graybox.lol/frames/web :3-->
</body>
</html>