2020-04-23 19:26:47 +00:00
|
|
|
function isValidURL(text) {
|
2020-04-16 17:57:34 +00:00
|
|
|
if (text.toLowerCase().startsWith('http')) {
|
|
|
|
if (text.toLowerCase().indexOf('deezer.com') >= 0 || text.toLowerCase().indexOf('open.spotify.com') >= 0)
|
2020-04-08 17:01:50 +00:00
|
|
|
return true
|
2020-04-16 17:57:34 +00:00
|
|
|
} else if (text.toLowerCase().startsWith('spotify:')) return true
|
2020-04-08 17:01:50 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-04-14 14:48:13 +00:00
|
|
|
|
2020-04-23 19:26:47 +00:00
|
|
|
function convertDuration(duration) {
|
2020-04-09 10:24:49 +00:00
|
|
|
//convert from seconds only to mm:ss format
|
2020-04-16 17:57:34 +00:00
|
|
|
let mm, ss
|
2020-04-09 10:24:49 +00:00
|
|
|
mm = Math.floor(duration / 60)
|
2020-04-16 17:57:34 +00:00
|
|
|
ss = duration - mm * 60
|
2020-04-09 10:24:49 +00:00
|
|
|
//add leading zero if ss < 0
|
|
|
|
if (ss < 10) {
|
2020-04-16 17:57:34 +00:00
|
|
|
ss = '0' + ss
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
return mm + ':' + ss
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 19:26:47 +00:00
|
|
|
function convertDurationSeparated(duration) {
|
2020-04-16 17:57:34 +00:00
|
|
|
let hh, mm, ss
|
2020-04-09 10:24:49 +00:00
|
|
|
mm = Math.floor(duration / 60)
|
|
|
|
hh = Math.floor(mm / 60)
|
2020-04-16 17:57:34 +00:00
|
|
|
ss = duration - mm * 60
|
|
|
|
mm -= hh * 60
|
2020-04-09 10:24:49 +00:00
|
|
|
return [hh, mm, ss]
|
|
|
|
}
|
|
|
|
|
2020-04-23 19:03:12 +00:00
|
|
|
// On scroll event, returns currentTarget = null
|
|
|
|
// Probably on other events too
|
2020-04-23 19:26:47 +00:00
|
|
|
function debounce(func, wait, immediate) {
|
2020-04-19 20:02:06 +00:00
|
|
|
var timeout
|
|
|
|
return function () {
|
|
|
|
var context = this
|
|
|
|
var args = arguments
|
|
|
|
var later = function () {
|
|
|
|
timeout = null
|
|
|
|
if (!immediate) func.apply(context, args)
|
|
|
|
}
|
|
|
|
var callNow = immediate && !timeout
|
|
|
|
clearTimeout(timeout)
|
|
|
|
timeout = setTimeout(later, wait)
|
|
|
|
if (callNow) func.apply(context, args)
|
|
|
|
}
|
2020-04-09 10:24:49 +00:00
|
|
|
}
|
2020-04-23 19:26:47 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
isValidURL,
|
|
|
|
convertDuration,
|
|
|
|
convertDurationSeparated,
|
|
|
|
debounce
|
|
|
|
}
|