forked from Kieran/snort
feat: twitch embed
This commit is contained in:
parent
81b92c4acb
commit
b6b969a9df
@ -8,7 +8,7 @@
|
|||||||
<meta name="description" content="Fast nostr web ui" />
|
<meta name="description" content="Fast nostr web ui" />
|
||||||
<meta
|
<meta
|
||||||
http-equiv="Content-Security-Policy"
|
http-equiv="Content-Security-Policy"
|
||||||
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; 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;" />
|
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;" />
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet" />
|
||||||
|
@ -135,7 +135,14 @@ export const SoundCloudRegex = /soundcloud\.com\/(?!live)([a-zA-Z0-9]+)\/([a-zA-
|
|||||||
/**
|
/**
|
||||||
* Mixcloud regex
|
* Mixcloud regex
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const MixCloudRegex = /mixcloud\.com\/(?!live)([a-zA-Z0-9]+)\/([a-zA-Z0-9-]+)/;
|
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]+)/;
|
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;
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
SoundCloudRegex,
|
SoundCloudRegex,
|
||||||
MixCloudRegex,
|
MixCloudRegex,
|
||||||
SpotifyRegex,
|
SpotifyRegex,
|
||||||
|
TwitchRegex,
|
||||||
} from "Const";
|
} from "Const";
|
||||||
import { RootState } from "State/Store";
|
import { RootState } from "State/Store";
|
||||||
import SoundCloudEmbed from "Element/SoundCloudEmded";
|
import SoundCloudEmbed from "Element/SoundCloudEmded";
|
||||||
@ -18,6 +19,7 @@ import SpotifyEmbed from "Element/SpotifyEmbed";
|
|||||||
import TidalEmbed from "Element/TidalEmbed";
|
import TidalEmbed from "Element/TidalEmbed";
|
||||||
import { ProxyImg } from "Element/ProxyImg";
|
import { ProxyImg } from "Element/ProxyImg";
|
||||||
import { HexKey } from "Nostr";
|
import { HexKey } from "Nostr";
|
||||||
|
import TwitchEmbed from "./TwitchEmbed";
|
||||||
|
|
||||||
export default function HyperText({ link, creator }: { link: string; creator: HexKey }) {
|
export default function HyperText({ link, creator }: { link: string; creator: HexKey }) {
|
||||||
const pref = useSelector((s: RootState) => s.login.preferences);
|
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 soundcloundId = SoundCloudRegex.test(a) && RegExp.$1;
|
||||||
const mixcloudId = MixCloudRegex.test(a) && RegExp.$1;
|
const mixcloudId = MixCloudRegex.test(a) && RegExp.$1;
|
||||||
const spotifyId = SpotifyRegex.test(a);
|
const spotifyId = SpotifyRegex.test(a);
|
||||||
|
const twitchId = TwitchRegex.test(a);
|
||||||
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
|
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
|
||||||
if (extension) {
|
if (extension) {
|
||||||
switch (extension) {
|
switch (extension) {
|
||||||
@ -109,6 +112,8 @@ export default function HyperText({ link, creator }: { link: string; creator: He
|
|||||||
return <MixCloudEmbed link={a} />;
|
return <MixCloudEmbed link={a} />;
|
||||||
} else if (spotifyId) {
|
} else if (spotifyId) {
|
||||||
return <SpotifyEmbed link={a} />;
|
return <SpotifyEmbed link={a} />;
|
||||||
|
} else if (twitchId) {
|
||||||
|
return <TwitchEmbed link={a} />;
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<a href={a} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
|
<a href={a} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
|
||||||
|
8
src/Element/TwitchEmbed.tsx
Normal file
8
src/Element/TwitchEmbed.tsx
Normal file
@ -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 <iframe src={`https://player.twitch.tv/${args}`} className="w-max" allowFullScreen={true}></iframe>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TwitchEmbed;
|
Loading…
Reference in New Issue
Block a user