SHARE
TWEET

mastocomments test

a guest Oct 11th, 2018 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (window) {
  2.  
  3.     function mastocommentsLibrary() {
  4.         var _mastoComments = {};
  5.  
  6.         _mastoComments.settings = {
  7.             'instance_url': null,
  8.             'id': null,
  9.             'amountOfCommentsLoaded': 5,
  10.             'amountOfRepliesToNest': 1
  11.         };
  12.  
  13.         _mastoComments.load = function() {
  14.             let divId = "mastocomments";
  15.  
  16.             document.getElementById(divId).innerHTML = `<img src='loading.png'\>`;
  17.  
  18.             var xhttp = new XMLHttpRequest();
  19.             xhttp.open("GET", _mastoComments.settings.instance_url + "api/v1/statuses/" + _mastoComments.settings.id + "/context", true);
  20.             xhttp.send();
  21.             xhttp.onreadystatechange = function() {
  22.                 // TODO convert to the createElement thing
  23.                 if (this.readyState == 4 && this.status == 200) {
  24.                     var html = "<p>Comments</p>"
  25.                     var response = JSON.parse(xhttp.responseText).descendants;
  26.                     for (var x = Object.keys(response).length - 1; x > -1 ; x--) {
  27.                         console.log(response[x]);
  28.                         html += "<p><strong>" + response[x].account.username + "</strong>: " + response[x].content + "</p>";
  29.                     }
  30.                     document.getElementById(divId).innerHTML = html;
  31.                 }
  32.             }
  33.         }
  34.  
  35.         return _mastoComments;
  36.     }
  37.  
  38.     if (typeof(window.mastoComments) === 'undefined') {
  39.         window.mastoComments = mastocommentsLibrary();
  40.     }
  41. })(window);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top