Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (window) {
- function mastocommentsLibrary() {
- var _mastoComments = {};
- _mastoComments.settings = {
- 'instance_url': null,
- 'id': null,
- 'amountOfCommentsLoaded': 5,
- 'amountOfRepliesToNest': 1
- };
- _mastoComments.load = function() {
- let divId = "mastocomments";
- document.getElementById(divId).innerHTML = `<img src='loading.png'\>`;
- var xhttp = new XMLHttpRequest();
- xhttp.open("GET", _mastoComments.settings.instance_url + "api/v1/statuses/" + _mastoComments.settings.id + "/context", true);
- xhttp.send();
- xhttp.onreadystatechange = function() {
- // TODO convert to the createElement thing
- if (this.readyState == 4 && this.status == 200) {
- var html = "<p>Comments</p>"
- var response = JSON.parse(xhttp.responseText).descendants;
- for (var x = Object.keys(response).length - 1; x > -1 ; x--) {
- console.log(response[x]);
- html += "<p><strong>" + response[x].account.username + "</strong>: " + response[x].content + "</p>";
- }
- document.getElementById(divId).innerHTML = html;
- }
- }
- }
- return _mastoComments;
- }
- if (typeof(window.mastoComments) === 'undefined') {
- window.mastoComments = mastocommentsLibrary();
- }
- })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement