From b6875ee886d8d53b0e62767d5147804280d6f425 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sat, 4 Jun 2022 17:54:13 +0300 Subject: [PATCH] Twitter twimg redirects #307 --- src/assets/javascripts/twitter.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/assets/javascripts/twitter.js b/src/assets/javascripts/twitter.js index 1cc57cb..8a73044 100644 --- a/src/assets/javascripts/twitter.js +++ b/src/assets/javascripts/twitter.js @@ -92,8 +92,11 @@ function redirect(url, initiator) { const randomInstance = utils.getRandomInstance(instancesList); // https://pbs.twimg.com/profile_images/648888480974508032/66_cUYfj_400x400.jpg - if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") - return `${randomInstance}/pic/${encodeURIComponent(`${url.host}${url.pathname}`)}`; + if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") { + const [, id, format, extra] = url.search.match(/(.*)\?format=(.*)&(.*)/); + const query = encodeURIComponent(`${id}.${format}?${extra}`); + return `${randomInstance}/pic${url.pathname}${query}`; + } else if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${url.search}`; else if (url.host == 't.co')