Add ability to paste YouTube links into the search bar to go directly to them

This commit is contained in:
Preston 2020-05-31 23:13:03 -04:00
parent 138f4b90f4
commit 2b476f4dc6
3 changed files with 34 additions and 13 deletions

View File

@ -59,17 +59,27 @@ export default Vue.extend({
searchContainer.style.display = 'none'
}
router.push(
{
path: `/search/${query}`,
query: {
sortBy: this.searchSettings.sortBy,
time: this.searchSettings.time,
type: this.searchSettings.type,
duration: this.searchSettings.duration
}
this.$store.dispatch('getVideoIdFromUrl', query).then((result) => {
if (result) {
this.$router.push(
{
path: `/watch/${result}`,
}
)
} else {
router.push(
{
path: `/search/${query}`,
query: {
sortBy: this.searchSettings.sortBy,
time: this.searchSettings.time,
type: this.searchSettings.type,
duration: this.searchSettings.duration
}
}
)
}
)
})
this.showFilters = false
},

View File

@ -220,9 +220,6 @@ export default Vue.extend({
onScroll: function (event) {
const liveChatComments = $('.liveChatComments').get(0)
const scrollTop = liveChatComments.scrollTop
const scrollHeight = liveChatComments.scrollHeight
const clientHeight = liveChatComments.clientHeight
if (event.wheelDelta >= 0 && this.stayAtBottom) {
$('.liveChatComments').data('animating', 0)
this.stayAtBottom = false

View File

@ -51,6 +51,20 @@ const actions = {
getRandomColorClass () {
const randomInt = Math.floor(Math.random() * state.colorClasses.length)
return state.colorClasses[randomInt]
},
getVideoIdFromUrl ({ state }, url) {
console.log('checking for id')
console.log(url)
const rx = /^.*(?:(?:(you|hook)tu\.?be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/
const match = url.match(rx)
if (match) {
return match[2]
} else {
return false
}
}
}