From 07186f87876ba754aef5fa1834a30abbbd9df741 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 31 Jan 2022 04:05:43 +0000 Subject: [PATCH] Use regex to replace URLs. Close #773 --- src/components/WatchVideo.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 3c586ecb..ba362062 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -282,8 +282,11 @@ export default { if (!this.isEmbed) this.fetchSubscribedStatus(); this.video.description = this.video.description - .replaceAll("http://www.youtube.com", "") - .replaceAll("https://www.youtube.com", "") + .replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9?=&]*)/gm, "$1") + .replaceAll( + /(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9?=&]*)/gm, + "/watch?v=$1", + ) .replaceAll("\n", "
"); } });