mirror of https://github.com/VueTubeApp/VueTube
fix: link handling in search
This commit is contained in:
parent
9cf045dc45
commit
3a78833baa
|
@ -38,7 +38,7 @@
|
||||||
text
|
text
|
||||||
tile
|
tile
|
||||||
dense
|
dense
|
||||||
class="searchButton text-left text-capitalize"
|
class="searchButton text-left"
|
||||||
@click="youtubeSearch(item)"
|
@click="youtubeSearch(item)"
|
||||||
>
|
>
|
||||||
<v-icon class="mr-5">mdi-magnify</v-icon>
|
<v-icon class="mr-5">mdi-magnify</v-icon>
|
||||||
|
@ -108,21 +108,10 @@ export default {
|
||||||
|
|
||||||
// --- External URL Handling --- //
|
// --- External URL Handling --- //
|
||||||
CapacitorApp.addListener("appUrlOpen", (event) => {
|
CapacitorApp.addListener("appUrlOpen", (event) => {
|
||||||
const slug = new URL(event.url);
|
|
||||||
this.$logger("ExternalURL", event.url);
|
this.$logger("ExternalURL", event.url);
|
||||||
// We only push to the route if there is a url present
|
// We only push to the route if there is a url present
|
||||||
if (slug) {
|
linkParser(event.url);
|
||||||
const host = slug.hostname.toLowerCase().replace(/^www\./, "");
|
if (result) this.$router.push(result.pathname + result.search);
|
||||||
let result;
|
|
||||||
if (host == "youtube.com") {
|
|
||||||
result = slug;
|
|
||||||
} else if (host == "youtu.be") {
|
|
||||||
result = new URL("/watch", window.location.origin);
|
|
||||||
result.searchParams.set("v", slug.pathname.split("/")[1]);
|
|
||||||
}
|
|
||||||
if (result instanceof URL)
|
|
||||||
this.$router.push(result.pathname + result.search);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Import Twemoji ---///
|
// --- Import Twemoji ---///
|
||||||
|
@ -144,8 +133,8 @@ export default {
|
||||||
if (isLink) {
|
if (isLink) {
|
||||||
this.response = [
|
this.response = [
|
||||||
{
|
{
|
||||||
text: `Watch video from ID: ${isLink}`,
|
text: `Watch Video from ID: ${isLink.searchParams.get("v")}`,
|
||||||
id: isLink,
|
id: isLink.searchParams.get("v"),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
return;
|
return;
|
||||||
|
@ -230,6 +219,7 @@ div {
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.searchButton {
|
.searchButton {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
text-transform: none !important;
|
||||||
justify-content: left !important;
|
justify-content: left !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -42,10 +42,21 @@ function getMutationByKey(key, mutations) {
|
||||||
return mutations.find((mutation) => mutation.entityKey === key).payload;
|
return mutations.find((mutation) => mutation.entityKey === key).payload;
|
||||||
}
|
}
|
||||||
function linkParser(url) {
|
function linkParser(url) {
|
||||||
console.log("linkParpar", url)
|
let result;
|
||||||
const regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
|
if (url) {
|
||||||
const match = url.match(regExp);
|
try {
|
||||||
return (match && match[7].length == 11) ? match[7] : false;
|
const slug = new URL(url);
|
||||||
|
const host = slug.hostname.toLowerCase().replace(/^www\./, "");
|
||||||
|
if (host == "youtube.com") {
|
||||||
|
result = slug;
|
||||||
|
} else if (host == "youtu.be") {
|
||||||
|
result = new URL("/watch", window.location.origin);
|
||||||
|
result.searchParams.set("v", slug.pathname.split("/")[1]);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return result instanceof URL ? result : false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue