From d1de40a6a91b7f1859dc804b7fd1771801bb187c Mon Sep 17 00:00:00 2001 From: vyneer Date: Sun, 3 Sep 2023 20:45:43 +0300 Subject: [PATCH] feat: add youtube shorts embed support --- assets/chat/js/hashlinkconverter.js | 5 +++++ assets/chat/js/hashlinkconverter.test.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/assets/chat/js/hashlinkconverter.js b/assets/chat/js/hashlinkconverter.js index 722332dc..6b030e57 100644 --- a/assets/chat/js/hashlinkconverter.js +++ b/assets/chat/js/hashlinkconverter.js @@ -8,6 +8,7 @@ class HashLinkConverter { constructor() { this.hasHttp = /^http[s]?:\/{0,2}/; this.youtubeLiveRegex = /^live\/([A-Za-z0-9-_]{11})$/; + this.youtubeShortsRegex = /^shorts\/([A-Za-z0-9-_]{11})$/; this.twitchClipRegex = /^[^/]+\/clip\/([A-Za-z0-9-_]*)$/; this.twitchVODRegex = /^videos\/(\d+)$/; this.rumbleEmbedRegex = /^embed\/([a-z0-9]+)\/?$/; @@ -45,6 +46,10 @@ class HashLinkConverter { if (match) { return `#youtube/${match[1]}`; } + match = pathname.match(this.youtubeShortsRegex); + if (match) { + return `#youtube/${match[1]}`; + } videoId = url.searchParams.get('v'); timestamp = url.searchParams.get('t'); if (!videoId) { diff --git a/assets/chat/js/hashlinkconverter.test.js b/assets/chat/js/hashlinkconverter.test.js index 6c702b10..68ed0486 100644 --- a/assets/chat/js/hashlinkconverter.test.js +++ b/assets/chat/js/hashlinkconverter.test.js @@ -54,6 +54,11 @@ describe('Valid embeds', () => { 'https://www.youtube.com/live/EHs-_2ddcUQ?feature=share', '#youtube/EHs-_2ddcUQ', ], + [ + 'Youtube shorts link', + 'https://youtube.com/shorts/Bg1JpTqc0iA?si=7pzY1RnY2fEe9A8_', + '#youtube/Bg1JpTqc0iA', + ], [ 'Rumble embed', 'https://rumble.com/embed/v26pcdc/?pub=4',