From 7cf5d36e0f07a42c6bc62ecdd9f90f5914255895 Mon Sep 17 00:00:00 2001 From: Slugalisk Date: Sat, 2 Dec 2023 13:41:23 -0800 Subject: [PATCH] replace twitter links with nitter --- .env.example | 1 + assets/.eslintrc.js | 3 ++- assets/chat/js/formatters.js | 12 +++++++++++- webpack.config.js | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index bd10721b..15ffcbf6 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ API_URI= LOGIN_URI= RUSTLA_URL=https://strims.gg +NITTER_URL=https://nitter.strims.gg WEBSOCKET_URI=wss://chat.strims.gg/ws WEBPACK_DEVSERVER_HOST= WEBPACK_DEVSERVER_HTTPS=true diff --git a/assets/.eslintrc.js b/assets/.eslintrc.js index 6e96a5bb..56ff03c3 100644 --- a/assets/.eslintrc.js +++ b/assets/.eslintrc.js @@ -5,7 +5,8 @@ module.exports = { API_URI: false, LOGIN_URI: false, WEBSOCKET_URI: false, - RUSTLA_URL: false + RUSTLA_URL: false, + NITTER_URL: false }, env: { browser: true, diff --git a/assets/chat/js/formatters.js b/assets/chat/js/formatters.js index 92df386f..93ec9d0b 100644 --- a/assets/chat/js/formatters.js +++ b/assets/chat/js/formatters.js @@ -619,7 +619,8 @@ class UrlFormatter { relaxed = strict + "|" + webURL; this.linkregex = new RegExp(relaxed, "gi"); this.discordmp4Regex = /https:\/\/(media|cdn)\.discordapp\.(net|com)\/attachments.*?\.(mp4|webm|mov)/i; - this.refLinkRegex = /^(https?:\/\/)?(www\.)?(((smile\.)?amazon)|twitter|(open\.)?spotify)\.[a-z]{2,3}/ + this.refLinkRegex = /^(https?:\/\/)?(www\.)?(((smile\.)?amazon)|twitter|(open\.)?spotify)\.[a-z]{2,3}/; + this.twitterRegex = /^(?:https:\/\/)?(?:www\.)?twitter\.com\/([^ ?]+)/i; // e.g. youtube ids include "-" and "_". const embedCommonId = '([\\w-]{1,30})'; @@ -709,6 +710,15 @@ class UrlFormatter { if (self.discordmp4Regex.test(decodedUrl)) { decodedUrl = location.origin + "/discordmedia.html?v=" + encodeURIComponent(decodedUrl); } + const tm = decodedUrl.match(self.twitterRegex); + if (tm) { + url = self.encodeUrl(tm[0]); + const href = scheme + url; + if (tm) { + const embedHref = `${NITTER_URL}/${tm[1]}`; + return `${embedHref}`; + } + } if(self.refLinkRegex.test(decodedUrl)){ if( decodedUrl.includes("?ref")){ decodedUrl = decodedUrl.split('?ref')[0]; diff --git a/webpack.config.js b/webpack.config.js index b5d1b912..31210f83 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -205,7 +205,8 @@ const plugins = [ WEBSOCKET_URI: process.env.WEBSOCKET_URI ? `'${process.env.WEBSOCKET_URI}'` : '"wss://chat.strims.gg/ws"', API_URI: process.env.API_URI ? `'${process.env.API_URI}'` : '""', LOGIN_URI: process.env.LOGIN_URI ? `'${process.env.LOGIN_URI}'` : 'false', - RUSTLA_URL: process.env.RUSTLA_URL ? `'${process.env.RUSTLA_URL}'` : '"https://strims.gg"' + RUSTLA_URL: process.env.RUSTLA_URL ? `'${process.env.RUSTLA_URL}'` : '"https://strims.gg"', + NITTER_URL: process.env.NITTER_URL ? `'${process.env.NITTER_URL}'` : '"https://nitter.net"' }), emoteManifestPlugin ];