Merge pull request 'Add logic to parse and remove any instances of https://twitter.com by replacing with user's preference' (#378) from anshumankmr/teddit:main into main

Reviewed-on: https://codeberg.org/teddit/teddit/pulls/378
This commit is contained in:
teddit 2023-02-26 12:22:46 +00:00
commit 8c52544404
3 changed files with 39 additions and 16 deletions

View File

@ -257,25 +257,45 @@ module.exports = function(request, fs) {
return str
if(typeof(user_preferences.domain_youtube) != 'undefined')
if(user_preferences.domain_youtube)
str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube)
if(user_preferences.domain_youtube){
if (!youtubeRegex.test(str)){
youtubeRegex = /(https?:\/\/)([A-z.]+\.)?youtu(be\.com|\.be)(?=.+)/gm;
}
str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube);
}
if(typeof(user_preferences.domain_twitter) != 'undefined')
if(user_preferences.domain_twitter)
if(user_preferences.domain_twitter){
if (!twitterRegex.test(str)){
twitterRegex = /(https?:\/\/)(www\.)?twitter\.com(?=.)/gm;
}
str = str.replace(twitterRegex, protocol + user_preferences.domain_twitter)
}
if(typeof(user_preferences.domain_instagram) != 'undefined')
if(user_preferences.domain_instagram)
str = str.replace(instagramRegex, protocol + user_preferences.domain_instagram)
if(typeof(user_preferences.domain_quora) != 'undefined')
if(user_preferences.domain_quora)
if(typeof(user_preferences.domain_instagram) != 'undefined'){
if(user_preferences.domain_instagram){
if (!instagramRegex.test(str)){
instagramRegex = /(https?:\/\/)(www+\.)?instagram.com(?=.)/gm;
}
str = str.replace(instagramRegex, protocol + user_preferences.domain_instagram);
}
}
if(typeof(user_preferences.domain_quora) != 'undefined'){
if(user_preferences.domain_quora){
if (!quoraRegex.test(str)){
quoraRegex = /(https?:\/\/)([A-z.]+\.)?quora\.com(?=.)/gm;
}
str = str.replace(quoraRegex, protocol + user_preferences.domain_quora)
if(typeof(user_preferences.domain_imgur) != 'undefined')
if(user_preferences.domain_imgur)
}
}
if(typeof(user_preferences.domain_imgur) != 'undefined'){
if(user_preferences.domain_imgur){
if (!imgurRegex.test(str)){
imgurRegex = /(https?:\/{2})([im]\.)?(stack\.)?imgur\.(com|io)(?=.)/gm;
}
str = str.replace(imgurRegex, protocol + user_preferences.domain_imgur)
}
}
return str
}

View File

@ -210,7 +210,7 @@ module.exports = function() {
}
comments_html += replies_html + '</details></div>'
} else {
if(comment.children.length > 0) {
if(comment.children.length > 0) {
let parent_id = comment.parent_id.split('_')[1]
let load_comms_href = parent_id

View File

@ -20,7 +20,8 @@
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
"start": "node app.js",
"dev": "nodemon app.js"
},
"dependencies": {
"compression": "^1.7.4",
@ -34,5 +35,7 @@
"pug": "^3.0.2",
"redis": "^3.1.2"
},
"devDependencies": {}
"devDependencies": {
"nodemon": "^2.0.20"
}
}