show stickied comments in posts

This commit is contained in:
teddit 2020-11-22 14:09:43 +01:00
parent 348e88fee4
commit f27f27041e
3 changed files with 29 additions and 7 deletions

3
dist/css/styles.css vendored
View File

@ -767,6 +767,9 @@ input[type="submit"]:hover,
float: left; float: left;
width: 100%; width: 100%;
} }
#post .comment .meta p.stickied {
color: green;
}
#post .comment .meta p.author a { #post .comment .meta p.author a {
font-weight: initial; font-weight: initial;
margin-left: 10px; margin-left: 10px;

View File

@ -6,27 +6,35 @@ module.exports = function() {
if(comments.author !== undefined && comments.body_html !== undefined) { if(comments.author !== undefined && comments.body_html !== undefined) {
let classlist = [] let classlist = []
let submitter_link = '' let submitter_link = ''
let moderator = false
let submitter = false
if(post_author === comments.author) { if(post_author === comments.author) {
classlist.push('submitter') classlist.push('submitter')
submitter_link = `<a href="${post_url}" title="submitter">[S]</a>` submitter_link = `<a href="${post_url}" title="submitter">[S]</a>`
submitter = true
} }
if(comments.author === 'AutoModerator') { if(comments.distinguished === 'moderator') {
classlist.push('green') classlist.push('green')
moderator_badge = ` <span class="green" title="moderator of this subreddit">[M]</span>`
moderator = true
} }
comments_html = ` comments_html = `
<div class="comment" id="${comments.id}"> <div class="comment" id="${comments.id}">
<details open> <details open>
<summary> <summary>
<a href="/u/${comments.author}">${comments.author}</a> <a href="/u/${comments.author}">${comments.author}${moderator ? moderator_badge : ''}</a>
<p class="ups">${kFormatter(comments.ups)} points</p> <p class="ups">${kFormatter(comments.ups)} points</p>
<p class="created" title="${toUTCString(comments.created)}">${timeDifference(comments.created)}</p> <p class="created" title="${toUTCString(comments.created)}">${timeDifference(comments.created)}</p>
<p class="stickied">${comments.stickied ? 'stickied comment' : ''}</p>
</summary> </summary>
<div class="meta"> <div class="meta">
<p class="author"><a href="/u/${comments.author}" class="${classlist.join(' ')}">${comments.author}</a>${comments.author === post_author ? submitter_link : ''}</p> <p class="author"><a href="/u/${comments.author}" class="${classlist.join(' ')}">${comments.author}</a>${submitter ? submitter_link : ''}${moderator ? moderator_badge : ''}</p>
<p class="ups">${kFormatter(comments.ups)} points</p> <p class="ups">${kFormatter(comments.ups)} points</p>
<p class="created" title="${toUTCString(comments.created)}"> <p class="created" title="${toUTCString(comments.created)}">
<a href="${comments.permalink}">${timeDifference(comments.created)}</a> <a href="${comments.permalink}">${timeDifference(comments.created)}</a>
</p> </p>
<p class="stickied">${comments.stickied ? 'stickied comment' : ''}</p>
</div> </div>
<div class="body">${unescape(comments.body_html)}</div> <div class="body">${unescape(comments.body_html)}</div>
` `
@ -74,28 +82,35 @@ module.exports = function() {
if(comment.type !== 'load_more') { if(comment.type !== 'load_more') {
let classlist = [] let classlist = []
let submitter_link = '' let submitter_link = ''
let moderator = false
let submitter = false
if(post_author === comment.author) { if(post_author === comment.author) {
classlist.push('submitter') classlist.push('submitter')
submitter_link = `<a href="${post_url}" title="submitter">[S]</a>` submitter_link = `<a href="${post_url}" title="submitter">[S]</a>`
submitter = true
} }
if(comment.author === 'AutoModerator') { if(comments.distinguished === 'moderator') {
classlist.push('green') classlist.push('green')
moderator_badge = ` <span class="green" title="moderator of this subreddit">[M]</span>`
moderator = true
} }
comments_html += ` comments_html += `
<div class="comment" id="${comment.id}"> <div class="comment" id="${comment.id}">
<details open> <details open>
<summary> <summary>
<a href="/u/${comment.author}">${comment.author}</a> <a href="/u/${comment.author}">${comment.author}${moderator ? moderator_badge : ''}</a>
<p class="ups">${kFormatter(comment.ups)} points</p> <p class="ups">${kFormatter(comment.ups)} points</p>
<p class="created" title="${toUTCString(comment.created)}">${timeDifference(comment.created)}</p> <p class="created" title="${toUTCString(comment.created)}">${timeDifference(comment.created)}</p>
<p class="stickied">${comment.stickied ? 'stickied comment' : ''}</p>
</summary> </summary>
<div class="meta"> <div class="meta">
<p class="author"><a href="/u/${comment.author}" class="${classlist.join(' ')}">${comment.author}</a>${comment.author === post_author ? submitter_link : ''}</p> <p class="author"><a href="/u/${comment.author}" class="${classlist.join(' ')}">${comment.author}</a>${submitter ? submitter_link : ''}${moderator ? moderator_badge : ''}</p>
<p class="ups">${kFormatter(comment.ups)} points</p> <p class="ups">${kFormatter(comment.ups)} points</p>
<p class="created" title="${toUTCString(comment.created)}"> <p class="created" title="${toUTCString(comment.created)}">
<a href="${comment.permalink}">${timeDifference(comment.created)}</a> <a href="${comment.permalink}">${timeDifference(comment.created)}</a>
</p> </p>
<p class="stickied">${comment.stickied ? 'stickied comment' : ''}</p>
</div> </div>
<div class="body">${unescape(comment.body_html)}</div> <div class="body">${unescape(comment.body_html)}</div>
` `

View File

@ -136,6 +136,8 @@ module.exports = function(fetch) {
ups: comment.ups, ups: comment.ups,
id: comment.id, id: comment.id,
permalink: comment.permalink, permalink: comment.permalink,
stickied: comment.stickied,
distinguished: comment.distinguished,
replies: [] replies: []
} }
} else { } else {
@ -208,6 +210,8 @@ module.exports = function(fetch) {
ups: reply.ups, ups: reply.ups,
id: reply.id, id: reply.id,
permalink: reply.permalink, permalink: reply.permalink,
stickied: reply.stickied,
distinguished: reply.distinguished,
replies: [] replies: []
} }
} else { } else {