From 5061a4ac0ad8b6f2cb14a2f477d691c18927aed1 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 25 Feb 2022 11:40:24 +0000 Subject: [PATCH] Directly redirect to URLs from the search page. Closes #861 --- src/components/SearchResults.vue | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index e3da7a4f..557acad7 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -81,9 +81,11 @@ export default { }; }, mounted() { + if (this.handleRedirect()) return; this.updateResults(); }, activated() { + this.handleRedirect(); window.addEventListener("scroll", this.handleScroll); }, deactivated() { @@ -122,6 +124,18 @@ export default { shouldUseVideoItem(item) { return item.title; }, + handleRedirect() { + const query = this.$route.query.search_query; + const url = + /(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9?=&]*)/gm.exec(query)?.[1] ?? + /(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9?=&]*)/gm + .exec(query)?.[1] + .replace(/^/, "/watch?v="); + if (url) { + this.$router.push(url); + return true; + } + }, }, };