diff --git a/app.js b/app.js index bfdd898..6622b7c 100644 --- a/app.js +++ b/app.js @@ -137,6 +137,12 @@ const preferencesMiddleware = (req, res, next) => { res.cookie('collapse_child_comments', collapseChildComments, { maxAge: 31536000, httpOnly: true }) } + let showUpvotedPercentage = req.query.show_upvoted_percentage + if(showUpvotedPercentage) { + req.cookies.show_upvoted_percentage = showUpvotedPercentage + res.cookie('show_upvoted_percentage', showUpvotedPercentage, { maxAge: 31536000, httpOnly: true }) + } + next() } diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index 0909246..8d3ebf0 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -29,6 +29,7 @@ module.exports = function(fetch) { id: post.id, domain: post.domain, contest_mode: post.contest_mode, + upvote_ratio: post.upvote_ratio, comments: null, has_media: false, media: null, diff --git a/routes.js b/routes.js index 92dce1a..10aff1d 100644 --- a/routes.js +++ b/routes.js @@ -1582,6 +1582,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { let highlight_controversial = req.body.highlight_controversial let post_media_max_height = req.body.post_media_max_height let collapse_child_comments = req.body.collapse_child_comments + let show_upvoted_percentage = req.body.show_upvoted_percentage res.cookie('theme', theme, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true }) @@ -1612,6 +1613,12 @@ module.exports = (app, redis, fetch, RedditAPI) => { collapse_child_comments = 'false' res.cookie('collapse_child_comments', collapse_child_comments, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true }) + if(show_upvoted_percentage === 'on') + show_upvoted_percentage = 'true' + else + show_upvoted_percentage = 'false' + res.cookie('show_upvoted_percentage', show_upvoted_percentage, { 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 1292747..78b4109 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -698,6 +698,11 @@ footer a { font-weight: bold; font-size: small; } +#post .ratio { + font-size: 0.6rem; + display: block; + padding: 4px 0px 5px 0px; +} #post .title { float: left; width: calc(100% - 60px); diff --git a/views/post.pug b/views/post.pug index 08ffa22..b647e20 100644 --- a/views/post.pug +++ b/views/post.pug @@ -41,6 +41,9 @@ html .score div.arrow span #{kFormatter(post.ups)} + if user_preferences.show_upvoted_percentage === 'true' + - let downvoted = parseInt(post.ups * (1 - post.upvote_ratio)) + span.ratio(title="~"+ downvoted +" downvoted") #{post.upvote_ratio * 100}% div.arrow.down .title a(href="" + post.url + "", rel="noopener noreferrer") @@ -80,6 +83,9 @@ html .score div.arrow span #{kFormatter(post.crosspost.ups)} + if user_preferences.show_upvoted_percentage === 'true' + - let downvoted = parseInt(post.ups * (1 - post.upvote_ratio)) + span.ratio(title="~"+ downvoted +" downvoted") #{post.upvote_ratio * 100}% div.arrow.down p.submitted span(title="" + toUTCString(post.crosspost.created) + "") submitted #{timeDifference(post.crosspost.created)} by diff --git a/views/preferences.pug b/views/preferences.pug index 65f348c..b893a0b 100644 --- a/views/preferences.pug +++ b/views/preferences.pug @@ -71,6 +71,12 @@ html input(type="checkbox", name="collapse_child_comments", id="collapse_child_comments", checked="checked") else input(type="checkbox", name="collapse_child_comments", id="collapse_child_comments") + .setting + label(for="show_upvoted_percentage") Show upvote ratio percentage in posts: + if(user_preferences.show_upvoted_percentage == 'true') + input(type="checkbox", name="show_upvoted_percentage", id="show_upvoted_percentage", checked="checked") + else + input(type="checkbox", name="show_upvoted_percentage", id="show_upvoted_percentage") legend Subscribed subreddits .setting details