35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
const TIDAL_EXTRACTOR =
|
|
/^\/(?:(?<action>.*?)\/)?(?<item_type>(?:album|artist|episode|playlist|tracks?))\/(?<item_id>[0-9]+)/gi;
|
|
|
|
function embed_tidal(link_info) {
|
|
const is_tidal_link = ["tidal.com", "tidalhi.fi"].includes(link_info.domain?.toLowerCase());
|
|
|
|
if (!is_tidal_link) {
|
|
return;
|
|
}
|
|
|
|
TIDAL_EXTRACTOR.lastIndex = 0;
|
|
|
|
const {
|
|
groups: { action, item_type, item_id },
|
|
} = TIDAL_EXTRACTOR.exec(link_info.path ?? "") ?? { groups: {} };
|
|
|
|
if (!(item_type && item_id)) {
|
|
return;
|
|
}
|
|
|
|
return `
|
|
<div class="embed-container iframe ${item_type.toLowerCase().indexOf("track") === 0 ? "short" : "square"} tidal">
|
|
<div class="embed-actions-container">
|
|
<button class="icon plus" onclick="console.log(\"close\");"/>
|
|
<button class="icon pause" onclick="console.log(\"stop\");"/>
|
|
</div>
|
|
<iframe
|
|
src="https://embed.tidal.com/${item_type.at(-1) === "s" ? item_type : `${item_type}s`}/${item_id}"
|
|
allow="encrypted-media"
|
|
sandbox="allow-same-origin allow-scripts allow-forms allow-popups"
|
|
title="TIDAL Embed Player"
|
|
loading="lazy"
|
|
></iframe>
|
|
</div>`;
|
|
}
|