mirror of
https://codeberg.org/teddit/teddit.git
synced 2026-04-18 21:45:06 -04:00
replace youtube/twitter/instagram with privacy respecting ones
This commit is contained in:
+36
-13
@@ -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) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
let r = /([A-z.]+\.)?(reddit(\.com)|redd(\.it))/gm;
|
||||
let result = str.replace(r, config.domain)
|
||||
return result
|
||||
} else {
|
||||
return s.replace(re, (m) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
}
|
||||
let result = s.replace(re, (m) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
|
||||
result = replacePrivacyDomains(result, user_preferences)
|
||||
|
||||
return result
|
||||
} 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,
|
||||
|
||||
Reference in New Issue
Block a user