Directly redirect to URLs from the search page.

Closes #861
This commit is contained in:
FireMasterK 2022-02-25 11:40:24 +00:00
parent 34b4d608c5
commit 5061a4ac0a
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD

View File

@ -81,9 +81,11 @@ export default {
}; };
}, },
mounted() { mounted() {
if (this.handleRedirect()) return;
this.updateResults(); this.updateResults();
}, },
activated() { activated() {
this.handleRedirect();
window.addEventListener("scroll", this.handleScroll); window.addEventListener("scroll", this.handleScroll);
}, },
deactivated() { deactivated() {
@ -122,6 +124,18 @@ export default {
shouldUseVideoItem(item) { shouldUseVideoItem(item) {
return item.title; 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;
}
},
}, },
}; };
</script> </script>