From 9dfbb527688ecaa026e4276e78d62ee2e404aa0d Mon Sep 17 00:00:00 2001 From: Alejandro Gomez Date: Fri, 6 Jan 2023 18:00:33 +0100 Subject: [PATCH 1/2] feat: embed youtube videos --- public/index.html | 2 +- src/Text.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/public/index.html b/public/index.html index a8cdd9b..e34664d 100644 --- a/public/index.html +++ b/public/index.html @@ -8,7 +8,7 @@ + content="default-src 'self'; child-src 'none'; frame-src youtube.com www.youtube.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' https://static.cloudflareinsights.com;" /> diff --git a/src/Text.js b/src/Text.js index d8c9055..8107d3d 100644 --- a/src/Text.js +++ b/src/Text.js @@ -10,8 +10,10 @@ export function extractLinks(fragments) { return f.split(UrlRegex).map(a => { if (a.startsWith("http")) { try { - let url = new URL(a); - let ext = url.pathname.toLowerCase().match(FileExtensionRegex); + const url = new URL(a); + const vParam = url.searchParams.get('v') + const isYoutube = (url.host === "www.youtube.com" || url.host === "youtube.com" ) && vParam + const ext = url.pathname.toLowerCase().match(FileExtensionRegex); if (ext) { switch (ext[1]) { case "gif": @@ -30,6 +32,16 @@ export function extractLinks(fragments) { return