diff --git a/app.js b/app.js index 37a0e6b..2ae20d8 100644 --- a/app.js +++ b/app.js @@ -117,6 +117,12 @@ const preferencesMiddleware = (req, res, next) => { req.cookies.nsfw_enabled = nsfwEnabledOverride res.cookie('nsfw_enabled', nsfwEnabledOverride, { maxAge: 31536000, httpOnly: true }) } + + let highlightControversialOverride = req.query.highlight_controversial + if(highlightControversialOverride) { + req.cookies.highlight_controversial = highlightControversialOverride + res.cookie('highlight_controversial', highlightControversialOverride, { maxAge: 31536000, httpOnly: true }) + } next() } diff --git a/config.js.template b/config.js.template index 7879525..6e078f8 100644 --- a/config.js.template +++ b/config.js.template @@ -4,6 +4,7 @@ const config = { cert_dir: process.env.CERT_DIR || '', // For example '/home/teddit/letsencrypt/live/teddit.net', if you are using https. No trailing slash. theme: process.env.THEME || 'dark', // One of: 'dark', '' flairs_enabled: process.env.FLAIRS_ENABLED !== 'true' || true, // Enables the rendering of user and link flairs on teddit + highlight_controversial: process.env.HIGHLIGHT_CONTROVERSIAL !== 'true' || true, // Enables controversial comments to be indicated by a typographical dagger (†) api_enabled: process.env.API_ENABLED !== 'true' || true, // Teddit API feature. Might increase loads significantly on your instance. video_enabled: process.env.VIDEO_ENABLED !== 'true' || true, redis_enabled: process.env.REDIS_ENABLED !== 'true' || true, // If disabled, does not cache Reddit API calls diff --git a/inc/compilePostComments.js b/inc/compilePostComments.js index 5639d36..7dd58a0 100644 --- a/inc/compilePostComments.js +++ b/inc/compilePostComments.js @@ -17,6 +17,7 @@ module.exports = function() { let moderator = false let submitter = false let edited_span = '' + let controversial_span = '' if(post_author === comments.author) { classlist.push('submitter') @@ -36,6 +37,9 @@ module.exports = function() { if(comments.edited) { edited_span = `*` } + if(comments.controversiality > 0) { + controversial_span = `` + } comments_html = `
@@ -48,7 +52,7 @@ module.exports = function() {

${commentAuthor(comments, classlist, submitter && submitter_link, moderator && moderator_badge)}

${comments.user_flair}

-

${ups}

+

${ups}${controversial_span}

${timeDifference(comments.created)}${edited_span}

@@ -109,6 +113,7 @@ module.exports = function() { let submitter = false let ups = '' let edited_span = '' + let controversial_span = '' if(post_author === comment.author) { classlist.push('submitter') @@ -128,6 +133,9 @@ module.exports = function() { if(comment.edited) { edited_span = `*` } + if(comment.controversiality > 0) { + controversial_span = `` + } comments_html += `
@@ -140,7 +148,7 @@ module.exports = function() {

${commentAuthor(comment, classlist, submitter && submitter_link, moderator && moderator_badge)}

${comment.user_flair}

-

${ups}

+

${ups}${controversial_span}

${timeDifference(comment.created)}${edited_span}

diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index 48234f3..1c2e9c3 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -153,7 +153,8 @@ module.exports = function(fetch) { edited: comment.edited, replies: [], depth: 0, - user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(comment) : '') + user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(comment) : ''), + controversiality: (user_preferences.highlight_controversial != 'false' ? comment.controversiality : '') } } else { obj = { @@ -231,7 +232,8 @@ module.exports = function(fetch) { edited: reply.edited, replies: [], depth: depth, - user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(reply) : '') + user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(reply) : ''), + controversiality: (user_preferences.highlight_controversial != 'false' ? reply.controversiality : '') } } else { obj = { @@ -267,7 +269,8 @@ module.exports = function(fetch) { distinguished: comment.edited, replies: [], depth: depth + 1, - user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(comment) : '') + user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(comment) : ''), + controversiality: (user_preferences.highlight_controversial != 'false' ? comment.controversiality : '') } } else { objct = { diff --git a/routes.js b/routes.js index 4f2a6ca..174a695 100644 --- a/routes.js +++ b/routes.js @@ -22,6 +22,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { res.clearCookie('theme') res.clearCookie('flairs') res.clearCookie('nsfw_enabled') + res.clearCookie("highlight_controversial") return res.redirect('/preferences') }) @@ -783,6 +784,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { let theme = req.body.theme let flairs = req.body.flairs let nsfw_enabled = req.body.nsfw_enabled + let highlight_controversial = req.body.highlight_controversial res.cookie('theme', theme, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true }) @@ -797,7 +799,13 @@ module.exports = (app, redis, fetch, RedditAPI) => { else nsfw_enabled = 'false' res.cookie('nsfw_enabled', nsfw_enabled, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true }) - + + if(highlight_controversial === 'on') + highlight_controversial = 'true' + else + highlight_controversial = 'false' + res.cookie('highlight_controversial', highlight_controversial, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true }) + return res.redirect('/preferences') }) diff --git a/static/css/styles.css b/static/css/styles.css index 787d8cf..afd819c 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -640,6 +640,13 @@ footer a { .comment .meta .created a { color: var(--graytext); } +.comment .meta span.controversial { + font-size: var(--sm-font); + display:inline-block; + vertical-align: baseline; + position: relative; + top: -0.4em; +} .comment .body { float: left; width: 100%; diff --git a/views/preferences.pug b/views/preferences.pug index cfc27db..9ab1d57 100644 --- a/views/preferences.pug +++ b/views/preferences.pug @@ -25,6 +25,12 @@ html input(type="checkbox", name="flairs", id="flairs", checked="checked") else input(type="checkbox", name="flairs", id="flairs") + .setting + label(for="highlight_controversial") Show a dagger (†) on comments voted controversial: + if(!user_preferences.highlight_controversial || user_preferences.highlight_controversial == 'true') + input(type="checkbox", name="highlight_controversial", id="highlight_controversial", checked="checked") + else + input(type="checkbox", name="highlight_controversial", id="highlight_controversial") .setting label(for="nsfw_enabled") Show NSFW content: if (instance_config.nsfw_enabled === false && user_preferences.nsfw_enabled != 'true') || user_preferences.nsfw_enabled === 'false'