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