$('body').hide(); var CurrentMusicPlayerName = null let VideoIndexInMusicPlayer = 0; let CurrentVideoIndexInMusicPlayer = 0; function GetElementByClassName(className) { return $('.' + className) } function GetElementByIdentifier(identifier) { return $('#' + identifier) } function GetElementByTagName(tagName) { return $(tagName) } function SendClientEvent(action, data) { $.post('https://ngd-dj/'+action, JSON.stringify(data)); } // User Interraction $('#AddYoutubeVideo').click(function () { GetElementByClassName('YoutubeVideoAdder').css('display','flex'); }) $('#CancelYoutubeVideo').click(function () { GetElementByClassName('YoutubeVideoAdder').css('display','none'); }) $('#SubmitYoutubeVideo').click(function () { var url = $('.YoutubeVideo').val(); GetElementByClassName('YoutubeVideo').val(''); GetElementByClassName('YoutubeVideoAdder').css('display','none'); if (IsValidYouTubeUrl(url)) { var video_id = GetYoutubeVideoId(url); SendClientEvent('NewVideo', { name : CurrentMusicPlayerName, video_id : video_id}) UpdatePlayList({id : video_id, playing : false}); } }) $('input[type=range]').on('input', function () { SendClientEvent('ChangeVolume', { name : CurrentMusicPlayerName, volume : $(this).val() / 100}) }); $('#close').click(function () { Close(); }) // Events window.addEventListener('message', function (event) { let e = event.data; switch (e.action) { case "ShowMusicPlayer": ShowMusicPlayer(e.data); break; default: break; } }); $(function () { $(document).keyup(function (e) { let keyCode = e.keyCode || e.which; if (keyCode == 27) { Close(); } }); }); function Close() { SendClientEvent('close', {}) GetElementByClassName('video_boxes').html(''); GetElementByClassName('Title').html(''); VideoIndexInMusicPlayer = 0; CurrentVideoIndexInMusicPlayer = 0; ResetAllStyles(); GetElementByTagName('body').hide(); } // Functions function ShowMusicPlayer(data) { CurrentMusicPlayerName = data.name; GetElementByClassName('Title').html(data.musicPlayerData.title); CreatePlaylist(data); GetElementByTagName('body').show(); } function CreatePlaylist(data) { for (const video of data.musicPlayerData.playlist) { UpdatePlayList(video); } } function PlayYoutubeVideo(video_id, video_index) { SendClientEvent('PlayVideo', {name : CurrentMusicPlayerName, video_id : video_id, previous_video_index : parseInt(CurrentVideoIndexInMusicPlayer), current_video_index : parseInt(video_index)}) UpdateCover(video_id); UpdatePlayListActions(video_index); } function ReplayYoutubeVideo(video_id, video_index) { SendClientEvent('ReplayVideo', {name : CurrentMusicPlayerName, video_id : video_id, current_video_index : parseInt(video_index)}) GetElementByIdentifier('video_'+video_index+' .play').css('display','none'); GetElementByIdentifier('video_'+video_index+' .pause').css('display','block'); GetElementByIdentifier('video_'+video_index+' .replay').css('display','block'); GetElementByIdentifier('video_'+video_index+' .equalizer').css('display','block'); } function PauseYoutubeVideo(video_index) { GetElementByIdentifier('video_'+video_index+' .play').css('display','block'); GetElementByIdentifier('video_'+video_index+' .pause').css('display','none'); SendClientEvent('PauseVideo', {name : CurrentMusicPlayerName, current_video_index : parseInt(video_index)}) } function UpdateCover(video_id) { GetElementByClassName('current').css('background',`url('https://img.youtube.com//vi/${video_id}/0.jpg') center center`); GetElementByClassName('current').css('background-size',`contain`); GetElementByClassName('current').css('background-repeat',`no-repeat`); } function RemoveYoutubeVideo(video_id, video_index) { GetElementByIdentifier('video_'+video_index).css('display','none'); SendClientEvent('RemoveVideo', {name : CurrentMusicPlayerName, video_index : parseInt(video_index)}) if(video_index == CurrentVideoIndexInMusicPlayer) { ResetCover() } } function UpdatePlayListActions(video_index) { if (CurrentVideoIndexInMusicPlayer == 0 ) { CurrentVideoIndexInMusicPlayer = video_index; GetElementByIdentifier('video_'+video_index+' .play').css('display','none'); GetElementByIdentifier('video_'+video_index+' .pause').css('display','block'); GetElementByIdentifier('video_'+video_index+' .replay').css('display','block'); GetElementByIdentifier('video_'+video_index+' .equalizer').css('display','block'); } else if (CurrentVideoIndexInMusicPlayer != video_index) { GetElementByIdentifier('video_'+CurrentVideoIndexInMusicPlayer+' .play').css('display','block'); GetElementByIdentifier('video_'+CurrentVideoIndexInMusicPlayer+' .pause').css('display','none'); GetElementByIdentifier('video_'+CurrentVideoIndexInMusicPlayer+' .replay').css('display','none'); GetElementByIdentifier('video_'+CurrentVideoIndexInMusicPlayer+' .equalizer').css('display','none'); GetElementByIdentifier('video_'+video_index+' .play').css('display','none'); GetElementByIdentifier('video_'+video_index+' .pause').css('display','block'); GetElementByIdentifier('video_'+video_index+' .replay').css('display','block'); GetElementByIdentifier('video_'+video_index+' .equalizer').css('display','block'); CurrentVideoIndexInMusicPlayer = video_index; } else{ GetElementByIdentifier('video_'+video_index+' .play').css('display','none'); GetElementByIdentifier('video_'+video_index+' .pause').css('display','block'); GetElementByIdentifier('video_'+video_index+' .replay').css('display','block'); GetElementByIdentifier('video_'+video_index+' .equalizer').css('display','block'); } } function ResetAllStyles() { GetElementByClassName('current').removeAttr('style'); GetElementByClassName('play').removeAttr('style'); GetElementByClassName('pause').removeAttr('style'); GetElementByClassName('replay').removeAttr('style'); GetElementByClassName('equalizer').removeAttr('style'); } function ResetCover() { GetElementByClassName('current').removeAttr('style'); } //██╗ ██╗████████╗███╗ ███╗██╗ ██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗ //██║ ██║╚══██╔══╝████╗ ████║██║ ██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗ //███████║ ██║ ██╔████╔██║██║ ██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝ //██╔══██║ ██║ ██║╚██╔╝██║██║ ██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗ //██║ ██║ ██║ ██║ ╚═╝ ██║███████╗ ██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║ //╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝ function UpdatePlayList(video) { VideoIndexInMusicPlayer = VideoIndexInMusicPlayer + 1; var infos = GetVideoTitle(video.id); $(".video_boxes").append(`
${infos[1].substring(0, 25)}