Redirect redd.it/xxxxxx shortlinks

This commit is contained in:
DokterKaj 2024-09-28 12:52:58 +08:00 committed by GitHub
parent 0f880e1233
commit cb2da51549
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -220,15 +220,17 @@ function rewrite(url, originUrl, frontend, randomInstance) {
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`
case "redlib": case "redlib":
case "libreddit": { 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}` if (!subdomain) return `${randomInstance}${url.pathname}${url.search}`
switch (subdomain[0]) { switch (subdomain[1]) {
case "preview": case "preview":
return `${randomInstance}/preview/pre${url.pathname}${url.search}` return `${randomInstance}/preview/pre${url.pathname}${url.search}`
case "external-preview": case "external-preview":
return `${randomInstance}/preview/external-pre${url.pathname}${url.search}` return `${randomInstance}/preview/external-pre${url.pathname}${url.search}`
case "i": case "i":
return `${randomInstance}/img${url.pathname}` return `${randomInstance}/img${url.pathname}`
default:
return `${randomInstance}/comments${url.pathname}`
} }
return randomInstance return randomInstance
} }