diff --git a/public/index.html b/public/index.html index 30fd0073..d2f1ab0f 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 a037de0d..1fabf33d 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 b6f51835..057812b1 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 00000000..2151db82 --- /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;