X-Git-Url: http://unremediatedgender.space/source?a=blobdiff_plain;f=theme%2Fstatic%2Fjs%2Frecent_comments.js;fp=theme%2Fstatic%2Fjs%2Frecent_comments.js;h=18ee00691d20527ef2ea32669cf505ec2b1cf30a;hb=0f9374a08228965c207e0d77fd5adc701a3b461b;hp=0000000000000000000000000000000000000000;hpb=c25ced8c462d48f0c8667ec64634e8b57bf371ed;p=Ultimately_Untrue_Thought.git diff --git a/theme/static/js/recent_comments.js b/theme/static/js/recent_comments.js new file mode 100644 index 0000000..18ee006 --- /dev/null +++ b/theme/static/js/recent_comments.js @@ -0,0 +1,36 @@ + +function getRecentComments() { + let container = document.querySelector("#recent-comments-container"); + console.log(container); + + let request = new XMLHttpRequest(); + request.open('GET', 'http://unremediatedgender.space/isso/latest?limit=5', true); + + request.onload = function() { + if (this.status >= 200 && this.status < 400) { + let comments = JSON.parse(this.response); + console.log(comments); + for (let comment of comments.reverse()) { + let p = document.createElement('p'); + let a = document.createElement('a'); + let text = document.createTextNode(`${comment.author} on ${comment.uri}`); + a.appendChild(text); + a.href = `${comment.uri}#isso-${comment.id}`; + p.appendChild(a); + container.appendChild(p); + } + } else { + container.textContent = "(could not load recent comments)" + } + }; + + request.onerror = function() { + "(could not load recent comments)" + }; + + request.send(); +} + +document.addEventListener("DOMContentLoaded", function() { + getRecentComments(); +});