From b6b969a9df112e10f242b9b4dfa7314f8d4ee828 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 13 Feb 2023 11:19:50 +0000 Subject: [PATCH] feat: twitch embed --- public/index.html | 2 +- src/Const.ts | 9 ++++++++- src/Element/HyperText.tsx | 5 +++++ src/Element/TwitchEmbed.tsx | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/Element/TwitchEmbed.tsx diff --git a/public/index.html b/public/index.html index 30fd007..d2f1ab0 100644 --- a/public/index.html +++ b/public/index.html @@ -8,7 +8,7 @@ + content="default-src 'self'; child-src 'none'; worker-src 'self'; frame-src youtube.com www.youtube.com https://platform.twitter.com https://embed.tidal.com https://w.soundcloud.com https://www.mixcloud.com https://open.spotify.com https://player.twitch.tv; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* ws://*:* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' https://static.cloudflareinsights.com https://platform.twitter.com https://embed.tidal.com;" /> diff --git a/src/Const.ts b/src/Const.ts index a037de0..1fabf33 100644 --- a/src/Const.ts +++ b/src/Const.ts @@ -135,7 +135,14 @@ export const SoundCloudRegex = /soundcloud\.com\/(?!live)([a-zA-Z0-9]+)\/([a-zA- /** * Mixcloud regex */ - export const MixCloudRegex = /mixcloud\.com\/(?!live)([a-zA-Z0-9]+)\/([a-zA-Z0-9-]+)/; +/** + * Spotify embed regex + */ export const SpotifyRegex = /open\.spotify\.com\/(track|album|playlist|episode)\/([a-zA-Z0-9]+)/; + +/** + * Twitch embed regex + */ +export const TwitchRegex = /twitch.tv\/([a-z0-9_]+$)/i; diff --git a/src/Element/HyperText.tsx b/src/Element/HyperText.tsx index b6f5183..057812b 100644 --- a/src/Element/HyperText.tsx +++ b/src/Element/HyperText.tsx @@ -10,6 +10,7 @@ import { SoundCloudRegex, MixCloudRegex, SpotifyRegex, + TwitchRegex, } from "Const"; import { RootState } from "State/Store"; import SoundCloudEmbed from "Element/SoundCloudEmded"; @@ -18,6 +19,7 @@ import SpotifyEmbed from "Element/SpotifyEmbed"; import TidalEmbed from "Element/TidalEmbed"; import { ProxyImg } from "Element/ProxyImg"; import { HexKey } from "Nostr"; +import TwitchEmbed from "./TwitchEmbed"; export default function HyperText({ link, creator }: { link: string; creator: HexKey }) { const pref = useSelector((s: RootState) => s.login.preferences); @@ -43,6 +45,7 @@ export default function HyperText({ link, creator }: { link: string; creator: He const soundcloundId = SoundCloudRegex.test(a) && RegExp.$1; const mixcloudId = MixCloudRegex.test(a) && RegExp.$1; const spotifyId = SpotifyRegex.test(a); + const twitchId = TwitchRegex.test(a); const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1; if (extension) { switch (extension) { @@ -109,6 +112,8 @@ export default function HyperText({ link, creator }: { link: string; creator: He return ; } else if (spotifyId) { return ; + } else if (twitchId) { + return ; } else { return ( e.stopPropagation()} target="_blank" rel="noreferrer" className="ext"> diff --git a/src/Element/TwitchEmbed.tsx b/src/Element/TwitchEmbed.tsx new file mode 100644 index 0000000..2151db8 --- /dev/null +++ b/src/Element/TwitchEmbed.tsx @@ -0,0 +1,8 @@ +const TwitchEmbed = ({ link }: { link: string }) => { + const channel = link.split("/").slice(-1); + + const args = `?channel=${channel}&parent=${window.location.hostname}&muted=true`; + return ; +}; + +export default TwitchEmbed;