1
0
mirror of https://codeberg.org/tacerus/teddit.git synced 2025-07-26 03:47:26 +02:00

Merge pull request 'main' () from teddit/teddit:main into changelog

Reviewed-on: https://codeberg.org/random_guy52/teddit/pulls/1
This commit is contained in:
random_guy52 2021-01-17 13:27:45 +01:00
commit e20c1a4691
4 changed files with 27 additions and 8 deletions

@ -40,6 +40,12 @@ const config = {
shorts: 60 * 60 * 24 * 31, shorts: 60 * 60 * 24 * 31,
wikis: 60* 60 * 24 * 7 wikis: 60* 60 * 24 * 7
}, },
convert_urls: {
/**
* When enabled, all the domains in the content (e.g. comments, sidebars, wikis etc.) will be replaced with a privacy respecting version.
*/
reddit: true, // old.reddit.com and reddit.com --> instance domain (config.domain)
},
valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.com'], valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.com'],
reddit_api_error_text: `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.` reddit_api_error_text: `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.`
}; };

@ -125,12 +125,15 @@ module.exports = function(request, fs) {
} }
this.toUTCString = (time) => { this.toUTCString = (time) => {
let d = new Date(); let d = new Date()
d.setTime(time*1000); d.setTime(time*1000)
return d.toUTCString(); return d.toUTCString()
} }
this.unescape = (s) => { this.unescape = (s) => {
/* It would make much more sense to rename this function to something
* like "formatter".
*/
if(s) { if(s) {
var re = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g; var re = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
var unescaped = { var unescaped = {
@ -145,9 +148,18 @@ module.exports = function(request, fs) {
'"': '"', '"': '"',
'"': '"' '"': '"'
} }
return s.replace(re, (m) => { if(config.convert_urls.reddit) {
return unescaped[m] let str = s.replace(re, (m) => {
}) return unescaped[m]
})
let r = new RegExp('((www|old)\.)?reddit.com', 'g')
let result = str.replace(r, config.domain)
return result
} else {
return s.replace(re, (m) => {
return unescaped[m]
})
}
} else { } else {
return '' return ''
} }

@ -54,7 +54,7 @@ module.exports = function() {
<p>${comments.user_flair}</p> <p>${comments.user_flair}</p>
<p class="ups">${ups}${controversial_span}</p> <p class="ups">${ups}${controversial_span}</p>
<p class="created" title="${toUTCString(comments.created)}"> <p class="created" title="${toUTCString(comments.created)}">
<a href="${comments.permalink}">${timeDifference(comments.created)}${edited_span}</a> <a href="${comments.permalink}#c">${timeDifference(comments.created)}${edited_span}</a>
</p> </p>
<p class="stickied">${comments.stickied ? 'stickied comment' : ''}</p> <p class="stickied">${comments.stickied ? 'stickied comment' : ''}</p>
</div> </div>
@ -150,7 +150,7 @@ module.exports = function() {
<p>${comment.user_flair}</p> <p>${comment.user_flair}</p>
<p class="ups">${ups}${controversial_span}</p> <p class="ups">${ups}${controversial_span}</p>
<p class="created" title="${toUTCString(comment.created)}"> <p class="created" title="${toUTCString(comment.created)}">
<a href="${comment.permalink}">${timeDifference(comment.created)}${edited_span}</a> <a href="${comment.permalink}#c">${timeDifference(comment.created)}${edited_span}</a>
</p> </p>
<p class="stickied">${comment.stickied ? 'stickied comment' : ''}</p> <p class="stickied">${comment.stickied ? 'stickied comment' : ''}</p>
</div> </div>

@ -974,6 +974,7 @@ footer a {
float: left; float: left;
font-size: smaller; font-size: smaller;
padding-right: 15px; padding-right: 15px;
width: auto;
} }
.subreddit-listing { .subreddit-listing {
margin: 8px 0px; margin: 8px 0px;