From cb2da515491294a7abb560f8b1399f036d3ba5a1 Mon Sep 17 00:00:00 2001 From: DokterKaj <54882101+DokterKaj@users.noreply.github.com> Date: Sat, 28 Sep 2024 12:52:58 +0800 Subject: [PATCH] Redirect redd.it/xxxxxx shortlinks --- src/assets/javascripts/services.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 80a4851..3609d6c 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -220,15 +220,17 @@ function rewrite(url, originUrl, frontend, randomInstance) { return `${randomInstance}${url.pathname}${url.search}` case "redlib": case "libreddit": { - const subdomain = url.hostname.match(/^(?:(?:external-)?preview|i)(?=\.redd\.it)/) + const subdomain = url.hostname.match(/^(?:((?:external-)?preview|i)\.)?redd\.it/) if (!subdomain) return `${randomInstance}${url.pathname}${url.search}` - switch (subdomain[0]) { + switch (subdomain[1]) { case "preview": return `${randomInstance}/preview/pre${url.pathname}${url.search}` case "external-preview": return `${randomInstance}/preview/external-pre${url.pathname}${url.search}` case "i": return `${randomInstance}/img${url.pathname}` + default: + return `${randomInstance}/comments${url.pathname}` } return randomInstance }