mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-22 06:49:26 +01:00
replace youtube/twitter/instagram with privacy respecting ones
This commit is contained in:
parent
d963c14155
commit
3e9868fd5e
@ -55,12 +55,6 @@ const config = {
|
||||
new_page: 60
|
||||
},
|
||||
},
|
||||
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_embed_video_domains: ['gfycat.com', 'youtube.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.`
|
||||
|
@ -130,7 +130,9 @@ module.exports = function(request, fs) {
|
||||
return d.toUTCString()
|
||||
}
|
||||
|
||||
this.unescape = (s) => {
|
||||
|
||||
|
||||
this.unescape = (s, user_preferences) => {
|
||||
/* It would make much more sense to rename this function to something
|
||||
* like "formatter".
|
||||
*/
|
||||
@ -148,23 +150,44 @@ module.exports = function(request, fs) {
|
||||
'"': '"',
|
||||
'"': '"'
|
||||
}
|
||||
if(config.convert_urls.reddit) {
|
||||
let str = s.replace(re, (m) => {
|
||||
let result = s.replace(re, (m) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
let r = /([A-z.]+\.)?(reddit(\.com)|redd(\.it))/gm;
|
||||
let result = str.replace(r, config.domain)
|
||||
|
||||
result = replacePrivacyDomains(result, user_preferences)
|
||||
|
||||
return result
|
||||
} else {
|
||||
return s.replace(re, (m) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
this.replacePrivacyDomains = (str, user_preferences) => {
|
||||
if(typeof(user_preferences) == 'undefined')
|
||||
return str
|
||||
|
||||
let redditRegex = /([A-z.]+\.)?(reddit(\.com)|redd(\.it))/gm;
|
||||
let youtubeRegex = /([A-z.]+\.)?youtu(be\.com|\.be)/gm;
|
||||
let twitterRegex = /([A-z.]+\.)?twitter\.com/gm;
|
||||
let instagramRegex = /([A-z.]+\.)?instagram.com/gm;
|
||||
|
||||
str = str.replace(redditRegex, config.domain)
|
||||
|
||||
if(typeof(user_preferences.domain_youtube) != 'undefined')
|
||||
if(user_preferences.domain_youtube)
|
||||
str = str.replace(youtubeRegex, user_preferences.domain_youtube)
|
||||
|
||||
if(typeof(user_preferences.domain_twitter) != 'undefined')
|
||||
if(user_preferences.domain_twitter)
|
||||
str = str.replace(twitterRegex, user_preferences.domain_twitter)
|
||||
|
||||
if(typeof(user_preferences.domain_instagram) != 'undefined')
|
||||
if(user_preferences.domain_instagram)
|
||||
str = str.replace(instagramRegex, user_preferences.domain_instagram)
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
this.deleteFiles = (files, callback) => {
|
||||
var i = files.length
|
||||
files.forEach((filepath) => {
|
||||
|
@ -24,7 +24,7 @@ module.exports = function(fetch) {
|
||||
over_18: post.over_18,
|
||||
permalink: teddifyUrl(post.permalink),
|
||||
title: post.title,
|
||||
url: teddifyUrl(post.url),
|
||||
url: teddifyUrl(post.url, user_preferences),
|
||||
ups: post.ups,
|
||||
id: post.id,
|
||||
domain: post.domain,
|
||||
|
@ -91,7 +91,7 @@ module.exports = function() {
|
||||
title: data.title,
|
||||
ups: data.ups,
|
||||
upvote_ratio: data.upvote_ratio,
|
||||
url: data.url,
|
||||
url: replacePrivacyDomains(data.url, user_preferences),
|
||||
stickied: data.stickied,
|
||||
is_self_link: is_self_link,
|
||||
subreddit_front: subreddit_front,
|
||||
|
@ -64,7 +64,7 @@ module.exports = function() {
|
||||
title: post.title,
|
||||
created: post.created_utc,
|
||||
ups: post.ups,
|
||||
url: url,
|
||||
url: replacePrivacyDomains(url, user_preferences),
|
||||
thumbnail: await downloadAndSave(post.thumbnail),
|
||||
duration: duration,
|
||||
edited: post.edited,
|
||||
@ -83,7 +83,7 @@ module.exports = function() {
|
||||
created: post.created_utc,
|
||||
subreddit_name_prefixed: post.subreddit_name_prefixed,
|
||||
ups: post.ups,
|
||||
url: url,
|
||||
url: replacePrivacyDomains(url, user_preferences),
|
||||
edited: post.edited,
|
||||
body_html: unescape(post.body_html),
|
||||
num_comments: post.num_comments,
|
||||
|
@ -72,7 +72,7 @@ module.exports = function() {
|
||||
link_flair_text: post.link_flair_text,
|
||||
ups: post.ups,
|
||||
images: images,
|
||||
url: post.url,
|
||||
url: replacePrivacyDomains(post.url, user_preferences),
|
||||
edited: post.edited,
|
||||
selftext_html: unescape(post.body_html),
|
||||
num_comments: post.num_comments,
|
||||
|
@ -36,7 +36,7 @@ module.exports = function() {
|
||||
display_name: data.display_name,
|
||||
display_name_prefixed: data.display_name_prefixed,
|
||||
public_description: data.public_description,
|
||||
url: data.url,
|
||||
url: replacePrivacyDomains(data.url, user_preferences),
|
||||
subscribers: data.subscribers,
|
||||
over_18: data.over18,
|
||||
title: data.title,
|
||||
|
10
routes.js
10
routes.js
@ -1598,6 +1598,9 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
||||
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
|
||||
let domain_twitter = req.body.domain_twitter
|
||||
let domain_youtube = req.body.domain_youtube
|
||||
let domain_instagram = req.body.domain_instagram
|
||||
|
||||
res.cookie('theme', theme, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true })
|
||||
|
||||
@ -1634,6 +1637,10 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
||||
show_upvoted_percentage = 'false'
|
||||
res.cookie('show_upvoted_percentage', show_upvoted_percentage, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true })
|
||||
|
||||
res.cookie('domain_twitter', domain_twitter, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true })
|
||||
res.cookie('domain_youtube', domain_youtube, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true })
|
||||
res.cookie('domain_instagram', domain_instagram, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true })
|
||||
|
||||
return res.redirect('/preferences')
|
||||
})
|
||||
|
||||
@ -1776,6 +1783,9 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
||||
res.clearCookie('collapse_child_comments')
|
||||
res.clearCookie('show_upvoted_percentage')
|
||||
res.clearCookie('subbed_subreddits')
|
||||
res.clearCookie('domain_twitter')
|
||||
res.clearCookie('domain_youtube')
|
||||
res.clearCookie('domain_instagram')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,14 +150,11 @@ form .setting {
|
||||
margin: 10px 0;
|
||||
width: 100%;
|
||||
}
|
||||
.export-import-form {
|
||||
margin: 60px 0px 0px 0px;
|
||||
}
|
||||
.export-import-form input {
|
||||
margin: 10px 0px 10px 0px;
|
||||
}
|
||||
.export-import-form:last-child {
|
||||
margin: 25px 0px 15px 0px;
|
||||
.bottom-prefs {
|
||||
margin: 60px 0px 0px 0px;
|
||||
}
|
||||
.container .content small.notice {
|
||||
padding-top: 20px;
|
||||
|
@ -8,6 +8,9 @@ link(rel="stylesheet", type="text/css", href="/css/styles.css")
|
||||
link(rel="icon", type="image/png", sizes="32x32", href="/favicon.png")
|
||||
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
||||
-
|
||||
if(!user_preferences)
|
||||
user_preferences = {}
|
||||
|
||||
function kFormatter(num) {
|
||||
return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ html
|
||||
.line
|
||||
.line
|
||||
.selftext
|
||||
!= unescape(link.selftext_html)
|
||||
!= unescape(link.selftext_html, user_preferences)
|
||||
if (link.images && link.images.preview)
|
||||
style.
|
||||
details.preview-container img {
|
||||
|
@ -9,6 +9,25 @@ html
|
||||
.content
|
||||
h1 Preferences
|
||||
form(action="/saveprefs", method="POST")
|
||||
legend Privacy
|
||||
.setting
|
||||
label(for="domain_twitter") Replace Twitter links with Nitter (blank to disable):
|
||||
if(user_preferences.domain_twitter != '' && typeof(user_preferences.domain_twitter) != 'undefined')
|
||||
input(type="text", name="domain_twitter", id="domain_twitter", value="" + user_preferences.domain_twitter + "", placeholder="e.g. nitter.net")
|
||||
else
|
||||
input(type="text", name="domain_twitter", id="domain_twitter", placeholder="e.g. nitter.net")
|
||||
.setting
|
||||
label(for="domain_youtube") Replace YouTube links with Invidious (blank to disable):
|
||||
if(user_preferences.domain_youtube != '' && typeof(user_preferences.domain_youtube) != 'undefined')
|
||||
input(type="text", name="domain_youtube", id="domain_youtube", value="" + user_preferences.domain_youtube + "", placeholder="e.g. invidious.site")
|
||||
else
|
||||
input(type="text", name="domain_youtube", id="domain_youtube", placeholder="e.g. invidious.site")
|
||||
.setting
|
||||
label(for="domain_instagram") Replace Instagram links with Bibliogram (blank to disable):
|
||||
if(user_preferences.domain_instagram != '' && typeof(user_preferences.domain_instagram) != 'undefined')
|
||||
input(type="text", name="domain_instagram", id="domain_instagram", value="" + user_preferences.domain_instagram + "", placeholder="e.g. bibliogram.art")
|
||||
else
|
||||
input(type="text", name="domain_instagram", id="domain_instagram", placeholder="e.g. bibliogram.art")
|
||||
legend Display
|
||||
.setting
|
||||
label(for="theme") Theme:
|
||||
@ -77,7 +96,11 @@ html
|
||||
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
|
||||
small(class="notice") Preferences are stored client-side using cookies without any personal information.
|
||||
br
|
||||
input(type="submit", value="Save preferences")
|
||||
a(href="/resetprefs", class="btn") Reset preferences
|
||||
.bottom-prefs
|
||||
.setting
|
||||
details
|
||||
summary
|
||||
@ -90,9 +113,6 @@ html
|
||||
a(href="/r/" + subreddit) #{subreddit}
|
||||
else
|
||||
small no subscribed subreddits
|
||||
small(class="notice") Preferences are stored client-side using cookies without any personal information.
|
||||
input(type="submit", value="Save preferences")
|
||||
a(href="/resetprefs", class="btn") Reset preferences
|
||||
form(action="/export_prefs", method="POST", class="export-import-form")
|
||||
if preferences_key
|
||||
details(open)
|
||||
|
@ -135,7 +135,7 @@ html
|
||||
.line
|
||||
.line
|
||||
.selftext
|
||||
!= unescape(link.selftext_html)
|
||||
!= unescape(link.selftext_html, user_preferences)
|
||||
if (link.images && link.images.preview)
|
||||
style.
|
||||
details.preview-container img {
|
||||
@ -215,9 +215,9 @@ html
|
||||
.heading
|
||||
p.title #{subreddit_about.title}
|
||||
.short-description
|
||||
!= unescape(subreddit_about.public_description_html)
|
||||
!= unescape(subreddit_about.public_description_html, user_preferences)
|
||||
.description
|
||||
!= unescape(subreddit_about.description_html)
|
||||
!= unescape(subreddit_about.description_html, user_preferences)
|
||||
else
|
||||
if subreddit.includes('+')
|
||||
.content
|
||||
|
Loading…
Reference in New Issue
Block a user