diff --git a/server/README.md b/server/README.md index 184fc386..8fb022b0 100644 --- a/server/README.md +++ b/server/README.md @@ -18,7 +18,7 @@ Clone this repository into a folder, and navigate to it. Use ```npm install``` Zoff is a shared (free) YouTube based radio service, built upon the YouTube API. -Zoff is mainly a webbased service. The website uses NodeJS with Socket.IO, MongoDB and PHP on the backend, with JavaScript, jQuery and Materialize on the frontend. +Zoff is mainly a webbased service. The website uses NodeJS with Socket.IO, MongoDB and express on the backend, with JavaScript, jQuery and Materialize on the frontend. The team consists of Kasper Rynning-Tønnesen and Nicolas Almagro Tonne, and the project has been worked on since late 2014. diff --git a/server/views/assets/dist/embed.min.js b/server/views/assets/dist/embed.min.js index 3bd42b87..704d7f98 100755 --- a/server/views/assets/dist/embed.min.js +++ b/server/views/assets/dist/embed.min.js @@ -1,2 +1,2 @@ -!function(){function e(){s.on("np",n.youtube_listener)}function t(){s.on("channel",p.channel_function)}function a(e){$("#volume").slider("value",e),d.setVolume(e)}var n={loaded:!0,before_load:"",after_load:"",player:"",stopInterval:!1,fireplace:"",youtube_listener:function(e){var t;try{t=n.player.getPlayerState()}catch(e){t=null}if(!(!S&&(null!=t||I)||S&&(null==t||I)||!S&&(null==t||I)||S&&t==-1)||S&&prev_chan_player==B)x||n.durationSetter(),duration=n.player.getDuration();else{prev_chan_player=B,I=!1,n.loaded=!1,i.log("--------youtube_listener--------"),i.log("Received: "),i.log(e),i.log("paused variable: "+m),i.log("mobile_beginning variable: "+C);try{i.log("getVideoUrl(): "+n.player.getVideoUrl().split("v=")[1])}catch(e){}if(i.log("video_id variable: "+l),i.log("---------------------------------"),e.np){if(m)n.getTitle(e.np[0].title,viewers),i.mobilecheck()||n.notifyUser(e.np[0].id,e.np[0].title),T||n.stopVideo(),l=e.np[0].id,conf=e.conf[0],time=e.time,o=time-conf.startTime,u=e.np[0].title,duration=e.np[0].duration,n.setBGimage(l);else if(!m){void 0===c?c=e.np[0].id:c!=l&&(c=l),l=e.np[0].id,conf=e.conf[0],time=e.time,o=time-conf.startTime,u=e.np[0].title,duration=e.np[0].duration,C&&i.mobilecheck()&&0===o&&!T&&(o=1);try{full_playlist[0].id!=l||C||p.song_change(full_playlist[0].added),Suggestions.fetchYoutubeSuggests(l)}catch(e){}if(n.getTitle(u,viewers),n.setBGimage(l),h&&!window.MSStream)try{(n.player.getVideoUrl().split("v=")[1]!=l||T)&&(n.loadVideoById(l),i.mobilecheck()||n.notifyUser(l,u),n.seekTo(o),m&&!T&&n.pauseVideo()),m||(C&&!T||n.playVideo(),x||n.durationSetter()),(n.player.getDuration()>o||0===n.player.getDuration()||T||n.player.getCurrentTime()!=o)&&n.seekTo(o),n.after_load=l,n.loaded||setTimeout(function(){n.loaded=!0},500)}catch(e){T&&(n.loadVideoById(l),n.seekTo(o)),x||T||n.durationSetter()}else n.getTitle(u,viewers)}}else{document.getElementById("song-title").innerHTML="Empty channel. Add some songs!",window.MSStream||T||$("#player_overlay").toggleClass("hide");try{T||n.stopVideo()}catch(e){}}}},onPlayerStateChange:function(e){i.log("-------onPlayerStateChange------"),i.log("New state\nState: "),i.log(e);try{i.log("Duration: "+n.player.getDuration(),"Current time: "+n.player.getCurrentTime()),i.log("getVideoUrl(): "+n.player.getVideoUrl().split("v=")[1])}catch(e){}switch(i.log("video_id variable: "+l),i.log("---------------------------------"),e.data){case-1:break;case 0:playing=!1,m=!1,S?n.playNext():s.emit("end",{id:l,channel:B.toLowerCase()});break;case 1:playing=!0,beginning&&i.mobilecheck()&&!T&&(n.pauseVideo(),beginning=!1,C=!1,setTimeout(function(){i.mobilecheck()&&($("#playpause").css("visibility","visible"),$("#playpause").css("pointer-events","all"),$("#channel-load").css("display","none"))},100)),_||"/"==window.location.pathname||T||i.addClass("#player_overlay","hide"),"/"!=window.location.pathname&&(1==document.getElementById("play").className.split(" ").length&&$("#play").toggleClass("hide"),2==document.getElementById("pause").className.split(" ").length&&$("#pause").toggleClass("hide")),m&&!S&&(s.emit("pos",{channel:B.toLowerCase()}),m=!1);break;case 2:T||(m=!0,"/"!=window.location.pathname&&d.play_pause_show(),C=!0);break;case 3:}},playVideo:function(){T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"playVideo"}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:u,image:"https://img.youtube.com/vi/"+l+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+l+"/mqdefault.jpg"),$("#pause").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):n.player.playVideo()},pauseVideo:function(){T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"pauseVideo"}),$("#play").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):n.player.pauseVideo()},seekTo:function(e){T?castSession.sendMessage("urn:x-cast:zoff.me",{type:"seekTo",seekTo:e}):S?n.player.seekTo(0):n.player.seekTo(e)},loadVideoById:function(e){T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:e}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:u,image:"https://img.youtube.com/vi/"+e+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+e+"/mqdefault.jpg")):n.player.loadVideoById(e,0)},stopVideo:function(){if(T)castSession.sendMessage("urn:x-cast:zoff.me",{type:"stopVideo"});else try{n.player.stopVideo()}catch(e){}},setVolume:function(e){T?castSession.setVolume(e/100):n.player.setVolume(e)},playNext:function(){var e=full_playlist[0];l=e.id,time=(new Date).getTime(),u=e.title,duration=e.duration,n.getTitle(u,viewers),n.setBGimage(l),T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:l}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:u,image:"https://img.youtube.com/vi/"+l+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+l+"/mqdefault.jpg")):n.loadVideoById(l),p.channel_function({type:"song_change",time:time})},sendNext:function(e){T&&castSession.sendMessage("urn:x-cast:zoff.me",{type:"nextVideo",title:e.title,videoId:e.videoId})},getTitle:function(e,t){var a="visibility",n=decodeURIComponent(e);if("/"!=window.location.pathname){var i=document.getElementById("song-title"),o=document.getElementById("viewers");i.innerHTML=n,o.innerHTML=a+" "+t,i.title=n,T&&($("#player_overlay").css("background","url(https://img.youtube.com/vi/"+l+"/hqdefault.jpg)"),$("#player_overlay").css("background-position","center"),$("#player_overlay").css("background-size","100%"),$("#player_overlay").css("background-color","black"),$("#player_overlay").css("background-repeat","no-repeat"))}document.title=n+" • Zoff / "+B},errorHandler:function(e){5==e.data||100==e.data||101==e.data||150==e.data?(curr_playing=n.player.getVideoUrl().replace("https://www.youtube.com/watch?v=",""),s.emit("skip",{error:e.data,id:l,pass:k,channel:B.toLowerCase})):void 0!==l&&n.loadVideoById(l)},onPlayerReady:function(e){try{beginning=!0,h=!0,window.MSStream||(i.mobilecheck()?($("#playpause").css("visibility","hidden"),$("#playpause").css("pointer-events","none")):$("#channel-load").css("display","none"),$("#player").css("opacity","1"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),n.loadVideoById(l),!L||i.mobilecheck()&&!T||n.playVideo(),x||n.durationSetter(),_?setTimeout(function(){n.player.seekTo(o),L||(n.player.pauseVideo(),d.play_pause_show())},1e3):n.seekTo(o)),n.readyLooks(),d.initYoutubeControls(n.player),d.initSlider(),n.player.setVolume(Crypt.get_volume()),$(".video-container").removeClass("no-opacity")}catch(e){}},readyLooks:function(){n.setBGimage(l)},setBGimage:function(e){if(void 0!==e&&!_){var t=new Image;t.onload=function(){var e=new ColorThief,a=e.getColor(t);"/"!=window.location.pathname&&(document.getElementById("main-container").style.backgroundColor=i.rgbToHsl(a,!0),$("meta[name=theme-color]").attr("content",i.rgbToHex(a[0],a[1],a[2])))},t.crossOrigin="Anonymous",t.src="https://zoff.me:8081/https://img.youtube.com/vi/"+e+"/mqdefault.jpg"}},set_width:function(e){if($(".video-container").width(e),!i.mobilecheck())if($(window).width()>769){var t=$(window).width()-$(".control-list").width()-$(".zbrand").outerWidth()-$(".brand-logo-navigate").outerWidth()-66;title_width=t,$(".title-container").width(title_width)}else $(".title-container").width("100%")},notifyUser:function(e,t){if(t=t.replace(/\\\'/g,"'").replace(/"/g,"'").replace(/&/g,"&"),"granted"===Notification.permission&&document.hidden){var a=new Notification("Now Playing",{body:t,icon:"https://i.ytimg.com/vi/"+e+"/mqdefault.jpg",iconUrl:"http://i.ytimg.com/vi/"+e+"/mqdefault.jpg"});a.onclick=function(e){window.focus(),this.cancel()},setTimeout(function(){a.close()},5e3)}},setup_all_listeners:function(){get_list_listener(),e(),setup_admin_listener(),setup_chat_listener(),t()},onYouTubeIframeAPIReady:function(){n.player=new YT.Player("player",{videoId:l,playerVars:{rel:"0",wmode:"transparent",controls:"0",fs:"0",iv_load_policy:"3",theme:"light",color:"white",showinfo:0},events:{onReady:n.onPlayerReady,onStateChange:n.onPlayerStateChange,onError:n.errorHandler}})},createFireplacePlayer:function(){n.fireplace=new YT.Player("fireplace_player",{videoId:"L_LUpnjgPso",playerVars:{rel:"0",wmode:"transparent",controls:"0",fs:"0",iv_load_policy:"3",theme:"light",color:"white",showinfo:0},events:{onReady:n.onFireplaceReady,onStateChange:n.onFireplaceChange}})},onFireplaceReady:function(){n.fireplace.playVideo()},onFireplaceChange:function(e){switch(e.data){case 0:n.fireplace.seekTo(0),n.fireplace.playVideo();break;case 2:n.fireplace.playVideo()}},durationSetter:function(){if(void 0!==duration)try{n.stopInterval||(x=!0),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=void 0!==n.player.getCurrentTime()?Math.floor(n.player.getCurrentTime()):o,currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=i.pad(minutes)+":"+i.pad(seconds)+" / "+i.pad(dMinutes)+":"+i.pad(dSeconds),per=100/duration*currDurr,per>=100?per=100:0===duration&&(per=0),N||$("#bar").width(per+"%")}catch(e){}n.stopInterval||setTimeout(n.durationSetter,1e3)},loadPlayer:function(){if(1==$("script[src='https://www.youtube.com/iframe_api']").length)try{n.onYouTubeIframeAPIReady()}catch(e){console.error("Seems YouTube iFrame script isn't correctly loaded. Please reload the page.")}else tag=document.createElement("script"),tag.src="https://www.youtube.com/iframe_api",firstScriptTag=document.getElementsByTagName("script")[0],firstScriptTag.parentNode.insertBefore(tag,firstScriptTag)}},i={log:function(e){"true"===localStorage.debug&&console.log(e)},rnd:function(e){return e[Math.floor(Math.random()*e.length)]},mobilecheck:function(){var e=!1;return(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4)))&&(e=!0),e},predicate:function(){for(var e,t,a,n=[],i=arguments.length,o=function(e,t){return e===t?0:e>24&255).toString(16)+(e>>16&255).toString(16)+(e>>8&255).toString(16)+(255&e).toString(16)},hexToRgb:function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null},pad:function(e){return e<10?"0"+Math.floor(e):Math.floor(e)},contains:function(e,t){for(var a=e.length;a--;)if(e[a]===t)return!0;return!1},sample:function(){Date.now()-lastSample>=2*SAMPLE_RATE&&(s.removeAllListeners(),s.disconnect(),s.connect(),n.setup_all_listeners()),lastSample=Date.now(),setTimeout(i.sample,SAMPLE_RATE)},loadjsfile:function(e){if(filesadded.indexOf("["+e+"]")==-1){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),filesadded+="["+e+"]"}},msieversion:function(){var e=window.navigator.userAgent,t=e.indexOf("MSIE ");return!!(t>0||navigator.userAgent.match(/Trident.*rv\:11\./))},getRandomInt:function(e,t){return Math.floor(Math.random()*(t-e))+e},secondsToOther:function(e){var t=e,a=Math.floor(t/60);return t-=60*a,[a,t]},rgbToHsl:function(e,t){r=e[0],g=e[1],b=e[2],r/=255,g/=255,b/=255;var a,n,i=Math.max(r,g,b),o=Math.min(r,g,b),s=(i+o)/2;if(i==o)a=n=0;else{var l=i-o;switch(n=s>.5?l/(2-i-o):l/(i+o),i){case r:a=(g-b)/l+(g.5&&t?s=.4:s<.65&&!t&&(s=.65),"hsl("+Math.floor(360*a)+", "+Math.floor(100*n)+"%, "+Math.floor(100*s)+"%)"},componentToHex:function(e){var t=e.toString(16);return 1==t.length?"0"+t:t},rgbToHex:function(e,t,a){return"#"+i.componentToHex(e)+i.componentToHex(t)+i.componentToHex(a)},upperFirst:function(e){return e.substring(0,1).toUpperCase()+e.substring(1).toLowerCase()},addClass:function(e,t){i.contains($(e).attr("class").split(" "),t)||$(e).addClass(t)},send_mail:function(e,t){""!==e&&""!==t&&($("#submit-contact-form").addClass("hide"),$("#send-loader").removeClass("hide"),$("#contact-form-from").attr("disabled","true"),$("#contact-form-message").attr("disabled","true"),$.ajax({type:"POST",data:{from:e,message:t},url:"/api/mail",success:function(e){"success"==e?($("#contact-container").empty(),$("#contact-container").html("Mail has been sent, we'll be back with you shortly.")):($("#contact-container").empty(),$("#contact-container").html("Something went wrong, sorry about that. You could instead try with your own mail-client: contact@zoff.no"))}}))}};$(document).on("submit","#contact-form",function(e){e.preventDefault();var t=$("#contact-form-message").val(),a=$("#contact-form-from").val();i.send_mail(a,t)}),Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;e=0&&e<=33?(1==document.getElementById("v-full").className.split(" ").length&&($("#v-full").toggleClass("hide"),$("#v-full-overlay").toggleClass("hide")),1==document.getElementById("v-medium").className.split(" ").length&&($("#v-medium").toggleClass("hide"),$("#v-medium-overlay").toggleClass("hide")),2==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),1==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide"))):e>=34&&e<=66?(1==document.getElementById("v-full").className.split(" ").length&&($("#v-full").toggleClass("hide"),$("#v-full-overlay").toggleClass("hide")),2==document.getElementById("v-medium").className.split(" ").length&&($("#v-medium").toggleClass("hide"),$("#v-medium-overlay").toggleClass("hide")),1==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),1==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide"))):e>=67&&e<=100&&(2==document.getElementById("v-full").className.split(" ").length&&($("#v-full").toggleClass("hide"),$("#v-full-overlay").toggleClass("hide")),1==document.getElementById("v-medium").className.split(" ").length&&($("#v-medium").toggleClass("hide"),$("#v-medium-overlay").toggleClass("hide")),1==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),1==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide")))},playPause:function(){state=n.player.getPlayerState(),button=document.getElementById("playpause"),1==state?n.pauseVideo():2==state&&n.playVideo()},volumeOptions:function(){T||(n.player.isMuted()?(n.player.unMute(),w=n.player.getVolume(),$("#volume").slider("value",n.player.getVolume())):(n.player.mute(),$("#volume").slider("value",0)))},hoverMute:function(e){w=n.player.getVolume()}},p={empty:!1,page:0,can_fit:Math.round($("#wrapper").height()/71),element_height:$("#wrapper").height()/Math.round($("#wrapper").height()/71)-25,uris:[],not_found:[],num_songs:0,channel_function:function(e){switch(e.type){case"list":S&&(!S||e.shuffled)||S&&prev_chan_list==B?S&&prev_chan_list==B&&void 0!=full_playlist&&!e.shuffled&&(p.populate_list(full_playlist,!0),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id})):(prev_chan_list=B,p.populate_list(e.playlist),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id}));break;case"added":p.added_song(e.value),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id});break;case"deleted":p.deleted_song(e.value,e.removed);break;case"vote":S||(p.voted_song(e.value,e.time),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id}));break;case"song_change":"/"!=window.location.pathname&&p.song_change(e.time,e.remove),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id})}},insertAtBeginning:function(e,t){var a=0==p.page?"":"none",n=p.generateSong(e,t,!1,!0,!1,a,!1);$("#wrapper").append(n)},insertAtIndex:function(e,t,a){var n=p.getIndexOfSong(e.id),i="none";if(!e.now_playing){n>=p.page&&n div:nth-child("+n+")").after(o);var s=$("#wrapper").children()[n];$(s).css("display",i),"block"==i&&$("#wrapper").children().length>=p.page+p.can_fit+1?$($("#wrapper").children()[p.page+p.can_fit]).css("display","none"):n=0?$($("#wrapper").children()[p.page]).css("display","block"):$("#wrapper").children().length>p.page+p.can_fit&&$($("#wrapper").children()[p.page+p.can_fit-1]).css("display","block"),a&&p.page>0&&$($("#wrapper").children()[p.page-1]).css("display","none"),t&&setTimeout(function(){$(s).css("height",p.element_height)},5)}},populate_list:function(e,t){if(i.mobilecheck()||_?_?(p.can_fit=Math.round($("#wrapper").height()/91)+1,p.element_height=$("#wrapper").height()/p.can_fit-4):(p.can_fit=Math.round(($(window).height()-$(".tabs").height()-$("header").height()-66)/71)+1,p.element_height=($(window).height()-$(".tabs").height()-$("header").height()-66)/p.can_fit-6):(p.can_fit=Math.round($("#wrapper").height()/71)+1,p.element_height=$("#wrapper").height()/p.can_fit-5.3),p.element_height<55.2&&(p.element_height=55.2),void 0===f&&(f=$("#list-song-html").html()),full_playlist=e,S&&!t)for(var a=0;a1?($.each(full_playlist,function(e,t){if(!t.now_playing){var a=p.generateSong(t,!1,v,!0,!1,"",!0);$("#wrapper").append(a)}}),$("#wrapper").children().length>p.can_fit&&!$("#pageButtons").length?($('
first_pagefirst_pagenavigate_before prevnavigate_before prev 1 next navigate_nextnext navigate_nextlast_pagelast_page
').insertAfter("#wrapper"),$(".prev_page").css("display","none"),$(".first_page").css("display","none"),$(".next_page_hide").css("display","none"),$(".last_page_hide").css("display","none")):$("#pageButtons").length||($('
first_pagefirst_pagenavigate_before prevnavigate_before prev 1 next navigate_nextnext navigate_nextlast_pagelast_page
').insertAfter("#wrapper"),$(".prev_page").css("display","none"),$(".next_page").css("display","none"),$(".last_page").css("display","none"),$(".first_page").css("display","none"),$(".next_page_hide").css("display","inline-flex"),$(".prev_page_hide").css("display","inline-flex")),p.dynamicContentPage(-10)):(p.empty=!0,$("#wrapper").html("The playlist is empty."),$("#pageButtons").length||$('
first_pagefirst_pagenavigate_before prevnavigate_before prev 1 next navigate_nextnext navigate_nextlast_pagelast_page
').insertAfter("#wrapper"),$(".prev_page").css("display","none"),$(".next_page").css("display","none"),$(".last_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".first_page").css("display","none"),$(".next_page_hide").css("display","inline-flex"),$(".prev_page_hide").css("display","inline-flex")),$("#settings").css("visibility","visible"),$("#settings").css("opacity","1"),$("#wrapper").css("opacity","1")},dynamicContentPageJumpTo:function(e){e*=p.can_fit,(e>p.page||e0&&"none"==$(".prev_page").css("display")&&($(".prev_page").css("display","inline-flex"),$(".prev_page_hide").css("display","none"),$(".first_page").css("display","inline-flex"),$(".first_page_hide").css("display","none")),p.page+p.can_fit>=$("#wrapper").children().length&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none")),$("#pageNumber").html(p.page/p.can_fit+1))},dynamicContentPage:function(e){1==e?($("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=p.page+p.can_fit,$("#wrapper").children().slice(p.page,p.page+p.can_fit).show(),p.page>0&&"none"==$(".prev_page").css("display")&&($(".prev_page").css("display","inline-flex"),$(".prev_page_hide").css("display","none"),$(".first_page").css("display","inline-flex"),$(".first_page_hide").css("display","none")),p.page+p.can_fit>=$("#wrapper").children().length&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none"))):10==e?($("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=Math.floor(($("#wrapper").children().length-1)/p.can_fit)*p.can_fit,$("#wrapper").children().slice(p.page,p.page+p.can_fit).show(),p.page>0&&"none"==$(".prev_page").css("display")&&($(".prev_page").css("display","inline-flex"),$(".prev_page_hide").css("display","none"),$(".first_page").css("display","inline-flex"),$(".first_page_hide").css("display","none")),p.page+p.can_fit>=$("#wrapper").children().length&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none"))):e==-10?($("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=0,$("#wrapper").children().slice(p.page,p.page+p.can_fit).show(),0==p.page&&"none"!=$(".prev_page").css("display")?($(".prev_page").css("display","none"),$(".prev_page_hide").css("display","inline-flex"),$(".first_page").css("display","none"),$(".first_page_hide").css("display","inline-flex")):"none"==$(".prev_page").css("display")?($(".prev_page_hide").css("display","inline-flex"),$(".first_page_hide").css("display","inline-flex")):($(".prev_page_hide").css("display","none"),$(".first_page_hide").css("display","none")),p.page+p.can_fit<$("#wrapper").children().length&&($(".next_page_hide").css("display","none"),$(".next_page").css("display","inline-flex"),$(".last_page_hide").css("display","none"),$(".last_page").css("display","inline-flex"))):($("#wrapper").children().slice(p.page-p.can_fit,p.page).show(),$("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=p.page-p.can_fit<0?0:p.page-p.can_fit,0==p.page&&"none"!=$(".prev_page").css("display")?($(".prev_page").css("display","none"),$(".prev_page_hide").css("display","inline-flex"),$(".first_page").css("display","none"),$(".first_page_hide").css("display","inline-flex")):"none"==$(".prev_page").css("display")?($(".prev_page_hide").css("display","inline-flex"),$(".first_page_hide").css("display","inline-flex")):($(".prev_page_hide").css("display","none"),$(".first_page_hide").css("display","none")),p.page+p.can_fit<$("#wrapper").children().length&&($(".next_page_hide").css("display","none"),$(".next_page").css("display","inline-flex"),$(".last_page_hide").css("display","none"),$(".last_page").css("display","inline-flex"))),$("#pageNumber").html(p.page/p.can_fit+1)},added_song:function(e){var t;if(void 0!=e){if(0!==full_playlist.length&&(t=full_playlist.pop()),full_playlist.push(e),p.sortList(),t&&full_playlist.push(t),$("#suggested-"+e.id).length>0){number_suggested-=1,number_suggested<0&&(number_suggested=0);var a=number_suggested>9?"9+":number_suggested;$(".suggested-link span.badge.new.white").hasClass("hide")||0!=a||$(".suggested-link span.badge.new.white").addClass("hide"),$(".suggested-link span.badge.new.white").text(a)}$("#suggested-"+e.id).remove(),p.empty&&(p.empty=!1),$("#empty-channel-message").remove(),p.insertAtIndex(e,!0),$($("#wrapper").children()[p.page+p.can_fit]).css("display","none"),$("#wrapper").children().length>p.page+p.can_fit?($(".next_page_hide").css("display","none"),$(".next_page").removeClass("hide"),$(".last_page_hide").css("display","none"),$(".next_page").css("display","inline-flex"),$(".last_page").css("display","inline-flex")):($(".next_page_hide").css("display","inline-flex"), -$(".next_page").css("display","none"))}},deleted_song:function(e,t){try{var a=p.getIndexOfSong(e),i=$("#wrapper").children()[a];t||(i.style.height=0),a=0?($($("#wrapper").children()[p.page]).css("height",0),$($("#wrapper").children()[p.page]).css("display","block"),$($("#wrapper").children()[p.page]).css("height",p.element_height)):$("#wrapper").children().length>p.page+p.can_fit&&($($("#wrapper").children()[p.page+p.can_fit]).css("height",0),$($("#wrapper").children()[p.page+p.can_fit]).css("display","block"),$($("#wrapper").children()[p.page+p.can_fit]).css("height",p.element_height)),p.page>=$("#wrapper").children().length-1?(p.dynamicContentPage(-1),$(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none")):p.page+p.can_fit+1>=$("#wrapper").children().length-1&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none")),setTimeout(function(){t||$("#"+e).remove(),full_playlist.splice(p.getIndexOfSong(e),1),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id})},305),t&&$("#"+e).remove()}catch(t){full_playlist.splice(p.getIndexOfSong(e),1),p.empty||($("#"+e).remove(),a=0?$($("#wrapper").children()[p.page-1]).css("display","block"):$("#wrapper").children().length>p.page+p.can_fit&&$($("#wrapper").children()[p.page+(p.can_fit-1)]).css("display","block"),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id}))}full_playlist.length<=2&&(p.empty=!0,$("#wrapper").html("The playlist is empty.")),$("#suggested-"+e).remove(),p.page+p.can_fit<$("#wrapper").children().length+1,p.page>=$("#wrapper").children().length&&p.dynamicContentPage(-1),Suggestions.checkUserEmpty()},voted_song:function(e,t){var a=p.getIndexOfSong(e),n=full_playlist[a];full_playlist[a].votes+=1,full_playlist[a].added=t,p.sortList(),$("#"+e).remove(),p.insertAtIndex(n,!1)},song_change:function(e,t){try{var a=full_playlist.length-1;$("#wrapper").children()[0].remove(),0===$("#wrapper").children().length&&(p.empty=!0,$("#wrapper").html("The playlist is empty.")),full_playlist[0].now_playing=!0,full_playlist[0].votes=0,full_playlist[0].guids=[],full_playlist[0].added=e,t?delete full_playlist[a]:full_playlist[a].now_playing=!1,i.log("---------------------------"),i.log("---SONG ON FIRST INDEX-----"),i.log(full_playlist[0]),i.log("---------------------------"),full_playlist.push(full_playlist.shift()),t||p.insertAtIndex(full_playlist[a-1],!1,!0)}catch(e){}},vote:function(e,t){return!S||"del"==t&&hasadmin&&!y&&""!=k?s.emit("vote",{channel:B,id:e,type:t,adminpass:k}):"pos"==t?p.voted_song(e,(new Date).getTime()/1e3):p.deleted_song(e),!0},skip:function(){return S?n.playNext():s.emit("skip",{pass:k,id:l,channel:B.toLowerCase()}),!0},exportToSpotify:function(){$.ajax({type:"GET",url:"https://api.spotify.com/v1/me",headers:{Authorization:"Bearer "+access_token_data.access_token},success:function(e){var t=e.id;$("#playlist_loader_export").removeClass("hide"),$(".exported-list-container").removeClass("hide"),$.ajax({type:"POST",url:"https://api.spotify.com/v1/users/"+t+"/playlists",headers:{Authorization:"Bearer "+access_token_data.access_token,"Content-Type":"application/json"},data:JSON.stringify({name:B.toLowerCase()+" - Zoff",public:!0}),success:function(e){var a=e.id;$.each(full_playlist,function(e,n){p.searchSpotify(n,a,t)})}})}})},searchSpotify:function(e,t,a){var n=e.title,o=e.title.toLowerCase().replace("-"," ");o=o.replace("official hd video",""),o=o.replace("unofficial video",""),o=o.replace("studio footage",""),o=o.replace("great song",""),o=o.replace("-"," "),o=o.replace("-"," "),o=o.replace(" hq "," "),o=o.replace("lyric video",""),o=o.replace("lyrics video",""),o=o.replace("album version",""),o=o.replace("drive original movie soundtrack",""),o=o.replace("original movie soundtrack",""),o=o.replace("live sessions",""),o=o.replace("audio only",""),o=o.replace("audio",""),o=o.replace("(new)",""),o=o.replace(" by "," "),o=o.replace(" vs "," "),o=o.replace("(full)"," "),o=o.replace("(video)"," "),o=o.replace("&"," "),o=o.replace("with lyrics",""),o=o.replace("lyrics",""),o=o.replace("w/",""),o=o.replace("w/",""),o=o.replace("official video",""),o=o.replace("studio version",""),o=o.replace("official music video",""),o=o.replace("music video",""),o=o.replace("musicvideo",""),o=o.replace("original video",""),o=o.replace("full version",""),o=o.replace("full song",""),o=o.replace("(official)",""),o=o.replace("official",""),o=o.replace("(original)",""),o=o.replace("("," "),o=o.replace(")"," "),o=o.replace("feat."," "),o=o.replace("feat"," "),o=o.replace("ft."," "),o=o.replace("["," "),o=o.replace("]"," "),o=o.replace(" free ",""),o=o.replace(" hd ",""),o=o.replace("original mix"," "),o=o.replace("radio edit"," "),o=o.replace("pop version"," "),o=o.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," "),o=encodeURIComponent(o),$.ajax({type:"GET",url:"https://api.spotify.com/v1/search?q="+o+"&type=track",headers:{Authorization:"Bearer "+access_token_data.access_token},async:!0,statusCode:{429:function(t){console.log(t.getAllResponseHeaders());var a=t.getResponseHeader("Retry-After");console.log(a),a||(a=5),a=parseInt(a,10),i.log("Retry-After",a),setTimeout(function(){p.searchSpotify(e)},1e3*a)}},error:function(t){if(429==t.status){console.log(t.getAllResponseHeaders());var a=t.getResponseHeader("Retry-After");console.log(a),a||(a=5),a=parseInt(a,10),i.log("Retry-After",a),setTimeout(function(){p.searchSpotify(e)},1e3*a)}},success:function(e){var s=!1;if($.each(e.tracks.items,function(e,t){if(t.name=t.name.toLowerCase(),t.name=t.name.replace("("," "),t.name=t.name.replace(")"," "),t.name=t.name.replace("["," "),t.name=t.name.replace("]"," "),t.name=t.name.replace("-"," "),t.name=t.name.replace("-"," "),t.name=t.name.replace("-"," "),t.name=t.name.replace("original mix"," "),t.name=t.name.replace("album version"," "),t.name=t.name.replace("abum version"," "),t.name=t.name.replace("feat."," "),t.artists[0].name=t.artists[0].name.replace("feat."," "),t.artists[0].name=t.artists[0].name.replace("feat"," "),t.name=t.name.replace("feat"," "),t.name=t.name.replace("ft."," "),t.name=t.name.replace("radio edit"," "),t.name=t.name.replace("pop version"," "),t.name=t.name.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," "),t.artists[0].name=t.artists[0].name.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ")," "==t.name.substring(t.name.length-1)&&(t.name=t.name.substring(0,t.name.length-1)),"."==t.name.substring(t.name.length-1)&&"."!=o.substring(o.length-1)&&(t.name=t.name.substring(0,t.name.length-1)),decodeURIComponent(o).indexOf(t.artists[0].name.toLowerCase())>=0&&decodeURIComponent(o).indexOf(t.name.toLowerCase())>=0)return s=!0,p.uris.push(t.uri),i.log("Found",o),!1;for(var a=t.name.split(" "),e=0;e=0||"&"==a[e]&&o.indexOf("and")>=0)&&o.indexOf(a[e])<0)return!0;return s=!0,p.uris.push(t.uri),i.log("Found",o),!1}),s||(p.not_found.push(n),p.num_songs=p.num_songs+1,i.log("Didn't find",n)),p.num_songs+p.uris.length==full_playlist.length){if(p.uris.length>100){for(;p.uris.length>100;)p.addToSpotifyPlaylist(p.uris.slice(0,100),t,a),p.uris=p.uris.slice(100,p.uris.length);p.addToSpotifyPlaylist(p.uris,t,a),$("#playlist_loader_export").addClass("hide")}else p.addToSpotifyPlaylist(p.uris,t,a),$("#playlist_loader_export").addClass("hide");$(".exported-list").append(""+B+""),$.each(p.not_found,function(e,t){var a=$("
"+not_export_html+"
");a.find(".extra-add-text").attr("value",t),a.find(".extra-add-text").attr("title",t),$(".not-exported-container").append(a.html())}),$(".not-exported").removeClass("hide"),$(".spotify_export_button").css("display","block")}}})},addToSpotifyPlaylist:function(e,t,a){$.ajax({type:"POST",url:"https://api.spotify.com/v1/users/"+a+"/playlists/"+t+"/tracks",headers:{Authorization:"Bearer "+access_token_data.access_token,"Content-Type":"application/json"},data:JSON.stringify({uris:e}),error:function(n){setTimeout(function(){p.addToSpotifyPlaylist(e,t,a)},3e3)},success:function(e){i.log("Added songs")}})},exportToYoutube:function(){var e="https://www.googleapis.com/youtube/v3/playlists?part=snippet";$(".exported-list-container").removeClass("hide"),$("#playlist_loader_export").removeClass("hide"),$.ajax({type:"POST",url:e,headers:{Authorization:"Bearer "+access_token_data_youtube.access_token,"Content-Type":"application/json"},data:JSON.stringify({snippet:{title:i.upperFirst(B.toLowerCase()),description:"Playlist exported from zoff"}}),success:function(e){var t=0,a=e.id,n="https://www.googleapis.com/youtube/v3/playlistItems?part=snippet";p.addToYoutubePlaylist(a,full_playlist,t,n)},error:function(e){i.log(e)}})},addToYoutubePlaylist:function(e,t,a,n){var o=JSON.stringify({snippet:{playlistId:e,resourceId:{kind:"youtube#video",videoId:t[a].id}}});$.ajax({type:"POST",url:n,headers:{Authorization:"Bearer "+access_token_data_youtube.access_token,"Content-Type":"application/json"},data:o,success:function(o){i.log("Added video: "+t[a].id+" to playlist id "+e),a==t.length-1?(i.log("All videoes added!"),i.log("url: https://www.youtube.com/playlist?list="+e),$(".exported-list").append(""+B+""),$("#playlist_loader_export").addClass("hide"),$(".current_number").addClass("hide")):($(".current_number").removeClass("hide"),$(".current_number").text(a+1+" of "+t.length),p.addToYoutubePlaylist(e,t,a+1,n))}})},importOldList:function(e){var t="",a=0;playlist_url="lists/"+e+".json",list=$.parseJSON($.ajax({type:"GET",url:playlist_url,async:!1}).responseText),$.each(list.songs,function(e,n){t+=n.id+",",a>45&&(Search.addVideos(t),t="",a=0),a++}),Search.addVideos(t),document.getElementById("search").value=""},sortList:function(){full_playlist.sort(i.predicate({name:"votes",reverse:!0},{name:"added",reverse:!1},{name:"title",reverse:!1}))},show:function(){i.mobilecheck()||(showToggle?(showToggle=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.me/"+B.toLowerCase())):(showToggle=!0,$("#toptitle").html("Zoff"),$("#chan").removeClass("bigChan"),$("#chan").html(B)))},generateSong:function(e,t,a,n,o,s,l){void 0===f&&(f=$("#list-song-html").html());var r,c,d=e.id,u=e.title,g=e.votes,m="background-image:url('//img.youtube.com/vi/"+d+"/mqdefault.jpg');",h=$("
"+f+"
"),v="style";if(t?h.find("#list-song").css("height",0):h.find(".list-song").css("height",p.element_height),y||h.find(".card-action").removeClass("hide"),1==g&&h.find(".vote-text").text("vote"),a&&(m="//img.youtube.com/vi/"+d+"/mqdefault.jpg",v="data-original"),n){h.find(".list-votes").text(g),h.find("#list-song").attr("id",d),h.find(".vote-container").attr("title",u),($("#wrapper").children().length>=p.can_fit&&l||"none"==s)&&h.find(".card").css("display","none"),r=".vote-container",c="delete_button";var _=i.secondsToOther(e.duration);h.find(".card-duration").text(i.pad(_[0])+":"+i.pad(_[1]))}else if(!n){h.find(".vote-text").text(""),h.find(".card-duration").text(i.pad(e.duration[0])+":"+i.pad(e.duration[1]));var w="user";r=".add-suggested",o?c="del_user_suggested":(c="del_suggested",w="system"),h.find(".vote-container").attr("class","clickable add-suggested"),h.find(".add-suggested").attr("title",u),h.find(".delete_button").addClass(c),h.find(r).attr("data-video-title",u),h.find(r).attr("data-video-length",e.length),h.find(r).attr("data-added-by",w),h.find("#list-song").attr("id","suggested-"+d),h.find(".list-image").attr("class",h.find(".list-image").attr("class").replace("list-image","list-suggested-image"))}return h.find(".list-title").text(u),h.find(".list-title").attr("title",u),h.find(r).attr("data-video-id",d),h.find(".list-image").attr(v,m),h.find(".list-suggested-image").attr(v,m),h.find("."+c).attr("data-video-id",d),h.html()},getIndexOfSong:function(e){try{return indexes=$.map(full_playlist,function(t,a){if(t.id==e)return a}),indexes[0]}catch(e){}},scrollTop:function(){$("#wrapper").scrollTop(0)},scrollBottom:function(){$("#wrapper").scrollTop($("#wrapper")[0].scrollHeight)}},u="",m=!1,h=!1,f=$("#list-song-html").html(),y=!0,v=!1,_=!0,w=100,k="",C=!1,x=!1,T=!1,S=!1,I=!1,E=window.location.hash.substring(1).split("&"),B=E[0],L=!1,M="#808080",N=!1,A={"sync disconnect on unload":!0,secure:!0,"force new connection":!0};$(document).ready(function(){3==E.length&&"autoplay"==E[2]?L=!0:m=!0,M="#"+E[1],add="https://zoff.me",s=io.connect(""+add+":8080",A),s.on("get_list",function(){setTimeout(function(){s.emit("list",B.toLowerCase())},1e3)}),s.on("viewers",function(e){viewers=e,void 0!==u&&n.getTitle(u,viewers)}),e(),t(),window.onYouTubeIframeAPIReady=n.onYouTubeIframeAPIReady,n.loadPlayer(),d.initSlider(),window.setVolume=a,$("#controls").css("background-color",M),$("#playlist").css("background-color",M)}),$(document).on("click","#zoffbutton",function(e){window.open("https://zoff.me/"+B.toLowerCase()+"/","_blank")}),$(document).on("click",".vote-container",function(e){var t=$(this).attr("data-video-id");p.vote(t,"pos")}),$(document).on("click",".prev_page",function(e){e.preventDefault(),p.dynamicContentPage(-1)}),$(document).on("click",".next_page",function(e){e.preventDefault(),p.dynamicContentPage(1)})}(); \ No newline at end of file +!function(){function e(){s.on("np",n.youtube_listener)}function t(){s.on("channel",p.channel_function)}function a(e){$("#volume").slider("value",e),d.setVolume(e)}var n={loaded:!0,before_load:"",after_load:"",player:"",stopInterval:!1,fireplace:"",youtube_listener:function(e){var t;try{t=n.player.getPlayerState()}catch(e){t=null}if(!(!S&&(null!=t||I)||S&&(null==t||I)||!S&&(null==t||I)||S&&t==-1)||S&&prev_chan_player==B)x||n.durationSetter(),duration=n.player.getDuration();else{prev_chan_player=B,I=!1,n.loaded=!1,i.log("--------youtube_listener--------"),i.log("Received: "),i.log(e),i.log("paused variable: "+m),i.log("mobile_beginning variable: "+C);try{i.log("getVideoUrl(): "+n.player.getVideoUrl().split("v=")[1])}catch(e){}if(i.log("video_id variable: "+l),i.log("---------------------------------"),e.np){if(m)n.getTitle(e.np[0].title,viewers),i.mobilecheck()||n.notifyUser(e.np[0].id,e.np[0].title),T||n.stopVideo(),l=e.np[0].id,conf=e.conf[0],time=e.time,o=time-conf.startTime,u=e.np[0].title,duration=e.np[0].duration,n.setBGimage(l);else if(!m){void 0===c?c=e.np[0].id:c!=l&&(c=l),l=e.np[0].id,conf=e.conf[0],time=e.time,o=time-conf.startTime,u=e.np[0].title,duration=e.np[0].duration,C&&i.mobilecheck()&&0===o&&!T&&(o=1);try{full_playlist[0].id!=l||C||p.song_change(full_playlist[0].added),Suggestions.fetchYoutubeSuggests(l)}catch(e){}if(n.getTitle(u,viewers),n.setBGimage(l),h&&!window.MSStream)try{(n.player.getVideoUrl().split("v=")[1]!=l||T)&&(n.loadVideoById(l),i.mobilecheck()||n.notifyUser(l,u),n.seekTo(o),m&&!T&&n.pauseVideo()),m||(C&&!T||n.playVideo(),x||n.durationSetter()),(n.player.getDuration()>o||0===n.player.getDuration()||T||n.player.getCurrentTime()!=o)&&n.seekTo(o),n.after_load=l,n.loaded||setTimeout(function(){n.loaded=!0},500)}catch(e){T&&(n.loadVideoById(l),n.seekTo(o)),x||T||n.durationSetter()}else n.getTitle(u,viewers)}}else{document.getElementById("song-title").innerHTML="Empty channel. Add some songs!",window.MSStream||T||$("#player_overlay").toggleClass("hide");try{T||n.stopVideo()}catch(e){}}}},onPlayerStateChange:function(e){i.log("-------onPlayerStateChange------"),i.log("New state\nState: "),i.log(e);try{i.log("Duration: "+n.player.getDuration(),"Current time: "+n.player.getCurrentTime()),i.log("getVideoUrl(): "+n.player.getVideoUrl().split("v=")[1])}catch(e){}switch(i.log("video_id variable: "+l),i.log("---------------------------------"),e.data){case-1:break;case 0:playing=!1,m=!1,S?n.playNext():s.emit("end",{id:l,channel:B.toLowerCase()});break;case 1:playing=!0,beginning&&i.mobilecheck()&&!T&&(n.pauseVideo(),beginning=!1,C=!1,setTimeout(function(){i.mobilecheck()&&($("#playpause").css("visibility","visible"),$("#playpause").css("pointer-events","all"),$("#channel-load").css("display","none"))},100)),_||"/"==window.location.pathname||T||i.addClass("#player_overlay","hide"),"/"!=window.location.pathname&&(1==document.getElementById("play").className.split(" ").length&&$("#play").toggleClass("hide"),2==document.getElementById("pause").className.split(" ").length&&$("#pause").toggleClass("hide")),m&&!S&&(s.emit("pos",{channel:B.toLowerCase()}),m=!1);break;case 2:T||(m=!0,"/"!=window.location.pathname&&d.play_pause_show(),C=!0);break;case 3:}},playVideo:function(){T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"playVideo"}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:u,image:"https://img.youtube.com/vi/"+l+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+l+"/mqdefault.jpg"),$("#pause").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):n.player.playVideo()},pauseVideo:function(){T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"pauseVideo"}),$("#play").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):n.player.pauseVideo()},seekTo:function(e){T?castSession.sendMessage("urn:x-cast:zoff.me",{type:"seekTo",seekTo:e}):S?n.player.seekTo(0):n.player.seekTo(e)},loadVideoById:function(e){T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:e}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:u,image:"https://img.youtube.com/vi/"+e+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+e+"/mqdefault.jpg")):n.player.loadVideoById(e,0)},stopVideo:function(){if(T)castSession.sendMessage("urn:x-cast:zoff.me",{type:"stopVideo"});else try{n.player.stopVideo()}catch(e){}},setVolume:function(e){T?castSession.setVolume(e/100):n.player.setVolume(e)},playNext:function(){var e=full_playlist[0];l=e.id,time=(new Date).getTime(),u=e.title,duration=e.duration,n.getTitle(u,viewers),n.setBGimage(l),T?(castSession.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:l}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:u,image:"https://img.youtube.com/vi/"+l+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+l+"/mqdefault.jpg")):n.loadVideoById(l),p.channel_function({type:"song_change",time:time})},sendNext:function(e){T&&castSession.sendMessage("urn:x-cast:zoff.me",{type:"nextVideo",title:e.title,videoId:e.videoId})},getTitle:function(e,t){var a="visibility",n=decodeURIComponent(e);if("/"!=window.location.pathname){var i=document.getElementById("song-title"),o=document.getElementById("viewers");i.innerHTML=n,o.innerHTML=a+" "+t,i.title=n,T&&($("#player_overlay").css("background","url(https://img.youtube.com/vi/"+l+"/hqdefault.jpg)"),$("#player_overlay").css("background-position","center"),$("#player_overlay").css("background-size","100%"),$("#player_overlay").css("background-color","black"),$("#player_overlay").css("background-repeat","no-repeat"))}document.title=n+" • Zoff / "+B},errorHandler:function(e){5==e.data||100==e.data||101==e.data||150==e.data?(curr_playing=n.player.getVideoUrl().replace("https://www.youtube.com/watch?v=",""),s.emit("skip",{error:e.data,id:l,pass:k,channel:B.toLowerCase})):void 0!==l&&n.loadVideoById(l)},onPlayerReady:function(e){try{beginning=!0,h=!0,window.MSStream||(i.mobilecheck()?($("#playpause").css("visibility","hidden"),$("#playpause").css("pointer-events","none")):$("#channel-load").css("display","none"),$("#player").css("opacity","1"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),n.loadVideoById(l),!M||i.mobilecheck()&&!T||n.playVideo(),x||n.durationSetter(),_?setTimeout(function(){n.player.seekTo(o),M||(n.player.pauseVideo(),d.play_pause_show())},1e3):n.seekTo(o)),n.readyLooks(),d.initYoutubeControls(n.player),d.initSlider(),n.player.setVolume(Crypt.get_volume()),$(".video-container").removeClass("no-opacity")}catch(e){}},readyLooks:function(){n.setBGimage(l)},setBGimage:function(e){if(void 0!==e&&!_){var t=new Image;t.onload=function(){var e=new ColorThief,a=e.getColor(t);"/"!=window.location.pathname&&(document.getElementById("main-container").style.backgroundColor=i.rgbToHsl(a,!0),$("meta[name=theme-color]").attr("content",i.rgbToHex(a[0],a[1],a[2])))},t.crossOrigin="Anonymous",t.src="https://zoff.me:8081/https://img.youtube.com/vi/"+e+"/mqdefault.jpg"}},set_width:function(e){if($(".video-container").width(e),!i.mobilecheck())if($(window).width()>769){var t=$(window).width()-$(".control-list").width()-$(".zbrand").outerWidth()-$(".brand-logo-navigate").outerWidth()-66;title_width=t,$(".title-container").width(title_width)}else $(".title-container").width("100%")},notifyUser:function(e,t){if(t=t.replace(/\\\'/g,"'").replace(/"/g,"'").replace(/&/g,"&"),"granted"===Notification.permission&&document.hidden){var a=new Notification("Now Playing",{body:t,icon:"https://i.ytimg.com/vi/"+e+"/mqdefault.jpg",iconUrl:"http://i.ytimg.com/vi/"+e+"/mqdefault.jpg"});a.onclick=function(e){window.focus(),this.cancel()},setTimeout(function(){a.close()},5e3)}},setup_all_listeners:function(){get_list_listener(),e(),setup_admin_listener(),setup_chat_listener(),t()},onYouTubeIframeAPIReady:function(){n.player=new YT.Player("player",{videoId:l,playerVars:{rel:"0",wmode:"transparent",controls:"0",fs:"0",iv_load_policy:"3",theme:"light",color:"white",showinfo:0},events:{onReady:n.onPlayerReady,onStateChange:n.onPlayerStateChange,onError:n.errorHandler}})},createFireplacePlayer:function(){n.fireplace=new YT.Player("fireplace_player",{videoId:"L_LUpnjgPso",playerVars:{rel:"0",wmode:"transparent",controls:"0",fs:"0",iv_load_policy:"3",theme:"light",color:"white",showinfo:0},events:{onReady:n.onFireplaceReady,onStateChange:n.onFireplaceChange}})},onFireplaceReady:function(){n.fireplace.playVideo()},onFireplaceChange:function(e){switch(e.data){case 0:n.fireplace.seekTo(0),n.fireplace.playVideo();break;case 2:n.fireplace.playVideo()}},durationSetter:function(){if(void 0!==duration)try{n.stopInterval||(x=!0),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=void 0!==n.player.getCurrentTime()?Math.floor(n.player.getCurrentTime()):o,currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=i.pad(minutes)+":"+i.pad(seconds)+" / "+i.pad(dMinutes)+":"+i.pad(dSeconds),per=100/duration*currDurr,per>=100?per=100:0===duration&&(per=0),N||$("#bar").width(per+"%")}catch(e){}n.stopInterval||setTimeout(n.durationSetter,1e3)},loadPlayer:function(){if(1==$("script[src='https://www.youtube.com/iframe_api']").length)try{n.onYouTubeIframeAPIReady()}catch(e){console.error("Seems YouTube iFrame script isn't correctly loaded. Please reload the page.")}else tag=document.createElement("script"),tag.src="https://www.youtube.com/iframe_api",firstScriptTag=document.getElementsByTagName("script")[0],firstScriptTag.parentNode.insertBefore(tag,firstScriptTag)}},i={log:function(e){"true"===localStorage.debug&&console.log(e)},rnd:function(e){return e[Math.floor(Math.random()*e.length)]},mobilecheck:function(){var e=!1;return(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4)))&&(e=!0),e},predicate:function(){for(var e,t,a,n=[],i=arguments.length,o=function(e,t){return e===t?0:e>24&255).toString(16)+(e>>16&255).toString(16)+(e>>8&255).toString(16)+(255&e).toString(16)},hexToRgb:function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null},pad:function(e){return e<10?"0"+Math.floor(e):Math.floor(e)},contains:function(e,t){for(var a=e.length;a--;)if(e[a]===t)return!0;return!1},sample:function(){Date.now()-lastSample>=2*SAMPLE_RATE&&(s.removeAllListeners(),s.disconnect(),s.connect(),n.setup_all_listeners()),lastSample=Date.now(),setTimeout(i.sample,SAMPLE_RATE)},loadjsfile:function(e){if(filesadded.indexOf("["+e+"]")==-1){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),filesadded+="["+e+"]"}},msieversion:function(){var e=window.navigator.userAgent,t=e.indexOf("MSIE ");return!!(t>0||navigator.userAgent.match(/Trident.*rv\:11\./))},getRandomInt:function(e,t){return Math.floor(Math.random()*(t-e))+e},secondsToOther:function(e){var t=e,a=Math.floor(t/60);return t-=60*a,[a,t]},rgbToHsl:function(e,t){r=e[0],g=e[1],b=e[2],r/=255,g/=255,b/=255;var a,n,i=Math.max(r,g,b),o=Math.min(r,g,b),s=(i+o)/2;if(i==o)a=n=0;else{var l=i-o;switch(n=s>.5?l/(2-i-o):l/(i+o),i){case r:a=(g-b)/l+(g.5&&t?s=.4:s<.65&&!t&&(s=.65),"hsl("+Math.floor(360*a)+", "+Math.floor(100*n)+"%, "+Math.floor(100*s)+"%)"},componentToHex:function(e){var t=e.toString(16);return 1==t.length?"0"+t:t},rgbToHex:function(e,t,a){return"#"+i.componentToHex(e)+i.componentToHex(t)+i.componentToHex(a)},upperFirst:function(e){return e.substring(0,1).toUpperCase()+e.substring(1).toLowerCase()},addClass:function(e,t){i.contains($(e).attr("class").split(" "),t)||$(e).addClass(t)},send_mail:function(e,t){""!==e&&""!==t&&($("#submit-contact-form").addClass("hide"),$("#send-loader").removeClass("hide"),$("#contact-form-from").attr("disabled","true"),$("#contact-form-message").attr("disabled","true"),$.ajax({type:"POST",data:{from:e,message:t},url:"/api/mail",success:function(e){"success"==e?($("#contact-container").empty(),$("#contact-container").html("Mail has been sent, we'll be back with you shortly.")):($("#contact-container").empty(),$("#contact-container").html("Something went wrong, sorry about that. You could instead try with your own mail-client: contact@zoff.no"))}}))}};$(document).on("submit","#contact-form",function(e){e.preventDefault();var t=$("#contact-form-message").val(),a=$("#contact-form-from").val();i.send_mail(a,t)}),Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;e=0&&e<=33?(1==document.getElementById("v-full").className.split(" ").length&&($("#v-full").toggleClass("hide"),$("#v-full-overlay").toggleClass("hide")),1==document.getElementById("v-medium").className.split(" ").length&&($("#v-medium").toggleClass("hide"),$("#v-medium-overlay").toggleClass("hide")),2==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),1==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide"))):e>=34&&e<=66?(1==document.getElementById("v-full").className.split(" ").length&&($("#v-full").toggleClass("hide"),$("#v-full-overlay").toggleClass("hide")),2==document.getElementById("v-medium").className.split(" ").length&&($("#v-medium").toggleClass("hide"),$("#v-medium-overlay").toggleClass("hide")),1==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),1==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide"))):e>=67&&e<=100&&(2==document.getElementById("v-full").className.split(" ").length&&($("#v-full").toggleClass("hide"),$("#v-full-overlay").toggleClass("hide")),1==document.getElementById("v-medium").className.split(" ").length&&($("#v-medium").toggleClass("hide"),$("#v-medium-overlay").toggleClass("hide")),1==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),1==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide")))},playPause:function(){state=n.player.getPlayerState(),button=document.getElementById("playpause"),1==state?n.pauseVideo():2==state&&n.playVideo()},volumeOptions:function(){T||(n.player.isMuted()?(n.player.unMute(),w=n.player.getVolume(),$("#volume").slider("value",n.player.getVolume())):(n.player.mute(),$("#volume").slider("value",0)))},hoverMute:function(e){w=n.player.getVolume()}},p={empty:!1,page:0,can_fit:Math.round($("#wrapper").height()/71),element_height:$("#wrapper").height()/Math.round($("#wrapper").height()/71)-25,uris:[],not_found:[],num_songs:0,channel_function:function(e){switch(e.type){case"list":S&&(!S||e.shuffled)||S&&prev_chan_list==B?S&&prev_chan_list==B&&void 0!=full_playlist&&!e.shuffled&&(p.populate_list(full_playlist,!0),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id})):(prev_chan_list=B,p.populate_list(e.playlist),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id}));break;case"added":p.added_song(e.value),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id});break;case"deleted":p.deleted_song(e.value,e.removed);break;case"vote":S||(p.voted_song(e.value,e.time),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id}));break;case"song_change":"/"!=window.location.pathname&&p.song_change(e.time,e.remove),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id})}},insertAtBeginning:function(e,t){var a=0==p.page?"":"none",n=p.generateSong(e,t,!1,!0,!1,a,!1);$("#wrapper").append(n)},insertAtIndex:function(e,t,a){var n=p.getIndexOfSong(e.id),i="none";if(!e.now_playing){n>=p.page&&n div:nth-child("+n+")").after(o);var s=$("#wrapper").children()[n];$(s).css("display",i),"block"==i&&$("#wrapper").children().length>=p.page+p.can_fit+1?$($("#wrapper").children()[p.page+p.can_fit]).css("display","none"):n=0?$($("#wrapper").children()[p.page]).css("display","block"):$("#wrapper").children().length>p.page+p.can_fit&&$($("#wrapper").children()[p.page+p.can_fit-1]).css("display","block"),a&&p.page>0&&$($("#wrapper").children()[p.page-1]).css("display","none"),t&&setTimeout(function(){$(s).css("height",p.element_height)},5)}},populate_list:function(e,t){if(i.mobilecheck()||_?_?(p.can_fit=Math.round($("#wrapper").height()/91)+1,p.element_height=$("#wrapper").height()/p.can_fit-4):(p.can_fit=Math.round(($(window).height()-$(".tabs").height()-$("header").height()-66)/71)+1,p.element_height=($(window).height()-$(".tabs").height()-$("header").height()-66)/p.can_fit-6):(p.can_fit=Math.round($("#wrapper").height()/71)+1,p.element_height=$("#wrapper").height()/p.can_fit-5.3),p.element_height<55.2&&(p.element_height=55.2),void 0===f&&(f=$("#list-song-html").html()),full_playlist=e,S&&!t)for(var a=0;a1?($.each(full_playlist,function(e,t){if(!t.now_playing){var a=p.generateSong(t,!1,v,!0,!1,"",!0);$("#wrapper").append(a)}}),$("#wrapper").children().length>p.can_fit&&!$("#pageButtons").length?($('
first_pagefirst_pagenavigate_before prevnavigate_before prev 1 next navigate_nextnext navigate_nextlast_pagelast_page
').insertAfter("#wrapper"),$(".prev_page").css("display","none"),$(".first_page").css("display","none"),$(".next_page_hide").css("display","none"),$(".last_page_hide").css("display","none")):$("#pageButtons").length||($('
first_pagefirst_pagenavigate_before prevnavigate_before prev 1 next navigate_nextnext navigate_nextlast_pagelast_page
').insertAfter("#wrapper"),$(".prev_page").css("display","none"),$(".next_page").css("display","none"),$(".last_page").css("display","none"),$(".first_page").css("display","none"),$(".next_page_hide").css("display","inline-flex"),$(".prev_page_hide").css("display","inline-flex")),p.dynamicContentPage(-10)):(p.empty=!0,$("#wrapper").html("The playlist is empty."),$("#pageButtons").length||$('
first_pagefirst_pagenavigate_before prevnavigate_before prev 1 next navigate_nextnext navigate_nextlast_pagelast_page
').insertAfter("#wrapper"),$(".prev_page").css("display","none"),$(".next_page").css("display","none"),$(".last_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".first_page").css("display","none"),$(".next_page_hide").css("display","inline-flex"),$(".prev_page_hide").css("display","inline-flex")),$("#settings").css("visibility","visible"),$("#settings").css("opacity","1"),$("#wrapper").css("opacity","1")},dynamicContentPageJumpTo:function(e){e*=p.can_fit,(e>p.page||e0&&"none"==$(".prev_page").css("display")&&($(".prev_page").css("display","inline-flex"),$(".prev_page_hide").css("display","none"),$(".first_page").css("display","inline-flex"),$(".first_page_hide").css("display","none")),p.page+p.can_fit>=$("#wrapper").children().length&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none")),$("#pageNumber").html(p.page/p.can_fit+1))},dynamicContentPage:function(e){1==e?($("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=p.page+p.can_fit,$("#wrapper").children().slice(p.page,p.page+p.can_fit).show(),p.page>0&&"none"==$(".prev_page").css("display")&&($(".prev_page").css("display","inline-flex"),$(".prev_page_hide").css("display","none"),$(".first_page").css("display","inline-flex"),$(".first_page_hide").css("display","none")),p.page+p.can_fit>=$("#wrapper").children().length&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none"))):10==e?($("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=Math.floor(($("#wrapper").children().length-1)/p.can_fit)*p.can_fit,$("#wrapper").children().slice(p.page,p.page+p.can_fit).show(),p.page>0&&"none"==$(".prev_page").css("display")&&($(".prev_page").css("display","inline-flex"),$(".prev_page_hide").css("display","none"),$(".first_page").css("display","inline-flex"),$(".first_page_hide").css("display","none")),p.page+p.can_fit>=$("#wrapper").children().length&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none"))):e==-10?($("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=0,$("#wrapper").children().slice(p.page,p.page+p.can_fit).show(),0==p.page&&"none"!=$(".prev_page").css("display")?($(".prev_page").css("display","none"),$(".prev_page_hide").css("display","inline-flex"),$(".first_page").css("display","none"),$(".first_page_hide").css("display","inline-flex")):"none"==$(".prev_page").css("display")?($(".prev_page_hide").css("display","inline-flex"),$(".first_page_hide").css("display","inline-flex")):($(".prev_page_hide").css("display","none"),$(".first_page_hide").css("display","none")),p.page+p.can_fit<$("#wrapper").children().length&&($(".next_page_hide").css("display","none"),$(".next_page").css("display","inline-flex"),$(".last_page_hide").css("display","none"),$(".last_page").css("display","inline-flex"))):($("#wrapper").children().slice(p.page-p.can_fit,p.page).show(),$("#wrapper").children().slice(p.page,p.page+p.can_fit).hide(),p.page=p.page-p.can_fit<0?0:p.page-p.can_fit,0==p.page&&"none"!=$(".prev_page").css("display")?($(".prev_page").css("display","none"),$(".prev_page_hide").css("display","inline-flex"),$(".first_page").css("display","none"),$(".first_page_hide").css("display","inline-flex")):"none"==$(".prev_page").css("display")?($(".prev_page_hide").css("display","inline-flex"),$(".first_page_hide").css("display","inline-flex")):($(".prev_page_hide").css("display","none"),$(".first_page_hide").css("display","none")),p.page+p.can_fit<$("#wrapper").children().length&&($(".next_page_hide").css("display","none"),$(".next_page").css("display","inline-flex"),$(".last_page_hide").css("display","none"),$(".last_page").css("display","inline-flex"))),$("#pageNumber").html(p.page/p.can_fit+1)},added_song:function(e){var t;if(void 0!=e){if(0!==full_playlist.length&&(t=full_playlist.pop()),full_playlist.push(e),p.sortList(),t&&full_playlist.push(t),$("#suggested-"+e.id).length>0){number_suggested-=1,number_suggested<0&&(number_suggested=0);var a=number_suggested>9?"9+":number_suggested;$(".suggested-link span.badge.new.white").hasClass("hide")||0!=a||$(".suggested-link span.badge.new.white").addClass("hide"),$(".suggested-link span.badge.new.white").text(a)}$("#suggested-"+e.id).remove(),p.empty&&(p.empty=!1),$("#empty-channel-message").remove(),p.insertAtIndex(e,!0),$($("#wrapper").children()[p.page+p.can_fit]).css("display","none"),$("#wrapper").children().length>p.page+p.can_fit?($(".next_page_hide").css("display","none"),$(".next_page").removeClass("hide"),$(".last_page_hide").css("display","none"),$(".next_page").css("display","inline-flex"),$(".last_page").css("display","inline-flex")):($(".next_page_hide").css("display","inline-flex"), +$(".next_page").css("display","none"))}},deleted_song:function(e,t){try{var a=p.getIndexOfSong(e),i=$("#wrapper").children()[a];t||(i.style.height=0),a=0?($($("#wrapper").children()[p.page]).css("height",0),$($("#wrapper").children()[p.page]).css("display","block"),$($("#wrapper").children()[p.page]).css("height",p.element_height)):$("#wrapper").children().length>p.page+p.can_fit&&($($("#wrapper").children()[p.page+p.can_fit]).css("height",0),$($("#wrapper").children()[p.page+p.can_fit]).css("display","block"),$($("#wrapper").children()[p.page+p.can_fit]).css("height",p.element_height)),p.page>=$("#wrapper").children().length-1?(p.dynamicContentPage(-1),$(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none")):p.page+p.can_fit+1>=$("#wrapper").children().length-1&&($(".next_page_hide").css("display","inline-flex"),$(".next_page").css("display","none"),$(".last_page_hide").css("display","inline-flex"),$(".last_page").css("display","none")),setTimeout(function(){t||$("#"+e).remove(),full_playlist.splice(p.getIndexOfSong(e),1),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id})},305),t&&$("#"+e).remove()}catch(t){full_playlist.splice(p.getIndexOfSong(e),1),p.empty||($("#"+e).remove(),a=0?$($("#wrapper").children()[p.page-1]).css("display","block"):$("#wrapper").children().length>p.page+p.can_fit&&$($("#wrapper").children()[p.page+(p.can_fit-1)]).css("display","block"),T&&n.sendNext({title:full_playlist[0].title,videoId:full_playlist[0].id}))}full_playlist.length<=2&&(p.empty=!0,$("#wrapper").html("The playlist is empty.")),$("#suggested-"+e).remove(),p.page+p.can_fit<$("#wrapper").children().length+1,p.page>=$("#wrapper").children().length&&p.dynamicContentPage(-1),Suggestions.checkUserEmpty()},voted_song:function(e,t){var a=p.getIndexOfSong(e),n=full_playlist[a];full_playlist[a].votes+=1,full_playlist[a].added=t,p.sortList(),$("#"+e).remove(),p.insertAtIndex(n,!1)},song_change:function(e,t){try{var a=full_playlist.length-1;$("#wrapper").children()[0].remove(),0===$("#wrapper").children().length&&(p.empty=!0,$("#wrapper").html("The playlist is empty.")),full_playlist[0].now_playing=!0,full_playlist[0].votes=0,full_playlist[0].guids=[],full_playlist[0].added=e,t?delete full_playlist[a]:full_playlist[a].now_playing=!1,i.log("---------------------------"),i.log("---SONG ON FIRST INDEX-----"),i.log(full_playlist[0]),i.log("---------------------------"),full_playlist.push(full_playlist.shift()),t||p.insertAtIndex(full_playlist[a-1],!1,!0)}catch(e){}},vote:function(e,t){return!S||"del"==t&&hasadmin&&!y&&""!=k?s.emit("vote",{channel:B,id:e,type:t,adminpass:k}):"pos"==t?p.voted_song(e,(new Date).getTime()/1e3):p.deleted_song(e),!0},skip:function(){return S?n.playNext():s.emit("skip",{pass:k,id:l,channel:B.toLowerCase()}),!0},exportToSpotify:function(){$.ajax({type:"GET",url:"https://api.spotify.com/v1/me",headers:{Authorization:"Bearer "+access_token_data.access_token},success:function(e){var t=e.id;$("#playlist_loader_export").removeClass("hide"),$(".exported-list-container").removeClass("hide"),$.ajax({type:"POST",url:"https://api.spotify.com/v1/users/"+t+"/playlists",headers:{Authorization:"Bearer "+access_token_data.access_token,"Content-Type":"application/json"},data:JSON.stringify({name:B.toLowerCase()+" - Zoff",public:!0}),success:function(e){var a=e.id;$.each(full_playlist,function(e,n){p.searchSpotify(n,a,t)})}})}})},searchSpotify:function(e,t,a){var n=e.title,o=e.title.toLowerCase().replace("-"," ");o=o.replace("official hd video",""),o=o.replace("unofficial video",""),o=o.replace("studio footage",""),o=o.replace("great song",""),o=o.replace("-"," "),o=o.replace("-"," "),o=o.replace(" hq "," "),o=o.replace("lyric video",""),o=o.replace("lyrics video",""),o=o.replace("album version",""),o=o.replace("drive original movie soundtrack",""),o=o.replace("original movie soundtrack",""),o=o.replace("live sessions",""),o=o.replace("audio only",""),o=o.replace("audio",""),o=o.replace("(new)",""),o=o.replace(" by "," "),o=o.replace(" vs "," "),o=o.replace("(full)"," "),o=o.replace("(video)"," "),o=o.replace("&"," "),o=o.replace("with lyrics",""),o=o.replace("lyrics",""),o=o.replace("w/",""),o=o.replace("w/",""),o=o.replace("official video",""),o=o.replace("studio version",""),o=o.replace("official music video",""),o=o.replace("music video",""),o=o.replace("musicvideo",""),o=o.replace("original video",""),o=o.replace("full version",""),o=o.replace("full song",""),o=o.replace("(official)",""),o=o.replace("official",""),o=o.replace("(original)",""),o=o.replace("("," "),o=o.replace(")"," "),o=o.replace("feat."," "),o=o.replace("feat"," "),o=o.replace("ft."," "),o=o.replace("["," "),o=o.replace("]"," "),o=o.replace(" free ",""),o=o.replace(" hd ",""),o=o.replace("original mix"," "),o=o.replace("radio edit"," "),o=o.replace("pop version"," "),o=o.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," "),o=encodeURIComponent(o),$.ajax({type:"GET",url:"https://api.spotify.com/v1/search?q="+o+"&type=track",headers:{Authorization:"Bearer "+access_token_data.access_token},async:!0,statusCode:{429:function(t){console.log(t.getAllResponseHeaders());var a=t.getResponseHeader("Retry-After");console.log(a),a||(a=5),a=parseInt(a,10),i.log("Retry-After",a),setTimeout(function(){p.searchSpotify(e)},1e3*a)}},error:function(t){if(429==t.status){console.log(t.getAllResponseHeaders());var a=t.getResponseHeader("Retry-After");console.log(a),a||(a=5),a=parseInt(a,10),i.log("Retry-After",a),setTimeout(function(){p.searchSpotify(e)},1e3*a)}},success:function(e){var s=!1;if($.each(e.tracks.items,function(e,t){if(t.name=t.name.toLowerCase(),t.name=t.name.replace("("," "),t.name=t.name.replace(")"," "),t.name=t.name.replace("["," "),t.name=t.name.replace("]"," "),t.name=t.name.replace("-"," "),t.name=t.name.replace("-"," "),t.name=t.name.replace("-"," "),t.name=t.name.replace("original mix"," "),t.name=t.name.replace("album version"," "),t.name=t.name.replace("abum version"," "),t.name=t.name.replace("feat."," "),t.artists[0].name=t.artists[0].name.replace("feat."," "),t.artists[0].name=t.artists[0].name.replace("feat"," "),t.name=t.name.replace("feat"," "),t.name=t.name.replace("ft."," "),t.name=t.name.replace("radio edit"," "),t.name=t.name.replace("pop version"," "),t.name=t.name.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," "),t.artists[0].name=t.artists[0].name.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ")," "==t.name.substring(t.name.length-1)&&(t.name=t.name.substring(0,t.name.length-1)),"."==t.name.substring(t.name.length-1)&&"."!=o.substring(o.length-1)&&(t.name=t.name.substring(0,t.name.length-1)),decodeURIComponent(o).indexOf(t.artists[0].name.toLowerCase())>=0&&decodeURIComponent(o).indexOf(t.name.toLowerCase())>=0)return s=!0,p.uris.push(t.uri),i.log("Found",o),!1;for(var a=t.name.split(" "),e=0;e=0||"&"==a[e]&&o.indexOf("and")>=0)&&o.indexOf(a[e])<0)return!0;return s=!0,p.uris.push(t.uri),i.log("Found",o),!1}),s||(p.not_found.push(n),p.num_songs=p.num_songs+1,i.log("Didn't find",n)),p.num_songs+p.uris.length==full_playlist.length){if(p.uris.length>100){for(;p.uris.length>100;)p.addToSpotifyPlaylist(p.uris.slice(0,100),t,a),p.uris=p.uris.slice(100,p.uris.length);p.addToSpotifyPlaylist(p.uris,t,a),$("#playlist_loader_export").addClass("hide")}else p.addToSpotifyPlaylist(p.uris,t,a),$("#playlist_loader_export").addClass("hide");$(".exported-list").append(""+B+""),$.each(p.not_found,function(e,t){var a=$("
"+not_export_html+"
");a.find(".extra-add-text").attr("value",t),a.find(".extra-add-text").attr("title",t),$(".not-exported-container").append(a.html())}),$(".not-exported").removeClass("hide"),$(".spotify_export_button").css("display","block")}}})},addToSpotifyPlaylist:function(e,t,a){$.ajax({type:"POST",url:"https://api.spotify.com/v1/users/"+a+"/playlists/"+t+"/tracks",headers:{Authorization:"Bearer "+access_token_data.access_token,"Content-Type":"application/json"},data:JSON.stringify({uris:e}),error:function(n){setTimeout(function(){p.addToSpotifyPlaylist(e,t,a)},3e3)},success:function(e){i.log("Added songs")}})},exportToYoutube:function(){var e="https://www.googleapis.com/youtube/v3/playlists?part=snippet";$(".exported-list-container").removeClass("hide"),$("#playlist_loader_export").removeClass("hide"),$.ajax({type:"POST",url:e,headers:{Authorization:"Bearer "+access_token_data_youtube.access_token,"Content-Type":"application/json"},data:JSON.stringify({snippet:{title:i.upperFirst(B.toLowerCase()),description:"Playlist exported from zoff"}}),success:function(e){var t=0,a=e.id,n="https://www.googleapis.com/youtube/v3/playlistItems?part=snippet";p.addToYoutubePlaylist(a,full_playlist,t,n)},error:function(e){i.log(e)}})},addToYoutubePlaylist:function(e,t,a,n){var o=JSON.stringify({snippet:{playlistId:e,resourceId:{kind:"youtube#video",videoId:t[a].id}}});$.ajax({type:"POST",url:n,headers:{Authorization:"Bearer "+access_token_data_youtube.access_token,"Content-Type":"application/json"},data:o,success:function(o){i.log("Added video: "+t[a].id+" to playlist id "+e),a==t.length-1?(i.log("All videoes added!"),i.log("url: https://www.youtube.com/playlist?list="+e),$(".exported-list").append(""+B+""),$("#playlist_loader_export").addClass("hide"),$(".current_number").addClass("hide")):($(".current_number").removeClass("hide"),$(".current_number").text(a+1+" of "+t.length),p.addToYoutubePlaylist(e,t,a+1,n))}})},importOldList:function(e){var t="",a=0;playlist_url="lists/"+e+".json",list=$.parseJSON($.ajax({type:"GET",url:playlist_url,async:!1}).responseText),$.each(list.songs,function(e,n){t+=n.id+",",a>45&&(Search.addVideos(t),t="",a=0),a++}),Search.addVideos(t),document.getElementById("search").value=""},sortList:function(){full_playlist.sort(i.predicate({name:"votes",reverse:!0},{name:"added",reverse:!1},{name:"title",reverse:!1}))},show:function(){i.mobilecheck()||(showToggle?(showToggle=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.me/"+B.toLowerCase())):(showToggle=!0,$("#toptitle").html("Zoff"),$("#chan").removeClass("bigChan"),$("#chan").html(B)))},generateSong:function(e,t,a,n,o,s,l){void 0===f&&(f=$("#list-song-html").html());var r,c,d=e.id,u=e.title,g=e.votes,m="background-image:url('//img.youtube.com/vi/"+d+"/mqdefault.jpg');",h=$("
"+f+"
"),v="style";if(t?h.find("#list-song").css("height",0):h.find(".list-song").css("height",p.element_height),y||h.find(".card-action").removeClass("hide"),1==g&&h.find(".vote-text").text("vote"),a&&(m="//img.youtube.com/vi/"+d+"/mqdefault.jpg",v="data-original"),n){h.find(".list-votes").text(g),h.find("#list-song").attr("id",d),h.find(".vote-container").attr("title",u),($("#wrapper").children().length>=p.can_fit&&l||"none"==s)&&h.find(".card").css("display","none"),r=".vote-container",c="delete_button";var _=i.secondsToOther(e.duration);h.find(".card-duration").text(i.pad(_[0])+":"+i.pad(_[1]))}else if(!n){h.find(".vote-text").text(""),h.find(".card-duration").text(i.pad(e.duration[0])+":"+i.pad(e.duration[1]));var w="user";r=".add-suggested",o?c="del_user_suggested":(c="del_suggested",w="system"),h.find(".vote-container").attr("class","clickable add-suggested"),h.find(".add-suggested").attr("title",u),h.find(".delete_button").addClass(c),h.find(r).attr("data-video-title",u),h.find(r).attr("data-video-length",e.length),h.find(r).attr("data-added-by",w),h.find("#list-song").attr("id","suggested-"+d),h.find(".list-image").attr("class",h.find(".list-image").attr("class").replace("list-image","list-suggested-image"))}return h.find(".list-title").text(u),h.find(".list-title").attr("title",u),h.find(r).attr("data-video-id",d),h.find(".list-image").attr(v,m),h.find(".list-suggested-image").attr(v,m),h.find("."+c).attr("data-video-id",d),h.html()},getIndexOfSong:function(e){try{return indexes=$.map(full_playlist,function(t,a){if(t.id==e)return a}),indexes[0]}catch(e){}},scrollTop:function(){$("#wrapper").scrollTop(0)},scrollBottom:function(){$("#wrapper").scrollTop($("#wrapper")[0].scrollHeight)}},u="",m=!1,h=!1,f=$("#list-song-html").html(),y=!0,v=!1,_=!0,w=100,k="",C=!1,x=!1,T=!1,S=!1,I=!1,E=window.location.hash.substring(1).split("&"),B=E[0],M=!1,L="#808080",N=!1,A={"sync disconnect on unload":!0,secure:!0,"force new connection":!0};$(document).ready(function(){3==E.length&&"autoplay"==E[2]?M=!0:m=!0,L="#"+E[1],add="https://zoff.me",s=io.connect(""+add+":8080",A),s.on("get_list",function(){setTimeout(function(){s.emit("list",B.toLowerCase())},1e3)}),s.on("viewers",function(e){viewers=e,void 0!==u&&n.getTitle(u,viewers)}),e(),t(),window.onYouTubeIframeAPIReady=n.onYouTubeIframeAPIReady,n.loadPlayer(),d.initSlider(),window.setVolume=a,$("#controls").css("background-color",L),$("#playlist").css("background-color",L)}),$(document).on("click","#zoffbutton",function(e){window.open("https://zoff.me/"+B.toLowerCase()+"/","_blank")}),$(document).on("click",".vote-container",function(e){var t=$(this).attr("data-video-id");p.vote(t,"pos")}),$(document).on("click",".prev_page",function(e){e.preventDefault(),p.dynamicContentPage(-1)}),$(document).on("click",".next_page",function(e){e.preventDefault(),p.dynamicContentPage(1)})}(); \ No newline at end of file diff --git a/server/views/layouts/frontpage.handlebars b/server/views/layouts/frontpage.handlebars index b1a6bd34..d624e7d5 100755 --- a/server/views/layouts/frontpage.handlebars +++ b/server/views/layouts/frontpage.handlebars @@ -18,7 +18,7 @@