implement imgur replacement (#341)

This commit is contained in:
Jean-Luc Tibaux 2022-11-12 13:47:08 +00:00
parent e2237f1b93
commit 45dc798eef
4 changed files with 32 additions and 0 deletions

View File

@ -195,6 +195,13 @@ module.exports = function(request, fs) {
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 = /^https?:\/{2}([im]\.)?(stack\.)?imgur\.(com|io)/gm;
let protocol = config.https_enabled || config.api_force_https ? 'https://' : 'http://'
/**
@ -265,6 +272,10 @@ module.exports = function(request, fs) {
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
}

View File

@ -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;

View File

@ -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, {

View File

@ -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: