Skip to content

Commit

Permalink
replace twitter links with nitter
Browse files Browse the repository at this point in the history
  • Loading branch information
slugalisk committed Dec 2, 2023
1 parent b58cccf commit 7cf5d36
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion assets/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion assets/chat/js/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})';
Expand Down Expand Up @@ -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 `<a target="_blank" class="embed-internallink ${extraclass}" href="${embedHref}">${embedHref}</a><a target="_blank" class="embed-externallink" href="${href}" rel="nofollow" title="${url}"></a>`;
}
}
if(self.refLinkRegex.test(decodedUrl)){
if( decodedUrl.includes("?ref")){
decodedUrl = decodedUrl.split('?ref')[0];
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand Down

0 comments on commit 7cf5d36

Please sign in to comment.