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' searchContainer.style.display = 'none'
} }
router.push( this.$store.dispatch('getVideoIdFromUrl', query).then((result) => {
{ if (result) {
path: `/search/${query}`, this.$router.push(
query: { {
sortBy: this.searchSettings.sortBy, path: `/watch/${result}`,
time: this.searchSettings.time, }
type: this.searchSettings.type, )
duration: this.searchSettings.duration } 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 this.showFilters = false
}, },

View File

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

View File

@ -51,6 +51,20 @@ const actions = {
getRandomColorClass () { getRandomColorClass () {
const randomInt = Math.floor(Math.random() * state.colorClasses.length) const randomInt = Math.floor(Math.random() * state.colorClasses.length)
return state.colorClasses[randomInt] 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
}
} }
} }