diff --git a/package.json b/package.json index 83ef30c68..b8af5cdfe 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "react-redux": "^8.0.5", "react-router-dom": "^6.5.0", "react-scripts": "5.0.1", + "react-twitter-embed": "^4.0.4", "uuid": "^9.0.0" }, "scripts": { diff --git a/public/index.html b/public/index.html index e34664d5b..57dd0e506 100644 --- a/public/index.html +++ b/public/index.html @@ -8,7 +8,7 @@ + content="default-src 'self'; child-src 'none'; frame-src youtube.com www.youtube.com https://platform.twitter.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' https://static.cloudflareinsights.com https://platform.twitter.com;" /> diff --git a/src/Const.js b/src/Const.js index 5a9292e47..7bba48f77 100644 --- a/src/Const.js +++ b/src/Const.js @@ -63,6 +63,11 @@ export const InvoiceRegex = /(lnbc\w+)/i; */ export const YoutubeUrlRegex = /(?:https?:\/\/)?(?:www|m\.)?(?:youtu\.be\/|youtube\.com\/(?:shorts\/|embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})/; +/** + * Tweet Regex + */ +export const TweetUrlRegex = /https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(?:es)?\/(\d+)/ + /** * Hashtag regex */ diff --git a/src/Text.js b/src/Text.js index 9887bac7a..883d5cbd4 100644 --- a/src/Text.js +++ b/src/Text.js @@ -1,7 +1,8 @@ import { Link } from "react-router-dom"; +import { TwitterTweetEmbed } from "react-twitter-embed"; import Invoice from "./element/Invoice"; -import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex, HashtagRegex } from "./Const"; +import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex, TweetUrlRegex, HashtagRegex } from "./Const"; import { eventLink, hexToBech32, profileLink } from "./Util"; import LazyImage from "./element/LazyImage"; import Hashtag from "./element/Hashtag"; @@ -10,6 +11,7 @@ function transformHttpLink(a) { try { const url = new URL(a); const youtubeId = YoutubeUrlRegex.test(a) && RegExp.$1; + const tweetId = TweetUrlRegex.test(a) && RegExp.$2; const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1; if (extension) { switch (extension) { @@ -31,6 +33,12 @@ function transformHttpLink(a) { default: return e.stopPropagation()}>{url.toString()} } + } else if (tweetId) { + return ( +