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; + } + }, }, };