recent comments!
[Ultimately_Untrue_Thought.git] / theme / static / js / recent_comments.js
1
2 function getRecentComments() {
3     let container = document.querySelector("#recent-comments-container");
4     console.log(container);
5
6     let request = new XMLHttpRequest();
7     request.open('GET', 'http://unremediatedgender.space/isso/latest?limit=5', true);
8
9     request.onload = function() {
10         if (this.status >= 200 && this.status < 400) {
11             let comments = JSON.parse(this.response);
12             console.log(comments);
13             for (let comment of comments.reverse()) {
14                 let p = document.createElement('p');
15                 let a = document.createElement('a');
16                 let text = document.createTextNode(`${comment.author} on ${comment.uri}`);
17                 a.appendChild(text);
18                 a.href = `${comment.uri}#isso-${comment.id}`;
19                 p.appendChild(a);
20                 container.appendChild(p);
21             }
22         } else {
23             container.textContent = "(could not load recent comments)"
24         }
25     };
26
27     request.onerror = function() {
28         "(could not load recent comments)"
29     };
30
31     request.send();
32 }
33
34 document.addEventListener("DOMContentLoaded", function() {
35     getRecentComments();
36 });