forked from Kieran/snort
bug: always inject script
This commit is contained in:
parent
727bb07f18
commit
3db6d0c024
@ -2,11 +2,6 @@ import { useEffect, useMemo } from "react";
|
|||||||
import { TidalRegex } from "../Const";
|
import { TidalRegex } from "../Const";
|
||||||
|
|
||||||
const TidalEmbed = ({ link }: { link: string }) => {
|
const TidalEmbed = ({ link }: { link: string }) => {
|
||||||
// https://tidal.com/browse/mix/0029457ec7eed3b340ee2b907fc4d8
|
|
||||||
// https://tidal.com/browse/track/168295350
|
|
||||||
// https://tidal.com/browse/album/168295347
|
|
||||||
// https://tidal.com/browse/playlist/4261748a-4287-4758-aaab-6d5be3e99e52
|
|
||||||
|
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
const match = link.match(TidalRegex);
|
const match = link.match(TidalRegex);
|
||||||
if (match?.length != 3) {
|
if (match?.length != 3) {
|
||||||
@ -19,21 +14,14 @@ const TidalEmbed = ({ link }: { link: string }) => {
|
|||||||
|
|
||||||
const ScriptSrc = "https://embed.tidal.com/tidal-embed.js";
|
const ScriptSrc = "https://embed.tidal.com/tidal-embed.js";
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let head = document.head.querySelector(`script[src="${ScriptSrc}"]`);
|
|
||||||
console.debug(head);
|
|
||||||
if (!head) {
|
|
||||||
let sTag = document.createElement("script");
|
let sTag = document.createElement("script");
|
||||||
sTag.src = ScriptSrc;
|
sTag.src = ScriptSrc;
|
||||||
sTag.async = true;
|
sTag.async = true;
|
||||||
document.head.appendChild(sTag);
|
document.head.appendChild(sTag);
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
if (!data) return null;
|
||||||
<>
|
return <div className="tidal-embed" data-type={data.type} data-id={data.id}></div>;
|
||||||
<div className="tidal-embed" data-type={data?.type} data-id={data?.id}></div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TidalEmbed;
|
export default TidalEmbed;
|
Loading…
Reference in New Issue
Block a user