2020-04-10 14:12:21 +00:00
|
|
|
// Initialization
|
|
|
|
const socket = io.connect(window.location.href)
|
2020-04-17 15:25:01 +00:00
|
|
|
var localStorage = window.localStorage
|
2020-04-13 10:06:17 +00:00
|
|
|
// toasts stuff
|
2020-04-17 15:25:01 +00:00
|
|
|
var toastsWithId = {}
|
2020-04-14 17:58:54 +00:00
|
|
|
// settings
|
2020-04-17 15:25:01 +00:00
|
|
|
var lastSettings = {}
|
|
|
|
var lastCredentials = {}
|
2020-04-11 10:51:22 +00:00
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function toast(msg, icon = null, dismiss = true, id = null) {
|
|
|
|
if (toastsWithId[id]) {
|
2020-04-14 14:48:13 +00:00
|
|
|
let toastObj = toastsWithId[id]
|
|
|
|
let toastDOM = $(`div.toastify[toast_id=${id}]`)
|
2020-04-16 17:57:34 +00:00
|
|
|
if (msg) {
|
|
|
|
toastDOM.find('.toast-message').html(msg)
|
2020-04-11 19:55:12 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
if (icon) {
|
|
|
|
if (icon == 'loading') icon = `<div class="circle-loader"></div>`
|
|
|
|
else icon = `<i class="material-icons">${icon}</i>`
|
|
|
|
toastDOM.find('.toast-icon').html(icon)
|
2020-04-11 19:55:12 +00:00
|
|
|
}
|
|
|
|
if (dismiss !== null && dismiss){
|
2020-04-12 22:14:34 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
toastObj.hideToast()
|
|
|
|
delete toastsWithId[id]
|
2020-04-16 17:57:34 +00:00
|
|
|
}, 3000)
|
2020-04-11 19:55:12 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
} else {
|
|
|
|
if (icon == null) icon = ''
|
|
|
|
else if (icon == 'loading') icon = `<div class="circle-loader"></div>`
|
|
|
|
else icon = `<i class="material-icons">${icon}</i>`
|
2020-04-14 14:48:13 +00:00
|
|
|
let toastObj = Toastify({
|
2020-04-11 19:55:12 +00:00
|
|
|
text: `<span class="toast-icon">${icon}</span><span class="toast-message">${msg}</toast>`,
|
|
|
|
duration: dismiss ? 3000 : 0,
|
|
|
|
gravity: 'bottom',
|
|
|
|
position: 'left'
|
|
|
|
}).showToast()
|
2020-04-16 17:57:34 +00:00
|
|
|
if (id) {
|
2020-04-11 19:55:12 +00:00
|
|
|
toastsWithId[id] = toastObj
|
|
|
|
$(toastObj.toastElement).attr('toast_id', id)
|
|
|
|
}
|
2020-04-11 10:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
socket.on('toast', data => {
|
2020-04-11 10:51:22 +00:00
|
|
|
toast(data.msg, data.icon || null, data.dismiss !== undefined ? data.dismiss : true, data.id || null)
|
|
|
|
})
|
|
|
|
|
2020-04-14 17:58:54 +00:00
|
|
|
// Debug messages for socketio
|
2020-04-16 17:57:34 +00:00
|
|
|
socket.on('message', function (msg) {
|
2020-04-14 17:58:54 +00:00
|
|
|
console.log(msg)
|
|
|
|
})
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
$(function () {
|
|
|
|
if (localStorage.getItem('arl')) {
|
|
|
|
socket.emit('login', localStorage.getItem('arl'))
|
|
|
|
$('#login_input_arl').val(localStorage.getItem('arl'))
|
2020-04-13 10:06:17 +00:00
|
|
|
}
|
|
|
|
// Check if download tab should be open
|
2020-04-16 17:57:34 +00:00
|
|
|
if (eval(localStorage.getItem('downloadTabOpen'))) $('#show_download_tab').click()
|
|
|
|
else $('#hide_download_tab').click()
|
2020-04-13 10:06:17 +00:00
|
|
|
|
|
|
|
// Open default tab
|
2020-04-16 17:57:34 +00:00
|
|
|
document.getElementById('main_home_tablink').click()
|
2020-04-13 10:06:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Show/Hide Download Tab
|
2020-04-16 17:57:34 +00:00
|
|
|
document.querySelector('#show_download_tab').onclick = ev => {
|
|
|
|
ev.preventDefault()
|
|
|
|
document.querySelector('#download_tab_bar').style.display = 'none'
|
|
|
|
document.querySelector('#download_tab').style.display = 'block'
|
|
|
|
localStorage.setItem('downloadTabOpen', true)
|
2020-04-13 10:06:17 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
document.querySelector('#hide_download_tab').onclick = ev => {
|
|
|
|
ev.preventDefault()
|
|
|
|
document.querySelector('#download_tab_bar').style.display = 'block'
|
|
|
|
document.querySelector('#download_tab').style.display = 'none'
|
|
|
|
localStorage.setItem('downloadTabOpen', false)
|
2020-04-13 10:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Login stuff
|
2020-04-11 19:55:12 +00:00
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function loginButton() {
|
|
|
|
let arl = document.querySelector('#login_input_arl').value
|
|
|
|
if (arl != '' && arl != localStorage.getItem('arl')) {
|
|
|
|
socket.emit('login', arl, true)
|
2020-04-12 22:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function copyARLtoClipboard() {
|
|
|
|
$('#login_input_arl').attr('type', 'text')
|
|
|
|
let copyText = document.querySelector('#login_input_arl')
|
|
|
|
copyText.select()
|
|
|
|
copyText.setSelectionRange(0, 99999)
|
|
|
|
document.execCommand('copy')
|
|
|
|
$('#login_input_arl').attr('type', 'password')
|
|
|
|
toast('ARL copied to clipboard', 'assignment')
|
2020-04-11 19:55:12 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
function logout() {
|
|
|
|
socket.emit('logout')
|
2020-04-12 22:14:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
socket.on('logging_in', function () {
|
|
|
|
toast('Logging in', 'loading', false, 'login-toast')
|
2020-04-11 19:55:12 +00:00
|
|
|
})
|
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
socket.on('logged_in', function (data) {
|
2020-04-12 22:14:34 +00:00
|
|
|
console.log(data)
|
|
|
|
switch (data.status) {
|
|
|
|
case 1:
|
|
|
|
case 3:
|
2020-04-16 17:57:34 +00:00
|
|
|
toast('Logged in', 'done', true, 'login-toast')
|
|
|
|
if (data.arl) {
|
|
|
|
localStorage.setItem('arl', data.arl)
|
|
|
|
$('#login_input_arl').val(data.arl)
|
2020-04-12 22:14:34 +00:00
|
|
|
}
|
|
|
|
$('#open_login_prompt').hide()
|
2020-04-16 17:57:34 +00:00
|
|
|
if (data.user) {
|
|
|
|
$('#settings_username').text(data.user.name)
|
|
|
|
$('#settings_picture').attr(
|
|
|
|
'src',
|
|
|
|
`https://e-cdns-images.dzcdn.net/images/user/${data.user.picture}/125x125-000000-80-0-0.jpg`
|
|
|
|
)
|
|
|
|
$('#logged_in_info').show()
|
2020-04-12 22:14:34 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
break
|
2020-04-12 22:14:34 +00:00
|
|
|
case 2:
|
2020-04-16 17:57:34 +00:00
|
|
|
toast('Already logged in', 'done', true, 'login-toast')
|
|
|
|
if (data.user) {
|
|
|
|
$('#settings_username').text(data.user.name)
|
|
|
|
$('#settings_picture').attr(
|
|
|
|
'src',
|
|
|
|
`https://e-cdns-images.dzcdn.net/images/user/${data.user.picture}/125x125-000000-80-0-0.jpg`
|
|
|
|
)
|
|
|
|
$('#logged_in_info').show()
|
2020-04-12 22:14:34 +00:00
|
|
|
}
|
2020-04-16 17:57:34 +00:00
|
|
|
break
|
2020-04-12 22:14:34 +00:00
|
|
|
case 0:
|
2020-04-16 17:57:34 +00:00
|
|
|
toast("Couldn't log in", 'close', true, 'login-toast')
|
|
|
|
localStorage.removeItem('arl')
|
|
|
|
$('#login_input_arl').val('')
|
2020-04-12 22:14:34 +00:00
|
|
|
$('#open_login_prompt').show()
|
2020-04-16 17:57:34 +00:00
|
|
|
$('#logged_in_info').hide()
|
|
|
|
$('#settings_username').text('Not Logged')
|
|
|
|
$('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
|
|
|
break
|
2020-04-11 10:51:22 +00:00
|
|
|
}
|
|
|
|
})
|
2020-04-12 22:14:34 +00:00
|
|
|
|
2020-04-16 17:57:34 +00:00
|
|
|
socket.on('logged_out', function () {
|
|
|
|
toast('Logged out', 'done', true, 'login-toast')
|
|
|
|
localStorage.removeItem('arl')
|
|
|
|
$('#login_input_arl').val('')
|
2020-04-12 22:14:34 +00:00
|
|
|
$('#open_login_prompt').show()
|
2020-04-16 17:57:34 +00:00
|
|
|
$('#logged_in_info').hide()
|
|
|
|
$('#settings_username').text('Not Logged')
|
|
|
|
$('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
2020-04-12 22:14:34 +00:00
|
|
|
})
|
2020-04-13 18:05:26 +00:00
|
|
|
|
2020-04-14 17:58:54 +00:00
|
|
|
// settings stuff
|
2020-04-13 18:05:26 +00:00
|
|
|
var settingsTab = new Vue({
|
|
|
|
el: '#settings_tab',
|
|
|
|
data: {
|
2020-04-16 11:38:59 +00:00
|
|
|
settings: {tags: {}},
|
2020-04-16 08:37:02 +00:00
|
|
|
spotifyFeatures: {}
|
2020-04-13 18:05:26 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-16 08:37:02 +00:00
|
|
|
socket.on("init_settings", function(settings, credentials){
|
|
|
|
console.log(settings,credentials)
|
|
|
|
loadSettings(settings, credentials)
|
2020-04-14 17:58:54 +00:00
|
|
|
toast("Settings loaded!", 'settings')
|
2020-04-13 18:05:26 +00:00
|
|
|
})
|
2020-04-14 17:58:54 +00:00
|
|
|
|
2020-04-16 08:37:02 +00:00
|
|
|
socket.on("updateSettings", function(settings, credentials){
|
|
|
|
loadSettings(settings, credentials)
|
2020-04-14 17:58:54 +00:00
|
|
|
toast("Settings updated!", 'settings')
|
|
|
|
})
|
|
|
|
|
2020-04-16 08:37:02 +00:00
|
|
|
function loadSettings(settings, spotifyCredentials){
|
2020-04-14 17:58:54 +00:00
|
|
|
lastSettings = {...settings}
|
2020-04-16 08:37:02 +00:00
|
|
|
lastCredentials = {...spotifyCredentials}
|
2020-04-14 17:58:54 +00:00
|
|
|
settingsTab.settings = settings
|
2020-04-16 08:37:02 +00:00
|
|
|
settingsTab.spotifyFeatures = spotifyCredentials
|
2020-04-14 17:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveSettings(){
|
|
|
|
lastSettings = {...settingsTab.settings}
|
2020-04-16 08:37:02 +00:00
|
|
|
lastCredentials = {...settingsTab.spotifyFeatures}
|
|
|
|
socket.emit("saveSettings", lastSettings, lastCredentials)
|
2020-04-14 17:58:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 11:38:59 +00:00
|
|
|
// quality modal stuff
|
|
|
|
var modalQuality = document.getElementById('modal_quality');
|
|
|
|
modalQuality.open = false
|
|
|
|
|
2020-04-16 13:52:07 +00:00
|
|
|
window.onclick = function(event) {
|
|
|
|
if (event.target == modalQuality && modalQuality.open) {
|
|
|
|
$(modalQuality).addClass('animated fadeOut')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(modalQuality).on('webkitAnimationEnd', function () {
|
|
|
|
if (modalQuality.open){
|
|
|
|
$(this).removeClass('animated fadeOut')
|
|
|
|
$(this).css('display', 'none')
|
|
|
|
modalQuality.open = false
|
|
|
|
}else{
|
|
|
|
$(this).removeClass('animated fadeIn')
|
|
|
|
$(this).css('display', 'block')
|
|
|
|
modalQuality.open = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-16 11:38:59 +00:00
|
|
|
function openQualityModal(link){
|
|
|
|
$(modalQuality).data("url", link)
|
|
|
|
$(modalQuality).css('display', 'block')
|
|
|
|
$(modalQuality).addClass('animated fadeIn')
|
|
|
|
}
|
|
|
|
|
|
|
|
function modalQualityButton(bitrate){
|
|
|
|
var url=$(modalQuality).data("url")
|
|
|
|
if (url.indexOf(";") != -1){
|
|
|
|
urls = url.split(";")
|
|
|
|
urls.forEach(url=>{
|
|
|
|
sendAddToQueue(url, bitrate)
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
sendAddToQueue(url, bitrate)
|
|
|
|
}
|
|
|
|
$(modalQuality).addClass('animated fadeOut')
|
|
|
|
}
|