Merge pull request 'add imgur replacement feature (#341)' (#365) from eUgEntOptIc44/teddit:eugentoptic44-add-rimgo into main
Reviewed-on: https://codeberg.org/teddit/teddit/pulls/365
This commit is contained in:
commit
22b63a3415
|
@ -194,6 +194,13 @@ module.exports = function(request, fs) {
|
|||
let twitterRegex = /(?<=href=")(https?:\/\/)(www\.)?twitter\.com(?=.+")/gm;
|
||||
let instagramRegex = /(?<=href=")(https?:\/\/)(www+\.)?instagram.com(?=.+")/gm;
|
||||
let quoraRegex = /(?<=href=")(https?:\/\/)([A-z.]+\.)?quora\.com(?=.+")/gm;
|
||||
|
||||
/*
|
||||
* regex pattern to replace imgur links (imgur.com, imgur.io, i.stack.imgur.com)
|
||||
* source: https://github.com/libredirect/libredirect/blob/32c4a0211e3b721d46219c05cba93f1a42cf3773/src/config/config.json#L317
|
||||
* license: GNU GPL v3 License -> https://github.com/libredirect/libredirect/blob/32c4a0211e3b721d46219c05cba93f1a42cf3773/LICENSE
|
||||
*/
|
||||
let imgurRegex = /(?<=href=")(https?:\/{2})([im]\.)?(stack\.)?imgur\.(com|io)(?=.+")/gm;
|
||||
|
||||
let protocol = config.https_enabled || config.api_force_https ? 'https://' : 'http://'
|
||||
|
||||
|
@ -264,6 +271,10 @@ module.exports = function(request, fs) {
|
|||
if(typeof(user_preferences.domain_quora) != 'undefined')
|
||||
if(user_preferences.domain_quora)
|
||||
str = str.replace(quoraRegex, protocol + user_preferences.domain_quora)
|
||||
|
||||
if(typeof(user_preferences.domain_imgur) != 'undefined')
|
||||
if(user_preferences.domain_imgur)
|
||||
str = str.replace(imgurRegex, protocol + user_preferences.domain_imgur)
|
||||
|
||||
return str
|
||||
}
|
||||
|
|
|
@ -110,6 +110,15 @@ overridingRoutes.all('*', (req, res, next) => {
|
|||
});
|
||||
}
|
||||
|
||||
let domainImgur = req.query.domain_imgur;
|
||||
if (domainImgur) {
|
||||
req.cookies.domain_imgur = domainImgur;
|
||||
res.cookie('domain_imgur', domainImgur, {
|
||||
maxAge: 31536000,
|
||||
httpOnly: true,
|
||||
});
|
||||
}
|
||||
|
||||
let videosMuted = req.query.videos_muted;
|
||||
if (videosMuted) {
|
||||
req.cookies.videos_muted = videosMuted;
|
||||
|
|
|
@ -16,6 +16,7 @@ function resetPreferences(res) {
|
|||
res.clearCookie('domain_youtube');
|
||||
res.clearCookie('domain_instagram');
|
||||
res.clearCookie('domain_quora');
|
||||
res.clearCookie('domain_imgur');
|
||||
res.clearCookie('videos_muted');
|
||||
res.clearCookie('prefer_frontpage');
|
||||
res.clearCookie('show_large_gallery_images');
|
||||
|
@ -94,6 +95,7 @@ preferenceRoutes.post('/saveprefs', (req, res, next) => {
|
|||
let domain_youtube = req.body.domain_youtube;
|
||||
let domain_instagram = req.body.domain_instagram;
|
||||
let domain_quora = req.body.domain_quora;
|
||||
let domain_imgur = req.body.domain_imgur;
|
||||
let videos_muted = req.body.videos_muted;
|
||||
let prefer_frontpage = req.body.prefer_frontpage;
|
||||
let show_large_gallery_images = req.body.show_large_gallery_images;
|
||||
|
@ -178,6 +180,10 @@ preferenceRoutes.post('/saveprefs', (req, res, next) => {
|
|||
maxAge: 365 * 24 * 60 * 60 * 1000,
|
||||
httpOnly: true,
|
||||
});
|
||||
res.cookie('domain_imgur', domain_imgur, {
|
||||
maxAge: 365 * 24 * 60 * 60 * 1000,
|
||||
httpOnly: true,
|
||||
});
|
||||
|
||||
if (prefer_frontpage === 'on') prefer_frontpage = 'true';
|
||||
res.cookie('prefer_frontpage', prefer_frontpage, {
|
||||
|
|
|
@ -37,6 +37,12 @@ html
|
|||
input(type="text", name="domain_quora", id="domain_quora", value="" + user_preferences.domain_quora + "", placeholder="e.g. quetre.iket.me")
|
||||
else
|
||||
input(type="text", name="domain_quora", id="domain_quora", placeholder="e.g. quetre.iket.me")
|
||||
.setting
|
||||
label(for="domain_imgur") Replace Imgur links with Rimgo (blank to disable):
|
||||
if(user_preferences.domain_imgur != '' && typeof(user_preferences.domain_imgur) != 'undefined')
|
||||
input(type="text", name="domain_imgur", id="domain_imgur", value="" + user_preferences.domain_imgur + "", placeholder="e.g. rimgo.bcow.xyz")
|
||||
else
|
||||
input(type="text", name="domain_imgur", id="domain_imgur", placeholder="e.g. rimgo.bcow.xyz")
|
||||
legend Display
|
||||
.setting
|
||||
label(for="theme") Theme:
|
||||
|
|
Loading…
Reference in New Issue