Merge pull request 'main' (#1) 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

View File

@ -40,6 +40,12 @@ const config = {
shorts: 60 * 60 * 24 * 31,
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'],
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.`
};

View File

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

View File

@ -54,7 +54,7 @@ module.exports = function() {
<p>${comments.user_flair}</p>
<p class="ups">${ups}${controversial_span}</p>
<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 class="stickied">${comments.stickied ? 'stickied comment' : ''}</p>
</div>
@ -150,7 +150,7 @@ module.exports = function() {
<p>${comment.user_flair}</p>
<p class="ups">${ups}${controversial_span}</p>
<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 class="stickied">${comment.stickied ? 'stickied comment' : ''}</p>
</div>

View File

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