Merge pull request #225 from jaki/support-redd.it

Redirect redd.it
This commit is contained in:
Simon Brazell 2021-06-16 22:31:16 +10:00 committed by GitHub
commit cda8e74567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -4,6 +4,7 @@ const targets = [
"new.reddit.com",
"amp.reddit.com",
"i.redd.it",
"redd.it",
];
const redirects = [
// libreddit: privacy w/ modern UI

View File

@ -482,6 +482,21 @@ function redirectReddit(url, initiator, type) {
} else {
return null;
}
} else if (url.host === "redd.it") {
if (
redditInstance.includes("teddit") &&
!url.pathname.match(/^\/+[^\/]+\/+[^\/]/)
) {
// As of 2021-04-22, redirects for teddit redd.it/foo links don't work.
// It appears that adding "/comments" as a prefix works, so manually add
// that prefix if it is missing. Even though redd.it/comments/foo links
// don't seem to work or exist, guard against affecting those kinds of
// paths.
//
// Note the difference between redd.it/comments/foo (doesn't work) and
// teddit.net/comments/foo (works).
return `${redditInstance}/comments${url.pathname}${url.search}`;
}
}
return `${redditInstance}${url.pathname}${url.search}`;
}