X-Git-Url: http://unremediatedgender.space/source?p=Ultimately_Untrue_Thought.git;a=blobdiff_plain;f=theme%2Fstatic%2Fjs%2Fcomment_counts.js;fp=theme%2Fstatic%2Fjs%2Fcomment_counts.js;h=d0df09b98e80f307c981403bc6a5946a42100f00;hp=0000000000000000000000000000000000000000;hb=b185f09fa25daa55ae4e50dbe00ada569377e744;hpb=e34aa9e4600b157348375883b7640523fc6bee9a diff --git a/theme/static/js/comment_counts.js b/theme/static/js/comment_counts.js new file mode 100644 index 0000000..d0df09b --- /dev/null +++ b/theme/static/js/comment_counts.js @@ -0,0 +1,30 @@ +function placeCommentCounts() { + let containers = Array.from(document.querySelectorAll(".comments-link-container")); + let paths = containers.map(function(span) { return span.dataset.path; }); + + let request = new XMLHttpRequest(); + + request.open('POST', 'http://unremediatedgender.space/isso/count', true); + request.setRequestHeader("Content-Type", "application/json"); + request.send(JSON.stringify(paths)); + + request.onload = function() { + if (this.status >= 200 && this.status < 400) { + let counts = JSON.parse(this.response); + for (let [i, container] of containers.entries()) { + let a = document.createElement('a'); + let count = counts[i]; + let pluralizer = count === 1 ? "" : "s"; + let text = document.createTextNode(`${count} comment${pluralizer}`); + a.appendChild(text); + a.href = `${paths[i]}#isso-thread`; + container.appendChild(a); + } + } + }; + +} + +document.addEventListener("DOMContentLoaded", function() { + placeCommentCounts(); +});