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
38
public/js/embeds/youtube.js
Normal file
38
public/js/embeds/youtube.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const YOUTUBE_ID_EXTRACTOR =
|
||||
/(?<video_domain>youtu(?:be\.com|\.be|be\.googleapis\.com))(?:\/(?<action>video|embed|watch|shorts|v))?.*(?:(?:\/|v=)(?<video_id>[A-Za-z0-9._%-]*))\S*/gi;
|
||||
|
||||
function embed_youtube(link_info) {
|
||||
const is_youtube_link = ["youtube.com", "youtu.be", "youtube.googleapis.com"].includes(
|
||||
link_info.domain?.toLowerCase(),
|
||||
);
|
||||
|
||||
if (!is_youtube_link) {
|
||||
return;
|
||||
}
|
||||
|
||||
YOUTUBE_ID_EXTRACTOR.lastIndex = 0;
|
||||
|
||||
const {
|
||||
groups: { video_domain, action, video_id },
|
||||
} = YOUTUBE_ID_EXTRACTOR.exec(link_info.url) ?? { groups: {} };
|
||||
|
||||
if (!video_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="embed-container iframe ${action === "shorts" ? "vertical" : "letterbox"} youtube">
|
||||
<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://www.youtube.com/embed/${video_id}"
|
||||
title="YouTube video player"
|
||||
allow="clipboard-write; encrypted-media; picture-in-picture; web-share;"
|
||||
referrerpolicy="strict-origin-when-cross-origin"
|
||||
allowfullscreen
|
||||
loading="lazy"
|
||||
></iframe>
|
||||
</div>`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue