From 0ccc62ece57ff188116dd84c4f12139b66ffe9c5 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 31 Oct 2019 10:34:42 +0100 Subject: [PATCH] Add date & time, add support for subjects. --- README.adoc | 13 +++++++------ mastodon-api-comments.js | 30 +++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/README.adoc b/README.adoc index d49ee25..3675d61 100644 --- a/README.adoc +++ b/README.adoc @@ -49,11 +49,13 @@ The generated HTML uses these classes: [options="header"] |=============================================================== -| Name | Description -| mastodon-api-comments | Encompasses everything. -| mastodon-api-comment-intro | The introduction sentence. -| mastodon-api-comment | A complete comment. -| mastodon-api-comment-author | The author portion the comment. +| Name | Description +| mastodon-api-comments | Encompasses everything. +| mastodon-api-comment-intro | The introduction sentence. +| mastodon-api-comment | A complete comment. +| mastodon-api-comment-author | The author line the comment. +| mastodon-api-comment-subject | The subject of the comment. +| mastodon-api-comment-content | The text the comment. |=============================================================== ==== Example CSS @@ -64,7 +66,6 @@ The generated HTML uses these classes: { margin-left: 1em; border: 0.1em solid black; - padding: 0.1em 1em; } .mastodon-api-comment:nth-child(even) { diff --git a/mastodon-api-comments.js b/mastodon-api-comments.js index 7fc573d..bca862e 100644 --- a/mastodon-api-comments.js +++ b/mastodon-api-comments.js @@ -53,19 +53,39 @@ function write_comments(root, data) const p = document.createElement("p"); p.setAttribute("class", "mastodon-api-comment"); - p.appendChild(author_html(status.account)); - p.innerHTML += content; + p.appendChild(author_html(status)); + if (status.spoiler_text.length > 0) + { + const subject_p = document.createElement("p"); + subject_p.setAttribute("class", "mastodon-api-comment-subject"); + const subject = document.createElement("strong"); + subject.appendChild(document.createTextNode(status.spoiler_text)); + subject_p.appendChild(subject); + p.appendChild(subject_p); + } + const content_p = document.createElement("p"); + content_p.setAttribute("class", "mastodon-api-comment-content"); + content_p.appendChild(document.createTextNode(content)); + p.appendChild(content_p); root.appendChild(p); } } -function author_html(account) +function author_html(status) { const p = document.createElement("p"); p.setAttribute("class", "mastodon-api-comment-author"); const strong = document.createElement("strong"); - strong.appendChild(document.createTextNode(account.display_name)); + strong.appendChild(document.createTextNode(status.account.display_name)); p.appendChild(strong); - p.appendChild(document.createTextNode(" (" + account.acct + ") wrote:")); + p.appendChild( + document.createTextNode(" (" + status.account.acct + ") wrote on " + + get_status_time(status) + ":")); return p; } + +// Human readable time, YYYY-MM-DD HH:MM. +function get_status_time(status) +{ + return status.created_at.substr(0, 16).replace('T', ' '); +}