forked from andyburke/autonomous.contact
refactor: clean up chat and split up embed handling
This commit is contained in:
parent
03751c6d00
commit
7e4ab72fe6
14 changed files with 352 additions and 274 deletions
33
public/js/embeds/spotify.js
Normal file
33
public/js/embeds/spotify.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const SPOTIFY_EXTRACTOR =
|
||||
/^\/(?<item_type>(?:album|artist|episode|playlist|tracks?))\/?(?<item_id>[a-zA-Z0-9]{22})/gi;
|
||||
|
||||
function embed_spotify(link_info) {
|
||||
const is_spotify_link = ["spotify.com"].includes(link_info.domain?.toLowerCase());
|
||||
|
||||
if (!is_spotify_link) {
|
||||
return;
|
||||
}
|
||||
|
||||
SPOTIFY_EXTRACTOR.lastIndex = 0;
|
||||
|
||||
const {
|
||||
groups: { item_type, item_id },
|
||||
} = SPOTIFY_EXTRACTOR.exec(link_info.path ?? "") ?? { groups: {} };
|
||||
|
||||
if (!item_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="embed-container iframe ${!item_type || item_type.toLowerCase().indexOf("track") === 0 ? "short" : "square"} spotify rounded">
|
||||
<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://open.spotify.com/embed/${item_type ?? "track"}/${item_id}"
|
||||
allowfullscreen
|
||||
allow="clipboard-write; encrypted-media; fullscreen; picture-in-picture"
|
||||
loading="lazy"></iframe>
|
||||
</div>`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue