Skip to content

Commit

Permalink
return html instead of json from initPageAsApi
Browse files Browse the repository at this point in the history
  • Loading branch information
RealDekkia committed Apr 21, 2024
1 parent 745957c commit b1c7f11
Showing 1 changed file with 54 additions and 39 deletions.
93 changes: 54 additions & 39 deletions thread/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const threadUnroll = {
initPageAsApi: function (instanceUri, statusID, callback) {
if (instanceUri && statusID && callback) {
threadUnroll.initApi(instanceUri);
threadUnroll.getAllStatuses(statusID, [], callback, true, statusID);
threadUnroll.getAllStatuses(statusID, [], function (x) {
threadUnroll.drawstatuses(x, callback);
}, true, statusID);
}
},
initApi: function (instanceUri) {
Expand Down Expand Up @@ -92,45 +94,52 @@ const threadUnroll = {
});
}
},
drawstatuses: function (statusArr) {
var mb = document.getElementById("mainBody");
mb.innerHTML = "";

//Draw header with info about the user and the thread
var userHeader = document.createElement("div");
userHeader.className = "userHeader";
userHeader.style.backgroundImage = "url(" + statusArr[0].account.header + ")";

var username = document.createElement("a");
username.className = "userName";
username.innerHTML = statusArr[0].account.display_name;
username.href = statusArr[0].account.url;
userHeader.appendChild(username);

if (statusArr[0].account.bot) {
var isBot = document.createElement("mark");
isBot.className = "userIsBot";
isBot.innerHTML = "Bot";
username.appendChild(isBot);
drawstatuses: function (statusArr, callback = false) {
var mb;
if (!callback) {
var mb = document.getElementById("mainBody");
mb.innerHTML = "";
} else {
mb = document.createElement("div");
}

var userImg = document.createElement("img");
userImg.className = "userImage";
userImg.alt = "Profile picture of " + statusArr[0].account.display_name;
userImg.src = statusArr[0].account.avatar;
userHeader.appendChild(userImg);
if (!callback) {
//Draw header with info about the user and the thread
var userHeader = document.createElement("div");
userHeader.className = "userHeader";
userHeader.style.backgroundImage = "url(" + statusArr[0].account.header + ")";

var username = document.createElement("a");
username.className = "userName";
username.innerHTML = statusArr[0].account.display_name;
username.href = statusArr[0].account.url;
userHeader.appendChild(username);

if (statusArr[0].account.bot) {
var isBot = document.createElement("mark");
isBot.className = "userIsBot";
isBot.innerHTML = "Bot";
username.appendChild(isBot);
}

var threadInfo = document.createElement("span");
var userImg = document.createElement("img");
userImg.className = "userImage";
userImg.alt = "Profile picture of " + statusArr[0].account.display_name;
userImg.src = statusArr[0].account.avatar;
userHeader.appendChild(userImg);

var threadInfoPostCnt = document.createElement("span");
threadInfoPostCnt.id = "threadInfoPostCnt";
threadInfo.appendChild(threadInfoPostCnt);
var threadInfo = document.createElement("span");

threadInfo.className = "threadInfo";
threadInfo.innerHTML += ", Created: " + new Date(statusArr[0].created_at).toLocaleString();
userHeader.appendChild(threadInfo);
var threadInfoPostCnt = document.createElement("span");
threadInfoPostCnt.id = "threadInfoPostCnt";
threadInfo.appendChild(threadInfoPostCnt);

mb.appendChild(userHeader);
threadInfo.className = "threadInfo";
threadInfo.innerHTML += ", Created: " + new Date(statusArr[0].created_at).toLocaleString();
userHeader.appendChild(threadInfo);

mb.appendChild(userHeader);
}

//Print all posts
var postCnt = 0;
Expand Down Expand Up @@ -228,11 +237,17 @@ const threadUnroll = {
}
});

document.getElementById("threadInfoPostCnt").innerHTML = postCnt;
if (postCnt == 1) {
document.getElementById("threadInfoPostCnt").innerHTML += " Post";
} else {
document.getElementById("threadInfoPostCnt").innerHTML += " Posts";
if (!callback) {
document.getElementById("threadInfoPostCnt").innerHTML = postCnt;
if (postCnt == 1) {
document.getElementById("threadInfoPostCnt").innerHTML += " Post";
} else {
document.getElementById("threadInfoPostCnt").innerHTML += " Posts";
}
}

if (callback) {
callback(mb);
}

}
Expand Down

0 comments on commit b1c7f11

Please sign in to comment.