").parent().html())),$("#video-container").append($(s.find("#main_components").wrap("
").parent().html())),$("#main-row").append("
"),$("#player").removeClass("player_bottom"),$("#main-row").removeClass("frontpage_modified_heights"),$("#main_section_frontpage").remove(),$("#closePlayer").remove(),$("#player_bottom_overlay").remove()),$("#search").attr("placeholder","Find song on YouTube..."),$(".page-footer").addClass("padding-bottom-novideo"),Pe=!0,1==$("#alreadychannel").length?a():(bt=!0,a()),0===$("#alreadyfp").length&&$("head").append("
")}})}};String.prototype.capitalizeFirstLetter=function(){return this.charAt(0).toUpperCase()+this.slice(1)};var q={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=[],s=arguments.length,i=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},hslToRgb:function(e,t,a){function n(e,t,a){return a<0&&(a+=1),a>1&&(a-=1),a<1/6?e+6*(t-e)*a:a<.5?t:a<2/3?e+(t-e)*(2/3-a)*6:e}var s,i,o;if(0==t)s=i=o=a;else{var l=a<.5?a*(1+t):a+t-a*t,r=2*a-l;s=n(r,l,e+1/3),i=n(r,l,e),o=n(r,l,e-1/3)}return[255*s,255*i,255*o]},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()-ke>=2*be&&(D.removeAllListeners(),D.disconnect(),D.connect(),xt.setup_all_listeners()),ke=Date.now(),setTimeout(q.sample,be)},loadjsfile:function(e){if(-1==de.indexOf("["+e+"]")){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),de+="["+e+"]"}},msieversion:function(){return!!(window.navigator.userAgent.indexOf("MSIE ")>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,s=Math.max(r,g,b),i=Math.min(r,g,b),o=(s+i)/2;if(s==i)a=n=0;else{var l=s-i;switch(n=o>.5?l/(2-s-i):l/(s+i),s){case r:a=(g-b)/l+(g.5&&t?o=.4:o<.65&&!t&&(o=.65),"hsl("+Math.floor(360*a)+", "+Math.floor(100*n)+"%, "+Math.floor(100*o)+"%)"},componentToHex:function(e){var t=e.toString(16);return 1==t.length?"0"+t:t},rgbToHex:function(e,t,a){return"#"+q.componentToHex(e)+q.componentToHex(t)+q.componentToHex(a)},upperFirst:function(e){return e.substring(0,1).toUpperCase()+e.substring(1).toLowerCase()},addClass:function(e,t){q.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"))}}))},firstY:null,lastY:null,currentY:null,vertScroll:!1,initAdjustment:0,touchstart:function(e){q.lastY=q.currentY=q.firstY=e.originalEvent.touches[0].pageY},touchmove:function(e){q.currentY=e.originalEvent.touches[0].pageY;var t=q.lastY-q.currentY;!q.vertScroll&&Math.abs(q.currentY-q.firstY)>30&&(q.vertScroll=!0,q.initAdjustment=q.currentY-q.firstY),q.vertScroll&&(window.scrollBy(0,t+q.initAdjustment),q.lastY=q.currentY+t)},touchend:function(e){q.vertScroll=!1,q.firstY=null,q.currentY=null,q.vertScroll=!1,q.initAdjustment=0,q.currentY=null},invertColor:function(e){if(0===e.indexOf("#")&&(e=e.slice(1)),3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)throw new Error("Invalid HEX color.");var t=(255-parseInt(e.slice(0,2),16)).toString(16),a=(255-parseInt(e.slice(2,4),16)).toString(16),n=(255-parseInt(e.slice(4,6),16)).toString(16);return"#"+padZero(t)+padZero(a)+padZero(n)},padZero:function(e,t){return t=t||2,(new Array(t).join("0")+e).slice(-t)}};Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;e0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id})):(Ke=Z,J.populate_list(e.playlist),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}));break;case"added":J.added_song(e.value),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}),nt=[],st=0;break;case"deleted":J.deleted_song(e.value,e.removed),nt=[],st=0;break;case"vote":Ze||(J.voted_song(e.value,e.time),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id})),nt=[],st=0;break;case"song_change":"/"!=window.location.pathname&&J.song_change(e.time,e.remove),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}),nt=[],st=0}},insertAtBeginning:function(e,t){var a=0==J.page?"":"none",n=J.generateSong(e,t,!1,!0,!1,a,!1);$("#wrapper").append(n)},insertAtIndex:function(e,t,a){var n=J.getIndexOfSong(e.id),s="none";if(!e.now_playing){n>=J.page&&n div:nth-child("+n+")").after(i);var o=$("#wrapper").children()[n];$(o).css("display",s),"inline-block"==s&&$("#wrapper").children().length>=J.page+J.can_fit+1?$($("#wrapper").children()[J.page+J.can_fit]).css("display","none"):n=0?$($("#wrapper").children()[J.page]).css("display","inline-block"):$("#wrapper").children().length>J.page+J.can_fit&&$($("#wrapper").children()[J.page+J.can_fit-1]).css("display","inline-block"),a&&J.page>0&&$($("#wrapper").children()[J.page-1]).css("display","none"),t&&setTimeout(function(){$(o).css("transform","translateX(0%)"),setTimeout(function(){$(o).removeClass("side_away")},300)},5)}},populate_list:function(e,t){if(q.mobilecheck()||Ee?Ee?(J.can_fit=Math.round($("#wrapper").height()/91)+1,J.element_height=$("#wrapper").height()/J.can_fit-4):(J.can_fit=Math.round(($(window).height()-$(".tabs").height()-$("header").height()-64-8)/71)+1,J.element_height=($(window).height()-$(".tabs").height()-$("header").height()-64-8)/J.can_fit-5):(J.can_fit=Math.round($("#wrapper").height()/71)+1,J.element_height=$("#wrapper").height()/J.can_fit-5.3),J.element_height<55.2&&(J.can_fit=J.can_fit-1,J.element_height=55.2,J.can_fit=Math.round(($(window).height()-$(".tabs").height()-$("header").height()-64-8)/71),J.element_height=($(window).height()-$(".tabs").height()-$("header").height()-64-8)/J.can_fit-5),void 0===ee&&(ee=$("#list-song-html").html()),ut=e,Ze&&!t)for(var a=0;a1?($.each(ut,function(e,t){if(!t.now_playing){var a=J.generateSong(t,!1,Ie,!0,!1,"",!0);$("#wrapper").append(a)}}),$("#wrapper").children().length>J.can_fit&&!$("#pageButtons").length?($('').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||($('').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")),J.dynamicContentPage(-10)):(J.empty=!0,$("#wrapper").html("The playlist is empty."),$("#pageButtons").length||$('').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*=J.can_fit)>J.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")),J.page+J.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(J.page/J.can_fit+1))},dynamicContentPage:function(e){1==e?($("#wrapper").children().slice(J.page,J.page+J.can_fit).hide(),J.page=J.page+J.can_fit,$("#wrapper").children().slice(J.page,J.page+J.can_fit).css("display","inline-block"),J.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")),J.page+J.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(J.page,J.page+J.can_fit).hide(),J.page=Math.floor(($("#wrapper").children().length-1)/J.can_fit)*J.can_fit,$("#wrapper").children().slice(J.page,J.page+J.can_fit).css("display","inline-block"),J.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")),J.page+J.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(J.page,J.page+J.can_fit).hide(),J.page=0,$("#wrapper").children().slice(J.page,J.page+J.can_fit).css("display","inline-block"),0==J.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")),J.page+J.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(J.page-J.can_fit,J.page).css("display","inline-block"),$("#wrapper").children().slice(J.page,J.page+J.can_fit).hide(),J.page=J.page-J.can_fit<0?0:J.page-J.can_fit,0==J.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")),J.page+J.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(J.page/J.can_fit+1)},added_song:function(e){var t;if(void 0!=e){if(0!==ut.length&&(t=ut.pop()),ut.push(e),J.sortList(),t&&ut.push(t),$("#suggested-"+e.id).length>0){Qe-=1,Qe<0&&(Qe=0);var a=Qe>9?"9+":Qe;$(".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(),J.empty&&(J.empty=!1),$("#empty-channel-message").remove(),J.insertAtIndex(e,!0),$($("#wrapper").children()[J.page+J.can_fit]).css("display","none"),$("#wrapper").children().length>J.page+J.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=J.getIndexOfSong(e);$("#wrapper").children()[a];a=0?($($("#wrapper").children()[J.page]).css("height",0),$($("#wrapper").children()[J.page]).css("display","inline-block"),$($("#wrapper").children()[J.page]).css("height",J.element_height)):$("#wrapper").children().length>J.page+J.can_fit&&($($("#wrapper").children()[J.page+J.can_fit]).css("height",0),$($("#wrapper").children()[J.page+J.can_fit]).css("display","inline-block"),$($("#wrapper").children()[J.page+J.can_fit]).css("height",J.element_height)),J.page>=$("#wrapper").children().length-1?(J.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")):J.page+J.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")),J.page<=a&&J.page-J.can_fit<=a?($("#"+e).addClass("side_away"),$("#"+e).find(".mobile-delete").remove(),$("#"+e).css("transform","translateX(-100%)"),setTimeout(function(){$("#"+e).remove()},300)):$("#"+e).remove(),ut.splice(J.getIndexOfSong(e),1),xt.sendNext({title:ut[0].title,videoId:ut[0].id})}catch(t){ut.splice(J.getIndexOfSong(e),1),J.empty||($("#"+e).remove(),a=0?$($("#wrapper").children()[J.page-1]).css("display","inline-block"):$("#wrapper").children().length>J.page+J.can_fit&&$($("#wrapper").children()[J.page+(J.can_fit-1)]).css("display","inline-block"),xt.sendNext({title:ut[0].title,videoId:ut[0].id}))}ut.length<=2&&(J.empty=!0,$("#wrapper").html("The playlist is empty.")),$("#suggested-"+e).remove(),J.page,J.can_fit,$("#wrapper").children().length,J.page>=$("#wrapper").children().length&&J.dynamicContentPage(-1),It.checkUserEmpty()},voted_song:function(e,t){var a=J.getIndexOfSong(e),n=ut[a];ut[a].votes+=1,ut[a].added=t,J.sortList(),$("#"+e).remove(),J.insertAtIndex(n,!1)},song_change:function(e,t){try{var a=ut.length-1;$("#wrapper").children()[0].remove(),ut.length<=1&&(J.empty=!0,$("#wrapper").html("The playlist is empty.")),ut[0].now_playing=!0,ut[0].votes=0,ut[0].guids=[],ut[0].added=e,t?delete ut[a]:ut[a].now_playing=!1,q.log("---------------------------"),q.log("---SONG ON FIRST INDEX-----"),q.log(ut[0]),q.log("---------------------------"),ut.push(ut.shift()),t||J.insertAtIndex(ut[$("#wrapper").children().length],!1,!0)}catch(e){}},vote:function(e,t){return!Ze||"del"==t&&Q&&!X&&""!=re?D.emit("vote",{channel:Z,id:e,type:t,adminpass:""==re?"":Y.crypt_pass(re),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}):"pos"==t?J.voted_song(e,(new Date).getTime()/1e3):J.deleted_song(e),!0},skip:function(){return Ze?xt.playNext():D.emit("skip",{pass:""==re?"":Y.crypt_pass(re),id:ft,channel:Z.toLowerCase(),userpass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}),!0},exportToSpotify:function(){$.ajax({type:"GET",url:"https://api.spotify.com/v1/me",headers:{Authorization:"Bearer "+De.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 "+De.access_token,"Content-Type":"application/json"},data:JSON.stringify({name:Z.toLowerCase()+" - Zoff",public:!0}),success:function(e){var a=e.id;$.each(ut,function(e,n){J.searchSpotify(n,a,t)})}})}})},searchSpotify:function(e,t,a){var n=e.title,s=e.title.toLowerCase().replace("-"," ");s.startsWith("the")&&(s=s.replace("the","")),s=s.replace(" hd",""),s=s.replace("official hd video",""),s=s.replace("unofficial video",""),s=s.replace("studio footage",""),s=s.replace("great song",""),s=s.replace("-"," "),s=s.replace("-"," "),s=s.replace(" hq"," "),s=s.replace("lyric video",""),s=s.replace("lyrics video",""),s=s.replace("album version",""),s=s.replace("drive original movie soundtrack",""),s=s.replace("original movie soundtrack",""),s=s.replace("live sessions",""),s=s.replace("audio only",""),s=s.replace("audio",""),s=s.replace("(new)",""),s=s.replace(" by "," "),s=s.replace(" vs "," "),s=s.replace("(full)"," "),s=s.replace("(video)"," "),s=s.replace("&"," "),s=s.replace("with lyrics",""),s=s.replace("lyrics",""),s=s.replace("w/",""),s=s.replace("w/",""),s=s.replace("official video",""),s=s.replace("studio version",""),s=s.replace("official music video",""),s=s.replace("music video",""),s=s.replace("musicvideo",""),s=s.replace("original video",""),s=s.replace("full version",""),s=s.replace("full song",""),s=s.replace("(official)",""),s=s.replace("official",""),s=s.replace("(original)",""),s=s.replace("("," "),s=s.replace(")"," "),s=s.replace("|",""),s=s.replace("feat."," "),s=s.replace("feat"," "),s=s.replace("ft."," "),s=s.replace("["," "),s=s.replace("]"," "),s=s.replace(" free ",""),s=s.replace(" hd",""),s=s.replace("original mix"," "),s=s.replace("radio edit"," "),s=s.replace("pop version"," "),s=s.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," "),s=encodeURIComponent(s),$.ajax({type:"GET",url:"https://api.spotify.com/v1/search?q="+s+"&type=track",headers:{Authorization:"Bearer "+De.access_token},async:!0,statusCode:{429:function(n){console.log(n.getAllResponseHeaders());var s=n.getResponseHeader("Retry-After");console.log(s),s||(s=5),s=parseInt(s,10),q.log("Retry-After",s),setTimeout(function(){J.searchSpotify(e,t,a)},1e3*s)}},error:function(n){if(429==n.status){console.log(n.getAllResponseHeaders());var s=n.getResponseHeader("Retry-After");console.log(s),s||(s=5),s=parseInt(s,10),q.log("Retry-After",s),setTimeout(function(){J.searchSpotify(e,t,a)},1e3*s)}},success:function(e){var i=!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)&&"."!=s.substring(s.length-1)&&(t.name=t.name.substring(0,t.name.length-1)),decodeURIComponent(s).indexOf(t.artists[0].name.toLowerCase())>=0&&decodeURIComponent(s).indexOf(t.name.toLowerCase())>=0)return i=!0,J.uris.push(t.uri),q.log("Found",s),!1;for(var a=t.name.split(" "),e=0;e=0||"&"==a[e]&&s.indexOf("and")>=0)&&s.indexOf(a[e])<0)return!0;return i=!0,J.uris.push(t.uri),q.log("Found",s),!1}),i||(J.not_found.push(n),J.num_songs=J.num_songs+1,q.log("Didn't find",n)),J.num_songs+J.uris.length==ut.length){if(J.uris.length>100){for(;J.uris.length>100;)J.addToSpotifyPlaylist(J.uris.slice(0,100),t,a),J.uris=J.uris.slice(100,J.uris.length);J.addToSpotifyPlaylist(J.uris,t,a),$("#playlist_loader_export").addClass("hide")}else J.addToSpotifyPlaylist(J.uris,t,a),$("#playlist_loader_export").addClass("hide");0==$(".exported-spotify-list").length&&$(".exported-list").append(""+Z+""),$.each(J.not_found,function(e,t){var a=$(""+ze+"
");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 "+De.access_token,"Content-Type":"application/json"},data:JSON.stringify({uris:e}),error:function(n){var s=t,i=e,o=a;setTimeout(function(){J.addToSpotifyPlaylist(i,s,o)},3e3)},success:function(e){q.log("Added songs")}})},exportToYoutube:function(){$(".exported-list-container").removeClass("hide"),$("#playlist_loader_export").removeClass("hide"),$.ajax({type:"POST",url:"https://www.googleapis.com/youtube/v3/playlists?part=snippet",headers:{Authorization:"Bearer "+Ue.access_token,"Content-Type":"application/json"},data:JSON.stringify({snippet:{title:q.upperFirst(Z.toLowerCase()),description:"Playlist exported from zoff"}}),success:function(e){var t=e.id;J.addToYoutubePlaylist(t,ut,0,"https://www.googleapis.com/youtube/v3/playlistItems?part=snippet")},error:function(e){q.log(e)}})},addToYoutubePlaylist:function(e,t,a,n){var s=JSON.stringify({snippet:{playlistId:e,resourceId:{kind:"youtube#video",videoId:t[a].id}}});$.ajax({type:"POST",url:n,headers:{Authorization:"Bearer "+Ue.access_token,"Content-Type":"application/json"},data:s,success:function(s){q.log("Added video: "+t[a].id+" to playlist id "+e),a==t.length-1?(q.log("All videoes added!"),q.log("url: https://www.youtube.com/playlist?list="+e),$(".exported-list").append(""+Z+""),$("#playlist_loader_export").addClass("hide"),$(".current_number").addClass("hide")):($(".current_number").removeClass("hide"),$(".current_number").text(a+1+" of "+t.length),J.addToYoutubePlaylist(e,t,a+1,n))}})},importOldList:function(e){var t="",a=0;playlist_url="lists/"+e+".json",yt=$.parseJSON($.ajax({type:"GET",url:playlist_url,async:!1}).responseText),$.each(yt.songs,function(e,n){t+=n.id+",",a>45&&(Tt.addVideos(t),t="",a=0),a++}),Tt.addVideos(t),document.getElementById("search").value=""},sortList:function(){ut.sort(q.predicate({name:"votes",reverse:!0},{name:"added",reverse:!1},{name:"title",reverse:!1}))},show:function(){q.mobilecheck()||(K?(K=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.me/"+Z.toLowerCase())):(K=!0,$("#toptitle").html("Zoff"),$("#chan").removeClass("bigChan"),$("#chan").html(Z)))},generateSong:function(e,t,a,n,s,i,o){void 0===ee&&(ee=$("#list-song-html").html());var l,r,c=e.id,d=e.title,p=e.votes,u="background-image:url('//img.youtube.com/vi/"+c+"/mqdefault.jpg');",g=$(""+ee+"
"),h="style";if(t&&(g.find(".list-song").css("transform","translateX(100%)"),g.find(".list-song").addClass("side_away")),g.find(".list-song").css("height",J.element_height),X||g.find(".card-action").removeClass("hide"),1==p&&g.find(".vote-text").text("vote"),a&&(u="//img.youtube.com/vi/"+c+"/mqdefault.jpg",h="data-original"),n){g.find(".list-votes").text(p),g.find("#list-song").attr("data-video-id",c),g.find("#list-song").attr("data-video-type","song"),g.find("#list-song").attr("id",c),g.find(".vote-container").attr("title",d),($("#wrapper").children().length>=J.can_fit&&o||"none"==i)&&g.find(".card").css("display","none"),l=".vote-container",r="delete_button";var m=q.secondsToOther(e.duration);g.find(".card-duration").text(q.pad(m[0])+":"+q.pad(m[1]))}else if(!n){g.find(".suggested_remove").removeClass("hide"),g.find(".vote-text").text(""),g.find(".card-duration").text(q.pad(e.duration[0])+":"+q.pad(e.duration[1]));var f="user";l=".add-suggested",s?r="del_user_suggested":(r="del_suggested",f="system"),g.find(".vote-container").attr("class","clickable add-suggested"),g.find(".add-suggested").attr("title",d),g.find(".delete_button").addClass(r),g.find(l).attr("data-video-title",d),g.find(l).attr("data-video-length",e.length),g.find(l).attr("data-added-by",f),g.find("#list-song").attr("data-video-type","suggested"),g.find("#list-song").attr("data-video-id",c),g.find("#list-song").attr("id","suggested-"+c),g.find(".list-image").attr("class",g.find(".list-image").attr("class").replace("list-image","list-suggested-image"))}return g.find(".mobile-delete").remove(),g.find(".list-title").text(d),g.find(".list-title").attr("title",d),g.find(l).attr("data-video-id",c),g.find(".list-image").attr(h,u),g.find(".list-suggested-image").attr(h,u),g.find("."+r).attr("data-video-id",c),g.html()},getIndexOfSong:function(e){try{return indexes=$.map(ut,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)}},W=3,Z=void 0===window.chan?$("#chan").html():window.chan,X=!0,Q=0,K=!0,ee=$("#list-song-html").html(),te=!1,ae="***REMOVED***",ne=!1,se=/P((([0-9]*\.?[0-9]*)Y)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)W)?(([0-9]*\.?[0-9]*)D)?)?(T(([0-9]*\.?[0-9]*)H)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)S)?)?/,ie=[],oe=!1,le=0,j=1,re="",ce=!1,de="",pe=!1,ue=1,ge="",he=!1,me=!1,fe=!1,ye=!1,ve=!1,_e=!1,$e=1,we=!1,be=6e3,ke=Date.now(),Ce=!1,xe=!1,Se="",Te=-1,Ie=!1,Ee=!1,Le=!0,Be=!1,Me=!1,Ae=!1,Ne=!1,Pe=!1,De={},Ve=!1,Oe="",ze="",Ye=300,je=600,Re="&autoplay",qe=!1,Ue={},He=!1,Fe=!1,Ge="808080",Je=!1,We=!1,Ze=!1,Xe=!1,Qe=0,Ke="",et="",tt=!1,at="",nt=[],st=0,it="";if(void 0===localStorage.debug){localStorage.debug=!1}var ot,lt,rt,ct,dt,pt,ut,ie,gt,ht,mt,ue,ft,yt,vt,_t,$t,D,wt={"sync disconnect on unload":!0,secure:!0,"force new connection":!0},bt=!1,kt=!1;try{navigator.serviceWorker.getRegistration("/").then(function(e){e&&e.unregister()})}catch(e){}$.ajaxPrefilter(function(e,t,a){e.async=!0}),$().ready(function(){localStorage.getItem("VERSION")&&parseInt(localStorage.getItem("VERSION"))==W||localStorage.setItem("VERSION",W),bt||"/"==window.location.pathname?kt||"/"!=window.location.pathname||t():a(),q.mobilecheck()&&D.on("guid",function(e){it=e}),D.on("connect",function(){qe&&(qe=!1,$(".connect_error").fadeOut(function(){$(".connect_error").remove(),Materialize.toast("Connected!",2e3,"green lighten"),Ze&&D.emit("offline",{status:!0,channel:void 0!=Z?Z.toLowerCase():""}),void 0!==Y.get_pass(Z.toLowerCase())&&""!==Y.get_pass(Z.toLowerCase())&&D.emit("password",{password:Y.crypt_pass(Y.get_pass(Z.toLowerCase())),channel:Z.toLowerCase()})}))}),D.on("self_ping",function(){void 0!=Z&&""!=Z.toLowerCase()&&D.emit("self_ping",{channel:Z.toLowerCase()})}),o();try{$.ajax({type:"GET",url:"https://api.github.com/users/zoff-music/received_events",success:function(e){for(var t=0;t"+e[0].created_at.substring(0,10)+": "+e[0].actor.display_login+"
"+e[0].payload.commits[0].sha.substring(0,10)+": "+e[0].payload.commits[0].message+"
J.can_fit||ee&&$($("#wrapper").children()[J.page+e]).css("display","none"),J.can_fit=e,J.element_height=$("#wrapper").height()/J.can_fit-5.3,$(".list-song").css("height",J.element_height+"px"),C(),$("#controls").length>0&&!q.mobilecheck()?$("#seekToDuration").css("top",$("#controls").position().top-55):$("#controls").length>0&&$("#seekToDuration").css("top",$("#controls").position().top-20)}}),$(document).on("click",".result-object",function(e){var t=$(e.target);if("9?"9+":Qe;$(".suggested-link span.badge.new.white").hasClass("hide")||0!=i||$(".suggested-link span.badge.new.white").addClass("hide"),$(".suggested-link span.badge.new.white").text(i)}$("#suggested-"+t).remove()}),$(document).on("click",".del_suggested",function(e){var t=$(this).attr("data-video-id");$("#suggested-"+t).remove()}),$(document).on("click",".del_user_suggested",function(e){var t=$(this).attr("data-video-id");$("#suggested-"+t).remove(),(Qe-=1)<0&&(Qe=0);var a=Qe>9?"9+":Qe;$(".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),J.vote(t,"del")}),$(document).on("click","#toast-container",function(){$(this).fadeOut(function(){$(this).remove()})}),$(document).on("click","#embed-area",function(){this.select()}),$(document).on("click",".brand-logo-navigate",function(e){e.preventDefault(),window.history.pushState("to the frontpage!","Title","/"),N()}),$(document).on("click","#player_bottom_overlay",function(){R.to_channel(Z.toLowerCase(),!1)}),$(document).keydown(function(e){if("/"!=window.location.pathname)if(91==e.keyCode||17==e.keyCode)Je=!0;else if(Je&&70==e.keyCode)Je=!1,We=!We,e.preventDefault(),We?($("#find_div").toggleClass("hide"),$("#find_input").focus(),at=""):($("#find_div").toggleClass("hide"),$("#find_input").val(""),$("#find_input").blur(),$(".highlight").removeClass("highlight"),nt=[],st=0,at="");else if(32!=e.keyCode||!$(".search-container").hasClass("hide")||"/"==window.location.pathname||$("#text-chat-input").is(":focus")||$("#password").is(":focus")||$("#user-pass-input").is(":focus")||$("#chan_thumbnail").is(":focus")||$("#chan_description").is(":focus")||$("#contact-form-from").is(":focus")||$("#contact-form-message").is(":focus")||$("#remote_channel").is(":focus")||$("#import").is(":focus")||$("#find_input").is(":focus")||$("#import_spotify").is(":focus"))Je=!1;else{if(1==xt.player.getPlayerState())return e.preventDefault(),xt.player.pauseVideo(),!1;if(2==xt.player.getPlayerState()||5==xt.player.getPlayerState())return e.preventDefault(),xt.player.playVideo(),!1}}),$(document).on("click","#close_find_form_button",function(e){e.preventDefault(),Je=!1,We=!1,$("#find_div").toggleClass("hide"),$("#find_input").val(""),$("#find_input").blur(),$(".highlight").removeClass("highlight"),nt=[],st=0,at=""}),$(document).keyup(function(e){91!=e.keyCode&&17!=e.keyCode||We||(Je=!1)}),$(document).on("submit","#find_form",function(e){if(e.preventDefault(),this.find_value.value!=at&&(at=this.find_value.value,nt=[],st=0),0==nt.length){var t=this;st=0,nt=$.map(ut,function(e,a){if(e.title.toLowerCase().indexOf(t.find_value.value.toLowerCase())>=0&&a!=ut.length-1)return a}),$("#num_found").text(st+1),$("#of_total_found").text(nt.length)}else st+=1,nt.length-10&&nt[st]!=ut.length-1){$(".highlight").removeClass("highlight");var a=Math.floor(nt[st]/J.can_fit);$($("#wrapper").children()[nt[st]]).addClass("highlight"),J.dynamicContentPageJumpTo(a)}else $(".highlight").removeClass("highlight"),q.log("none found")});var Ct={id:"",get_input:function(e){""===Ct.id?Ct.set_id(e.toLowerCase()):Ct.set_channel(e.toLowerCase())},set_id:function(e){Ct.id=e,$("#pausebutton_remote").attr("disabled",!1),$("#skipbutton_remote").attr("disabled",!1),$("#playbutton_remote").attr("disabled",!1),$("#skipbutton_remote").attr("disabled",!1),$("#remote_channel").val(""),$("#remote_channel").attr("placeholder","Change channel"),$("#remote_header").html("Controlling "+e),$("#volume-control-remote").css("display","inline-block"),$(".slider-vol-mobile").attr("style","display: inline-block !important")},set_channel:function(e){D.emit("id",{id:Ct.id,type:"channel",value:e})},play_remote:function(){D.emit("id",{id:Ct.id,type:"play",value:"mock"})},pause_remote:function(){D.emit("id",{id:Ct.id,type:"pause",value:"mock"})},skip_remote:function(){D.emit("id",{id:Ct.id,type:"skip",value:"mock"})},initiate_volume:function(){$("#volume-control-remote").slider({min:0,max:100,value:100,range:"min",animate:!0,stop:function(e,t){D.emit("id",{id:Ct.id,type:"volume",value:t.value}),q.log("volume")}})}},xt={loaded:!0,before_load:"",after_load:"",player:"",stopInterval:!1,fireplace:"",youtube_listener:function(e){var t;Ee&&e.np&&window.parentWindow&&window.parentOrigin&&(window.parentWindow.postMessage({type:"np",title:e.np[0].title},window.parentOrigin),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}));try{t=xt.player.getPlayerState()}catch(e){t=null}if((!Ze&&(null!=t||Pe)||Ze&&(null==t||Pe)||!Ze&&(null==t||Pe)||Ze&&-1==t)&&(!Ze||et!=Z)||Ze&&void 0==ft){et=Z,Pe=!1,xt.loaded=!1,q.log("--------youtube_listener--------"),q.log("Received: "),q.log(e),q.log("paused variable: "+_e),q.log("mobile_beginning variable: "+ct);try{q.log("getVideoUrl(): "+xt.player.getVideoUrl().split("v=")[1])}catch(e){}if(q.log("video_id variable: "+ft),q.log("---------------------------------"),e.np){if(_e)xt.getTitle(e.np[0].title,ue),q.mobilecheck()||xt.notifyUser(e.np[0].id,e.np[0].title),Fe||xt.stopVideo(),ft=e.np[0].id,ie=e.conf[0],time=e.time,vt=time-ie.startTime,_t=e.np[0].title,duration=e.np[0].duration,xt.setBGimage(ft);else if(!_e){void 0===$t?$t=e.np[0].id:$t!=ft&&($t=ft),ft=e.np[0].id,ie=e.conf[0],time=e.time,vt=time-ie.startTime,_t=e.np[0].title,duration=e.np[0].duration,ct&&q.mobilecheck()&&0===vt&&!Fe&&(vt=1);try{ut[0].id!=ft||ct||J.song_change(ut[0].added),It.fetchYoutubeSuggests(ft)}catch(e){}if(xt.getTitle(_t,ue),xt.setBGimage(ft),pe&&!window.MSStream)try{var a;try{a=xt.player.getVideoUrl().split("v=")[1]!=ft}catch(e){a=!0}(a||Fe)&&(xt.loadVideoById(ft,duration),q.mobilecheck()||xt.notifyUser(ft,_t),xt.seekTo(vt),_e&&!Fe&&xt.pauseVideo()),_e||(ct&&!Fe||xt.playVideo(),Be||xt.durationSetter()),(xt.player.getDuration()>vt||0===xt.player.getDuration()||Fe||xt.player.getCurrentTime()!=vt)&&xt.seekTo(vt),xt.after_load=ft,xt.loaded||setTimeout(function(){xt.loaded=!0},500)}catch(e){Fe&&(xt.loadVideoById(ft,duration),xt.seekTo(vt)),Be||Fe||xt.durationSetter()}else xt.getTitle(_t,ue)}}else{document.getElementById("song-title").innerHTML="Empty channel. Add some songs!",document.title="Zoff - the shared YouTube based radio",$("#channel-load").css("display","none"),window.MSStream||Fe||$("#player_overlay").hasClass("hide")&&$("#player_overlay").removeClass("hide");try{Fe||xt.stopVideo()}catch(e){}}}else Be||xt.durationSetter(),duration=xt.player.getDuration()},onPlayerStateChange:function(e){q.log("-------onPlayerStateChange------"),q.log("New state\nState: "),q.log(e);try{q.log("Duration: "+xt.player.getDuration(),"Current time: "+xt.player.getCurrentTime()),q.log("getVideoUrl(): "+xt.player.getVideoUrl().split("v=")[1])}catch(e){}switch(q.log("video_id variable: "+ft),q.log("---------------------------------"),e.data){case YT.PlayerState.UNSTARTED:break;case YT.PlayerState.ENDED:we=!1,_e=!1,Ze?xt.playNext():D.emit("end",{id:ft,channel:Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))});break;case YT.PlayerState.PLAYING:window.MSStream||($("#player").css("opacity","1"),q.mobilecheck()||$("#channel-load").css("display","none")),we=!0,beginning&&q.mobilecheck()&&!Fe&&(beginning=!1,ct=!1),Ee||"/"==window.location.pathname||Fe||q.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")),_e&&!Ze&&(D.emit("pos",{channel:Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}),_e=!1);break;case YT.PlayerState.PAUSED:Fe||(beginning&&ct&&($("#playpause").css("visibility","visible"),$("#playpause").css("pointer-events","all"),$("#channel-load").css("display","none")),_e=!0,"/"!=window.location.pathname&&St.play_pause_show(),ct=!0);break;case YT.PlayerState.BUFFERING:}},playVideo:function(){Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"playVideo"}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:_t,image:"https://img.youtube.com/vi/"+ft+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+ft+"/mqdefault.jpg"),$("#pause").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):xt.player.playVideo()},pauseVideo:function(){Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"pauseVideo"}),$("#play").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):xt.player.pauseVideo()},seekTo:function(e){Fe?U.sendMessage("urn:x-cast:zoff.me",{type:"seekTo",seekTo:e}):Ze?xt.player.seekTo(0):xt.player.seekTo(e)},loadVideoById:function(e,t){Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:e,channel:Z.toLowerCase()}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:_t,image:"https://img.youtube.com/vi/"+e+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+e+"/mqdefault.jpg")):xt.player.loadVideoById({videoId:e,startSeconds:0,endSeconds:t})},stopVideo:function(){if(Fe)U.sendMessage("urn:x-cast:zoff.me",{type:"stopVideo"});else try{xt.player.stopVideo()}catch(e){}},setVolume:function(e){Fe?U.setVolume(e/100):xt.player.setVolume(e)},playNext:function(){var e=ut[0];ft=e.id,time=(new Date).getTime(),_t=e.title,duration=e.duration,xt.getTitle(_t,ue),xt.setBGimage(ft),Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:ft,channel:Z.toLowerCase()}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:_t,image:"https://img.youtube.com/vi/"+ft+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+ft+"/mqdefault.jpg")):xt.loadVideoById(ft,duration),J.channel_function({type:"song_change",time:time})},sendNext:function(e){Fe&&U.sendMessage("urn:x-cast:zoff.me",{type:"nextVideo",title:e.title,videoId:e.videoId}),Ee&&window.parentWindow&&window.parentOrigin&&window.parentWindow.postMessage({type:"nextVideo",title:e.title},window.parentOrigin)},getTitle:function(e,t){var a=decodeURIComponent(e);if("/"!=window.location.pathname){var n=document.getElementById("song-title"),s=document.getElementById("viewers");n.innerHTML=a,s.innerHTML="visibility "+t,n.title=a,Fe&&($("#player_overlay").css("background","url(https://img.youtube.com/vi/"+ft+"/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=a+" • Zoff / "+Z},errorHandler:function(e){fe||(5==e.data||100==e.data||101==e.data||150==e.data?(curr_playing=xt.player.getVideoUrl().replace("https://www.youtube.com/watch?v=",""),D.emit("skip",{error:e.data,id:ft,pass:""==re?"":Y.crypt_pass(re),channel:Z.toLowerCase(),userpass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))})):void 0!==ft&&xt.loadVideoById(ft,duration))},onPlayerReady:function(e){try{beginning=!0,pe=!0,window.MSStream||(q.mobilecheck()&&($("#playpause").css("visibility","hidden"),$("#playpause").css("pointer-events","none"),$("#player").css("opacity","1")),$(".video-container").removeClass("no-opacity"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),xt.loadVideoById(ft,duration),!Le||q.mobilecheck()&&!Fe||xt.playVideo(),Be||xt.durationSetter(),Ee?setTimeout(function(){xt.player.seekTo(vt),Le||(xt.player.pauseVideo(),St.play_pause_show())},1e3):xt.seekTo(vt)),xt.readyLooks(),St.initYoutubeControls(xt.player),St.initSlider(),xt.player.setVolume(Y.get_volume())}catch(e){}},readyLooks:function(){xt.setBGimage(ft)},setBGimage:function(e){if(void 0!==e&&!Ee){var t=new Image;t.onload=function(){var e=new ColorThief,a=e.getColor(t);"/"!=window.location.pathname&&(document.getElementById("main-container").style.backgroundColor=q.rgbToHsl(a,!0),$("meta[name=theme-color]").attr("content",q.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),!q.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&&!Ee){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(){c(),l(),u(),h(),m()},onYouTubeIframeAPIReady:function(){xt.player=new YT.Player("player",{videoId:ft,playerVars:{rel:"0",wmode:"transparent",controls:"0",fs:"0",iv_load_policy:"3",theme:"light",color:"white",showinfo:0},events:{onReady:xt.onPlayerReady,onStateChange:xt.onPlayerStateChange,onError:xt.errorHandler}})},createFireplacePlayer:function(){xt.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:xt.onFireplaceReady,onStateChange:xt.onFireplaceChange}})},onFireplaceReady:function(){xt.fireplace.playVideo()},onFireplaceChange:function(e){switch(e.data){case 0:xt.fireplace.seekTo(0),xt.fireplace.playVideo();break;case 2:xt.fireplace.playVideo()}},durationSetter:function(){try{ye||void 0===duration||(xt.stopInterval||(Be=!0),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=void 0!==xt.player.getCurrentTime()?Math.floor(xt.player.getCurrentTime()):vt,currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=q.pad(minutes)+":"+q.pad(seconds)+" / "+q.pad(dMinutes)+":"+q.pad(dSeconds),per=100/duration*currDurr,per>=100?per=100:0===duration&&(per=0),Ee&&window.parentWindow&&window.parentOrigin&&window.parentWindow.postMessage({type:"duration",duration:xt.player.getCurrentTime(),full_duration:xt.player.getDuration(),percent:per},window.parentOrigin),me||$("#bar").width(per+"%"))}catch(e){}xt.stopInterval||setTimeout(xt.durationSetter,1e3)},loadPlayer:function(){if(1==$("script[src='https://www.youtube.com/iframe_api']").length)try{xt.onYouTubeIframeAPIReady()}catch(e){console.error("Seems YouTube iFrame script isn't correctly loaded. Please reload the page.")}else gt=document.createElement("script"),gt.src="https://www.youtube.com/iframe_api",ht=document.getElementsByTagName("script")[0],ht.parentNode.insertBefore(gt,ht)}},St={stopInterval:!1,initYoutubeControls:function(){q.mobilecheck()&&!window.MSStream&&$("#controls").appendTo("#playbar"),St.initControls()},initControls:function(){document.getElementById("volume-button").addEventListener("click",St.mute_video),document.getElementById("playpause").addEventListener("click",St.play_pause),document.getElementById("volume-button-overlay").addEventListener("click",St.mute_video),document.getElementById("playpause-overlay").addEventListener("click",St.play_pause),document.getElementById("fullscreen").addEventListener("click",St.fullscreen)},initSlider:function(){try{vol=Y.get_volume()}catch(e){}$("#volume").slider({min:0,max:100,value:vol,range:"min",animate:!0,slide:function(e,t){St.setVolume(t.value);try{Y.set_volume(t.value)}catch(e){}}}),St.choose_button(vol,!1)},fullscreen:function(){var e=document.getElementById("player"),t=e.requestFullScreen||e.mozRequestFullScreen||e.webkitRequestFullScreen;t&&t.bind(e)()},play_pause:function(){Fe?St.play_pause_show():xt.player.getPlayerState()==YT.PlayerState.PLAYING?(xt.pauseVideo(),q.mobilecheck()&&!window.MSStream&&(document.getElementById("player").style.display="none",$(".video-container").toggleClass("click-through"),$(".page-footer").toggleClass("padding-bottom-extra"))):xt.player.getPlayerState()!=YT.PlayerState.PAUSED&&xt.player.getPlayerState()!==YT.PlayerState.ENDED&&xt.player.getPlayerState()!==YT.PlayerState.CUED||(xt.playVideo(),q.mobilecheck()&&!window.MSStream&&(document.getElementById("player").style.display="block",$(".video-container").toggleClass("click-through"),$(".page-footer").toggleClass("padding-bottom-extra")))},play_pause_show:function(){Fe?$("#play").hasClass("hide")?xt.pauseVideo():$("#pause").hasClass("hide")&&xt.playVideo():(1==document.getElementById("pause").className.split(" ").length&&($("#pause").toggleClass("hide"),$("#pause-overlay").toggleClass("hide")),2==document.getElementById("play").className.split(" ").length&&($("#play").toggleClass("hide"),$("#play-overlay").toggleClass("hide")))},settings:function(){$("#qS").toggleClass("hide")},changeQuality:function(e){xt.player.getPlaybackQuality!=e&&(xt.player.setPlaybackQuality(e),xt.player.getPlaybackQuality()),$("#qS").toggleClass("hide")},mute_video:function(){xt.player.isMuted()?(Fe&&U.sendMessage("urn:x-cast:zoff.me",{type:"unMute"}),xt.player.unMute(),St.choose_button(xt.player.getVolume(),!1)):(Fe&&U.sendMessage("urn:x-cast:zoff.me",{type:"mute"}),St.choose_button(0,!0),xt.player.mute())},setVolume:function(e){xt.setVolume(e),St.choose_button(e,!1),xt.player.isMuted()&&xt.player.unMute()},choose_button:function(e,t){t?(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")),1==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),2==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide"))):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=xt.player.getPlayerState(),button=document.getElementById("playpause"),state==YT.PlayerState.PLAYING?xt.pauseVideo():state==YT.PlayerState.PAUSED&&xt.playVideo()},volumeOptions:function(){Fe||(xt.player.isMuted()?(xt.player.unMute(),vol=xt.player.getVolume(),$("#volume").slider("value",xt.player.getVolume())):(xt.player.mute(),$("#volume").slider("value",0)))},hoverMute:function(e){vol=xt.player.getVolume()}},Tt={submitArray:[],submitArrayExpected:null,showSearch:function(){$("#search-wrapper").toggleClass("hide"),q.mobilecheck()&&$(".search_input").focus(),$("#song-title").toggleClass("hide"),$("#results").empty(),"close"==$("#search-btn i").html()?$("#search-btn i").html("search"):$("#search-btn i").html("close"),$("#search").focus()},search:function(e,t,a){if(void 0!==lt&&void 0!==rt||(lt=$("#temp-results-container"),rt=$("#empty-results-container").html()),$(".search_results").html(""),""!==e){ne=!0;var n=encodeURIComponent(e),s="https://www.googleapis.com/youtube/v3/search?key="+ae+"&videoEmbeddable=true&part=id&fields=items(id)&type=video&order=viewCount&safeSearch=none&maxResults=25";s+="&q="+n,le&&(s+="&videoCategoryId=10");var i="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";if(a)var s="https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&relatedToVideoId="+n+"&type=video&key="+ae,i="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";q.contains($(".search_loader_spinner").attr("class").split(" "),"active")||$(".search_loader_spinner").addClass("active"),q.contains($("#results").attr("class").split(" "),"hide")&&$("#results").removeClass("hide"),$.ajax({type:"GET",url:s,dataType:"jsonp",success:function(a){0===a.items.length?($(""+rt+"
").appendTo($("#results")).show("blind",83.33),q.contains($(".search_loader_spinner").attr("class").split(" "),"active")&&$(".search_loader_spinner").removeClass("active")):a.items&&($.each(a.items,function(e,t){i+=t.id.videoId+","}),$.ajax({type:"GET",url:i,dataType:"jsonp",success:function(a){var n="",s=$(lt);$.each(a.items,function(e,t){var a=t.contentDetails.duration;if(secs=Tt.durationToSeconds(a),!longsongs||secs<720){mt=t.snippet.title,enc_title=mt,pt=t.id,a=a.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s"),thumb=t.snippet.thumbnails.medium.url;var i=s;i.find(".search-title").text(mt),i.find(".result_info").text(a),i.find(".thumb").attr("src",thumb),i.find("#add-many").attr("data-video-id",pt),i.find("#add-many").attr("data-video-title",enc_title),i.find("#add-many").attr("data-video-length",secs),i.find("#temp-results").attr("data-video-id",pt),i.find("#temp-results").attr("data-video-title",enc_title),i.find("#temp-results").attr("data-video-length",secs),i.find(".open-externally").attr("href","https://www.youtube.com/watch?v="+pt),void 0!=i.html()&&(n+=i.html())}}),n.length>0?($(""+n+"
").appendTo($("#results")).show("blind",83.33*(a.items.length-1)),q.contains($(".search_loader_spinner").attr("class").split(" "),"active")&&$(".search_loader_spinner").removeClass("active"),$(".add-many").click(function(e){return e.preventDefault(),e.stopPropagation(),!1})):t?($(""+rt+"
").appendTo($("#results")).show("blind",83.33),q.contains($(".search_loader_spinner").attr("class").split(" "),"active")&&$(".search_loader_spinner").removeClass("active")):Tt.search(e,!0)}}))}})}else $(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},backgroundSearch:function(e,t,a,n,s){var i=encodeURIComponent(e+" "+t),o="https://www.googleapis.com/youtube/v3/search?key="+ae+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10&videoCategoryId=10";o+="&q="+i;var l="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";t=t.split(" ");var r=e.split("-");r=r.join(" ").split(" "),$.ajax({type:"GET",url:o,dataType:"jsonp",success:function(s){if(0===s.items.length){Tt.readySubmit(!1,{totalLength:n-1}),q.log("------------------------------"),q.log("NO MATCH FOR:"),q.log("Spotify title: "+e+" "+t.join(" ")),q.log("Spotify length: "+a),q.log("------------------------------");var i=$(""+Oe+"
");i.find(".extra-add-text").text(e+" - "+t.join(" ")),i.find(".extra-add-text").attr("title",e+" - "+t.join(" ")),i.find(".extra-button-search").attr("data-text",e+" - "+t.join(" ")),$(".not-imported-container").append(i.html()),$(".not-imported").removeClass("hide")}else s.items.length>0&&($.each(s.items,function(e,t){l+=t.id.videoId+","}),$.ajax({type:"GET",url:l,dataType:"jsonp",success:function(s){if(s.items.length>0){var i=!1;if($.each(s.items,function(a,s){var o=Tt.durationToSeconds(s.contentDetails.duration),l=!1;if($.each(r,function(a,n){return-1!=s.snippet.title.toLowerCase().indexOf(n.toLowerCase())&&-1==s.snippet.title.toLowerCase().indexOf("cover")&&-1==e.toLowerCase().indexOf("cover")&&(-1==s.snippet.title.toLowerCase().indexOf("remix")&&-1==e.toLowerCase().indexOf("remix")||-1!=s.snippet.title.toLowerCase().indexOf("remix")&&-1!=e.toLowerCase().indexOf("remix")||-1!=s.snippet.title.toLowerCase().indexOf(t[0].toLowerCase())||-1!=s.snippet.channelTitle.toLowerCase().indexOf(t[0].toLowerCase())||-1!=s.snippet.channelTitle.toLowerCase().indexOf("vevo"))||(l=!0),!1}),!l)return i=!0,Tt.readySubmit(!0,{id:s.id,title:s.snippet.title,duration:o,totalLength:n-1}),!1}),!i){Tt.readySubmit(!1,{totalLength:n-1}),q.log("------------------------------"),q.log("NO MATCH FOR:"),q.log("Spotify title: "+e+" "+t.join(" ")),q.log("Spotify length: "+a),q.log("------------------------------");var o=$(""+Oe+"
");o.find(".extra-add-text").text(e+" - "+t.join(" ")),o.find(".extra-add-text").attr("title",e+" - "+t.join(" ")),o.find(".extra-button-search").attr("data-text",e+" - "+t.join(" ")),$(".not-imported-container").append(o.html()),$(".not-imported").removeClass("hide")}}}}))}})},readySubmit:function(e,t){null===Tt.submitArrayExpected&&(Tt.submitArrayExpected=t.totalLength),e?Tt.submitArray.push(t):Tt.submitArrayExpected-=1,Tt.submitArray.length-1==Tt.submitArrayExpected&&($.each(Tt.submitArray,function(e,t){Tt.submit(t.id,t.title,t.duration,!0,e,Tt.submitArray.length-1)}),document.getElementById("import_spotify").disabled=!1,$("#import_spotify").removeClass("hide"),$("#playlist_loader_spotify").addClass("hide"),Tt.submitArray=[],Tt.submitArrayExpected=null)},submitAndClose:function(e,t,a){Tt.submit(e,t,a,!1,0,1),$("#results").html(""),Tt.showSearch(),document.getElementById("search").value="",$("#results").html="",$(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},importPlaylist:function(e,t){token="";var a,n;void 0!==t&&(token="&pageToken="+t),playlist_url="https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+ae+"&playlistId="+e+token,He?(n="html",a={"Content-Type":"application/json",Authorization:"Bearer "+Ue.access_token}):(a={},n="jsonp"),$.ajax({type:"GET",url:playlist_url,dataType:n,headers:a,success:function(a){if(a.error)if("playlistItemsNotAccessible"==a.error.errors[0].reason){var n=S(29);window.callback=function(a){Ue=a,Ue.state==n?(He=!0,setTimeout(function(){He=!1,Ue={}},1e3*Ue.expires_in),Tt.importPlaylist(e,t)):(Ue="",console.error("Nonce doesn't match")),youtube_window.close(),window.callback=""},youtube_window=window.open("/o_callback#youtube=true&nonce="+n,"","width=600, height=600")}else q.log(a.error),document.getElementById("import").disabled=!1,$("#playlist_loader").addClass("hide"),$("#import").removeClass("hide"),A(),Materialize.toast("It seems you've entered a invalid url.",4e3);else{var s="";"string"==typeof a&&(a=$.parseJSON(a)),$.each(a.items,function(e,t){s+=t.contentDetails.videoId+","}),Tt.addVideos(s,!0),a.nextPageToken&&Tt.importPlaylist(e,a.nextPageToken),document.getElementById("import").value=""}}})},importSpotifyPlaylist:function(e){$.ajax({url:e,headers:{Authorization:"Bearer "+De.access_token},success:function(e){$.each(e.items,function(t,a){Tt.backgroundSearch(a.track.name,a.track.artists.map(function(e){return e.name}).join(" "),Math.floor(a.track.duration_ms/1e3),e.total,t+e.offset)}),e.next&&Tt.importSpotifyPlaylist(e.next)},error:function(){document.getElementById("import_spotify").disabled=!1,$("#import_spotify").removeClass("hide"),$("#playlist_loader_spotify").addClass("hide"),A(),Materialize.toast("It seems you've entered a invalid url.",4e3)}})},addVideos:function(e,t){var a="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id=";a+=e,$.ajax({type:"POST",url:a,dataType:"jsonp",success:function(e){var a=0,n=[];$.each(e.items,function(e,s){var i=Tt.durationToSeconds(s.contentDetails.duration);(!longsongs||i<720)&&(enc_title=s.snippet.title,a+=1,n.push({id:s.id,enc_title:enc_title,duration:i,playlist:t}))}),$.each(n,function(e,t){Tt.submit(t.id,t.enc_title,t.duration,t.playlist,e,a)})}})},submit:function(e,t,a,n,s,i){if(Ze&&document.getElementsByName("addsongs")[0].checked&&document.getElementsByName("addsongs")[0].disabled){var o=[];o=$.map(ut,function(t,a){if(t.id==e)return a}),0==o.length?J.channel_function({type:"added",value:{added:(new Date).getTime()/1e3,guids:[1],id:e,title:t,duration:a,playlist:!1,now_playing:!1,votes:1}}):J.vote(e,"pos")}else D.emit("add",{id:e,title:t,adminpass:""==re?"":Y.crypt_pass(re),list:Z.toLowerCase(),duration:a,playlist:n,num:s,total:i,pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))})},durationToSeconds:function(e){var t=e.match(se);return hours=parseInt(t[12])||0,minutes=parseInt(t[14])||0,seconds=parseInt(t[16])||0,60*hours*60+60*minutes+seconds}},It={catchUserSuggests:function(e,t){Qe+=t?1:e.length;var a=Qe>9?"9+":Qe;if($(".suggested-link span.badge.new.white").hasClass("hide")&&Qe>0&&$(".suggested-link span.badge.new.white").removeClass("hide"),$(".suggested-link span.badge.new.white").text(a),t)It.createSuggested(e);else for(var n in e)It.createSuggested(e[n]);It.checkUserEmpty()},createSuggested:function(e){var t=q.secondsToOther(e.duration),a=e.id,n=e.title,s=J.generateSong({id:a,title:n,length:e.duration,duration:t},!1,!1,!1,!0);$("#user-suggest-html").append(s)},fetchYoutubeSuggests:function(e){var t="https://www.googleapis.com/youtube/v3/search?part=snippet&relatedToVideoId="+e+"&type=video&key="+ae,a="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";$.ajax({type:"GET",url:t,dataType:"jsonp",success:function(e){$.each(e.items.slice(0,5),function(e,t){a+=t.id.videoId+","}),$.ajax({type:"GET",url:a,dataType:"jsonp",success:function(e){$("#suggest-song-html").empty(),$.each(e.items,function(e,t){var a=t.contentDetails.duration,n=Tt.durationToSeconds(a);a=q.secondsToOther(Tt.durationToSeconds(a));var s=t.id,i=t.snippet.title;$("#suggest-song-html").append(J.generateSong({id:s,title:i,length:n,duration:a},!1,!1,!1))})}})}})},checkUserEmpty:function(){0===$("#user-suggest-html").children().length?q.contains($("#user_suggests").attr("class").split(" "),"hide")||$("#user_suggests").addClass("hide"):$("#user_suggests").removeClass("hide")}}}();
\ No newline at end of file
+!function(){function e(){$("#facebook-code-link").attr("href","https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/"),$("#facebook-code-link").attr("onclick","window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/', 'Share Zoff','width=600,height=300'); return false;"),$("#twitter-code-link").attr("href","https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic"),$("#twitter-code-link").attr("onclick","window.open('https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic','Share Playlist','width=600,height=300'); return false;"),$("#qr-code-image-link").attr("src","//chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https://zoff.me/&choe=UTF-8&chld=L%7C1")}function t(){var t=new Date;R.blob_list=[],3==t.getMonth()&&1==t.getDate()&&($(".mega").css("-webkit-transform","rotate(180deg)"),$(".mega").css("-moz-transform","rotate(180deg)")),window.onpopstate=function(e){var t=window.location.href.split("/");""!==t[3]&&"#"!=t[3].substring(0,1)&&R.to_channel(t[3],!0)},N=$("#channel-list-container").clone().html(),"fb.zoff.me"!=window.location.hostname&&e(),"zoff.me"==window.location.hostname?add="https://zoff.me":add=window.location.hostname,(void 0===D||q.mobilecheck()||ye)&&(D=io.connect(add+":8080",wt),D.on("update_required",function(){window.location.reload(!0)})),(0===$("#alreadyfp").length||q.mobilecheck()||!D._callbacks.$playlists||ye)&&f(),$("#about").modal(),$("#help").modal(),$("#contact").modal(),$("select").material_select(),q.log("----"),q.log("Sending frontpage_lists"),q.log("Socket",D),q.log("-----"),Y.init(),Y.get_offline()?T(!0,Ze):$("#offline-mode").tooltip({delay:5,position:"bottom",tooltip:"Enable local mode"}),$("#frontpage-viewer-counter").tooltip({delay:5,position:"bottom",tooltip:"Total Viewers"}),D.emit("frontpage_lists",{version:parseInt(localStorage.getItem("VERSION"))}),D.emit("get_userlists",Y.getCookie("_uI")),$("#channel-load").css("display","none"),"#donation"==window.location.hash&&(window.location.hash="#",$("#donation").modal(),$("#donation").modal("open")),localStorage.ok_cookie||(A(),Materialize.toast("We're using cookies to enhance your experience! ok",1e4));var a=0;document.getElementById("zicon").addEventListener("click",function(){a+=10,document.getElementById("zicon").style.paddingLeft=a+"%",a>=100&&(window.location.href="http://etys.no")}),!q.mobilecheck()&&R.winter&&$(".mega").prepend(''),q.mobilecheck()&&$("input#searchFrontpage").characterCounter(),window.__onGCastApiAvailable=function(e,t){e&&(tt=!0)}}function a(){Qe=0;var e=!0;Z=$("#chan").html(),ct=q.mobilecheck();var t=q.mobilecheck()?"left":"right";if(window.onpopstate=function(e){P()},"fb.zoff.me"!=window.location.hostname&&M(),i="zoff.me"==window.location.hostname?"https://zoff.me":window.location.hostname,void 0!==xt&&(xt.stopInterval=!1),$("ul.playlist-tabs").tabs(),$("ul.playlist-tabs-loggedIn").tabs(),$("ul.chatTabs").tabs(),$("#settings").sideNav({menuWidth:310,edge:t,closeOnClick:!1}),$(".collapsible").collapsible({accordion:!0}),$("#help").modal(),$("#contact").modal(),$("#embed").modal(),$("#delete_song_alert").modal({dismissible:!1}),$("#user_password").modal({dismissible:!1}),I(Ve),lt=$("#temp-results-container"),rt=$("#empty-results-container").html(),Oe=$(".not-imported-container").html(),ze=$(".not-exported-container").html(),$(".not-imported-container").empty(),$(".not-exported-container").empty(),$(".video-container").resizable({start:function(e,t){$("iframe").css("pointer-events","none")},stop:function(e,t){$("iframe").css("pointer-events","auto"),Y.set_width($(this).width()),C()},handles:"e",minWidth:350,maxWidth:$(window).width()-241}),(void 0===D||q.mobilecheck())&&(e=!1,D=io.connect(i+":8080",wt),D.on("update_required",function(){window.location.reload(!0)})),Y.init(),s(),Y.get_offline()&&($(".offline_switch_class")[0].checked=!0,T(!0,Ze)),0===$("#alreadychannel").length||q.mobilecheck())l(),c(),d(),p();else{$("#channel-load").css("display","none"),$("#player").css("opacity","1"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),xt.readyLooks(),St.initYoutubeControls(xt.player),St.initSlider(),xt.player.setVolume(Y.get_volume()),$(".video-container").removeClass("no-opacity");var a="https://remote."+window.location.hostname+"/"+pt;$("#code-text").text(pt),$("#code-qr").attr("src","https://chart.googleapis.com/chart?chs=221x221&cht=qr&choe=UTF-8&chld=L|1&chl="+a),$("#code-link").attr("href",a)}if(e){var i="";oe&&(i=Y.getCookie("_uI")+"_"),D.emit("list",{version:parseInt(localStorage.getItem("VERSION")),channel:i+Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))})}$("#viewers").tooltip({delay:5,position:"top",tooltip:"Viewers"}),$("#fullscreen").tooltip({delay:5,position:"top",tooltip:"Fullscreen"}),$("#search-btn").tooltip({delay:5,position:"bottom",tooltip:"Search"}),$("#skip").tooltip({delay:5,position:"bottom",tooltip:"Skip"}),$("#shuffle").tooltip({delay:5,position:"bottom",tooltip:"Shuffle"}),$("#settings").tooltip({delay:5,position:"bottom",tooltip:"Settings"}),window.onYouTubeIframeAPIReady=xt.onYouTubeIframeAPIReady,(""===xt.player||void 0===xt.player||q.mobilecheck())&&xt.loadPlayer(),q.mobilecheck()?Ct.initiate_volume():$("input#chan_description").characterCounter(),u(),m(),h(),q.mobilecheck()||0!==$("#alreadychannel").length||y(),q.msieversion()||q.mobilecheck()||Notification.requestPermission(),$(".search_input").focus(),q.sample(),$(".castButton").tooltip({delay:5,position:"top",tooltip:"Cast Zoff to TV"}),$("#results").hover(function(){$("div.result").removeClass("hoverResults"),Te=0},function(){}),$("#search").focus(),$("#embed-button").css("display","inline-block"),$("#embed-area").val(k(Re,je,Ye,Ge)),$("#search").attr("placeholder","Find song on YouTube..."),/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())||q.mobilecheck()||$(".castButton").css("display","none"),q.log("chromecastAvailable"+Fe),q.log("chromecastAvailable"+tt),Fe?n(1):tt?initializeCastApi():window.__onGCastApiAvailable=function(e,t){e?setTimeout(function(){tt=!0,initializeCastApi()},1e3):tt=!0},$.contextMenu({selector:".playlist-element",reposition:!0,autoHide:!0,items:{copy:{name:"Copy link",callback:function(e,t){var a=$(this[0]).attr("data-video-id"),n="https://www.youtube.com/watch?v="+a;$(".copy_video_id").css("display","block"),$(".copy_video_id").text(n),document.querySelector(".copy_video_id").select(),document.execCommand("copy")?Materialize.toast("Copied!",2e3,"green lighten"):Materialize.toast("Error copying..",2e3,"red lighten"),$(".copy_video_id").css("display","none")}},similar:{name:"Find Similar",callback:function(e,t){var a=$(this[0]).attr("data-video-id");Tt.search(a,!1,!0),q.contains($(".search-container").attr("class").split(" "),"hide")&&Tt.showSearch()}},sep1:"---------",delete:{name:"Delete",callback:function(e,t){var a=$(this[0]).attr("data-video-id");if("suggested"==$(this[0]).attr("data-video-type")){(Qe-=1)<0&&(Qe=0);var n=Qe>9?"9+":Qe;$(".suggested-link span.badge.new.white").hasClass("hide")||0!=n||$(".suggested-link span.badge.new.white").addClass("hide"),$(".suggested-link span.badge.new.white").text(n)}J.vote(a,"del")},disabled:function(e,t){return X}}}}),q.mobilecheck()||null!=navigator.userAgent.match(/iPad/i)||setTimeout(function(){C()},100)}function n(e){if(1==e){$(".castButton").tooltip("remove"),$(".castButton").hasClass("castButton-white-active")||$(".castButton").addClass("castButton-white-active"),$(".castButton").tooltip({delay:5,position:"top",tooltip:"Stop casting"}),$("#duration").toggleClass("hide"),$("#fullscreen").toggleClass("hide");try{xt.player.stopVideo()}catch(e){}xt.stopInterval=!0,$("#player_overlay").removeClass("hide"),$("#player_overlay").css("display","block"),q.mobilecheck()?$("#pause").hasClass("hide")?($("#play").toggleClass("hide"),$("#pause").toggleClass("hide")):$("#play").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide")):$("#volume").slider("value",100),$("#player_overlay").css("background","url(https://i.ytimg.com/vi/"+ft+"/maxresdefault.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"),$("#playing_on").css("display","flex"),$("#chromecast_text").html("Playing on
"+U.La.friendlyName),xt.player.setVolume(100),$("#player_overlay_text").toggleClass("hide")}else 0==e&&($(".castButton").tooltip("remove"),$(".castButton").removeClass("castButton-white-active"),$(".castButton").tooltip({delay:5,position:"top",tooltip:"Cast Zoff to TV"}),$("#duration").toggleClass("hide"),$("#fullscreen").toggleClass("hide"),xt.player.playVideo(),xt.stopInterval=!1,duration=xt.player.getDuration(),xt.durationSetter(),q.mobilecheck()||(xt.player.setVolume(Y.get_volume()),$("#volume").slider("value",Y.get_volume())),$("#player_overlay").addClass("hide"),$("#player_overlay_text").toggleClass("hide"),$("#chromecast_text").html(""),$("#playing_on").css("display","none"),Ze?xt.loadVideoById(ft):D.emit("pos",{channel:Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}))}function i(e,t){var a=JSON.parse(t);switch(a.type){case-1:Ze?xt.playNext():D.emit("end",{id:a.videoId,channel:Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))});break;case 0:Ze?xt.playNext():D.emit("skip",{error:a.data_code,id:a.videoId,pass:""==re?"":Y.crypt_pass(re),channel:Z.toLowerCase(),userpass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))})}}function s(){D.on("auth_required",function(){fe=!0,$("#player_overlay").removeClass("hide"),$("#player_overlay").css("display","block"),$("#user_password").modal("open"),Y.remove_userpass(Z.toLowerCase()),A(),Materialize.toast("That is not the correct password, try again..",4e3)}),D.on("auth_accepted",function(e){e.hasOwnProperty("value")&&e.value&&""!=ge&&(Se=ge,Y.set_userpass(Z.toLowerCase(),Se))})}function o(){D.on("connect_failed",function(){q.log("Connection Failed"),qe||(qe=!0,Materialize.toast("Error connecting to server, please wait..",1e8,"red lighten connect_error"))}),D.on("connect_error",function(){q.log("Connection Failed."),qe||(qe=!0,Materialize.toast("Error connecting to server, please wait..",1e8,"red lighten connect_error"))})}function l(){D.on("np",xt.youtube_listener)}function c(){D.on("get_list",function(){var e="";oe&&(e=Y.getCookie("_uI")+"_"),D.emit("list",{version:parseInt(localStorage.getItem("VERSION")),channel:e+Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))})})}function d(){D.on("suggested",function(e){var t=!0;void 0===e.id&&(t=!1),It.catchUserSuggests(e,t)})}function p(){D.on("viewers",function(e){ue=e,$("#viewers").html("visibility "+e),void 0!==_t&&xt.getTitle(_t,ue)})}function u(){D.on("toast",O.toast),D.on("pw",O.pw),D.on("conf",O.conf)}function h(){D.on("chat.all",z.allchat),D.on("chat",z.channelchat)}function m(){D.on("channel",J.channel_function)}function f(){q.log("Setting up playlist_listener"),D.on("playlists",R.frontpage_function)}function y(){D.on("id",G.host_listener)}function v(e){D.on(e,G.host_on_action)}function _(){localStorage.debug=!0}function w(){localStorage.debug=!1}function k(e,t,a,n){return''}function C(e){if($(window).width()>760){var t=$(".brand-logo").outerWidth();e&&(t=.15*$(window).width());var a=$(window).width()-$(".control-list").width()-t-66;title_width=a,$(".title-container").width(title_width)}else $(".title-container").width("100%")}function S(e){for(var t="",a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_",n=0;n"+ee+""),ee=ee.html()),$("#viewers").addClass("hide"),$("#offline-mode").removeClass("waves-cyan"),$("#offline-mode").addClass("cyan"),$("#offline-mode").tooltip({delay:5,position:"bottom",tooltip:"Disable local mode"}),"/"!=window.location.pathname?($("#controls").on("mouseenter",function(e){$("#seekToDuration").hasClass("hide")&&$("#seekToDuration").removeClass("hide")}),$("#controls").on("mouseleave",function(e){me=!1,$("#seekToDuration").hasClass("hide")||$("#seekToDuration").addClass("hide")}),$("#controls").on("mousedown",function(e){["bar","controls","duration"].indexOf($(e.target).attr("id"))>=0&&(me=!0)}),$("#controls").on("mouseup",function(e){me=!1}),$("#controls").on("mousemove",E),$("#controls").on("click",L),$("#main_components").append("
00:00/01:00
"),q.mobilecheck()?q.mobilecheck()&&$("#seekToDuration").css("top",$("#controls").position().top-20):$("#seekToDuration").css("top",$("#controls").position().top-55),$("#controls").hasClass("ewresize")||$("#controls").addClass("ewresize")):($("#controls").off("mouseenter"),$("#controls").off("mouseleave"),$("#controls").off("mousemove"),$("#controls").off("click")),void 0!=ut&&!t){for(var a=0;a
"+ee+" "),ee=ee.html()),$("#viewers").removeClass("hide"),$("#offline-mode").addClass("waves-cyan"),$("#offline-mode").removeClass("cyan"),$("#offline-mode").tooltip({delay:5,position:"bottom",tooltip:"Enable local mode"}),$("#controls").off("mouseleave"),$("#controls").off("mouseenter"),$("#controls").off("mousedown"),$("#controls").off("mouseup"),$("#controls").off("mousemove",E),$("#controls").off("click",L),$("#seekToDuration").remove(),"/"!=window.location.pathname){D.emit("pos",{channel:Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))});var n="";oe&&(n=Y.getCookie("_uI")+"_"),D.emit("list",{version:parseInt(localStorage.getItem("VERSION")),channel:n+Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}),$("#controls").hasClass("ewresize")&&$("#controls").removeClass("ewresize")}}function I(e){e?(q.log("------------------------"),q.log("Spotify is authenticated"),q.log("access_token: "+De.access_token),q.log("token_type:"+De.token_type),q.log("expires_in: "+De.expires_in),q.log("------------------------"),$(".spotify_authenticated").css("display","block"),$(".spotify_unauthenticated").css("display","none")):(q.log("----------------------------"),q.log("Spotify is not authenticated"),q.log("----------------------------"),$(".spotify_authenticated").css("display","none"),$(".spotify_unauthenticated").css("display","block"))}function E(e){var t=e.clientX-Math.ceil($("#seekToDuration").width()/2)-8;t<0?t=0:t+$("#seekToDuration").width()>$("#controls").width()&&(t=$("#controls").width()-$("#seekToDuration").width()),$("#seekToDuration").css("left",t);try{var a=ut[ut.length-1].duration/$("#controls").width();a*=e.clientX;var n=q.secondsToOther(a),i=q.pad(n[0]),s=q.pad(Math.ceil(n[1]));$("#seekToDuration").text(i+":"+s);["bar","controls","duration"].indexOf($(e.target).attr("id"))>=0&&me&&$("#bar").width(100/xt.player.getDuration()*a+"%")}catch(e){}}function L(e){if(["bar","controls","duration"].indexOf($(e.target).attr("id"))>=0){var t=ut[ut.length-1].duration/$("#controls").width();t*=e.clientX,q.log(t),Fe?U.sendMessage("urn:x-cast:zoff.me",{type:"seekTo",seekTo:t}):(xt.player.seekTo(t),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=t,currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=q.pad(minutes)+":"+q.pad(seconds)+" ").parent().html()),$(".page-footer").removeClass("padding-bottom-extra"),$(".page-footer").removeClass("padding-bottom-novideo"),$("#favicon").attr("href","/assets/images/favicon.png"),$(".context-menu-list").remove(),q.log(D),1==$("#alreadyfp").length?t():(kt=!0,j=!0,t()),0!==$("#alreadychannel").length||ye?ye&&$("#alreadychannel").remove():$("head").append("
"),void 0!=e.description&&""!=e.description&&$("#description_area").html(e.description)},submitAdmin:function(e,t){voting=e.vote.checked,addsongs=e.addsongs.checked,longsongs=e.longsongs.checked,j=e.frontpage.checked,allvideos=e.allvideos.checked,removeplay=e.removeplay.checked,skipping=e.skip.checked,shuffling=e.shuffle.checked;var a=""==Se?Se:CryptoJS.SHA256(Se).toString();configs={channel:Z.toLowerCase(),voting:voting,addsongs:addsongs,longsongs:longsongs,frontpage:j,allvideos:allvideos,removeplay:removeplay,adminpass:""==re?"":Y.crypt_pass(re),skipping:skipping,shuffling:shuffling,userpass:Y.crypt_pass(a),userpass_changed:t},Y.set_userpass(Z.toLowerCase(),CryptoJS.SHA256(Se).toString()),D.emit("conf",configs)},hide_settings:function(){$("#settings").sideNav("hide")},shuffle:function(){if(Ze){for(var e=0;e
to change name","/removename to remove name"],namechange:function(e){D.emit("namechange",e),Y.set_name(e)},removename:function(){D.emit("removename"),Y.remove_name()},chat:function(e){if(!(e.value.length>150)){if(e.value.startsWith("/name "))z.namechange(e.value.substring(6));else if(e.value.startsWith("/help"))if("#all_chat"==$(".chat-tab-li a.active").attr("href")){$("#chatall").children().length>100&&$("#chatall").children()[0].remove();for(var t=0;tSystem: ");var i=document.createTextNode(z.chat_help[t]);$("#chatall li:last")[0].appendChild(i),document.getElementById("chatall").scrollTop=document.getElementById("chatall").scrollHeight}}else{$("#chatchannel").children().length>100&&$("#chatchannel").children()[0].remove();for(var t=0;tSystem: ");var i=document.createTextNode(z.chat_help[t]);$("#chatchannel li:last")[0].appendChild(i),document.getElementById("chatchannel").scrollTop=document.getElementById("chatchannel").scrollHeight}}else e.value.startsWith("/removename")?z.removename():"#all_chat"==$(".chat-tab-li a.active").attr("href")?D.emit("all,chat",{channel:Z.toLowerCase(),data:e.value}):D.emit("chat",{channel:Z.toLowerCase(),data:e.value,pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))});e.value=""}},allchat:function(e){if(":"==e.msg.substring(0,1)&&!Me){z.all_received+=1,$("#favicon").attr("href","/assets/images/highlogo.png"),te=!0,Ae=!0,$(".chat-link span.badge.new.white").hasClass("hide")&&$(".chat-link span.badge.new.white").removeClass("hide");var t=z.channel_received+z.all_received>9?"9+":z.channel_received+z.all_received;$(".chat-link span.badge.new.white").html(t)}document.hidden&&$("#favicon").attr("href","/assets/images/highlogo.png"),$("#chatall").children().length>100&&$("#chatall").children()[0].remove();var a=q.intToARGB(q.hashCode(e.from));if(a.length<6)for(x=a.length;x<6;x++)a="0"+a;a=q.hexToRgb(a.substring(0,6));var n=q.rgbToHsl([a.r,a.g,a.b],!1);$("#chatall").append(""+e.from+"");var i=document.createTextNode(e.msg);$("#chatall li:last")[0].appendChild(i),document.getElementById("chatall").scrollTop=document.getElementById("chatall").scrollHeight},channelchat:function(e){if(":"==e.msg.substring(0,1)&&!Me){$("#favicon").attr("href","/assets/images/highlogo.png"),te=!0,Ae=!0,z.channel_received+=1,$(".chat-link span.badge.new.white").hasClass("hide")&&$(".chat-link span.badge.new.white").removeClass("hide");var t=z.channel_received+z.all_received>9?"9+":z.channel_received+z.all_received;$(".chat-link span.badge.new.white").html(t)}$("#chatchannel").children().length>100&&$("#chatchannel").children()[0].remove();var a=q.intToARGB(q.hashCode(e.from));if(a.length<6)for(x=a.length;x<6;x++)a="0"+a;a=q.hexToRgb(a.substring(0,6));var n=q.rgbToHsl([a.r,a.g,a.b],!1);$("#chatchannel").append(""+e.from+"");var i=document.createTextNode(e.msg);$("#chatchannel li:last")[0].appendChild(i),document.getElementById("chatchannel").scrollTop=document.getElementById("chatchannel").scrollHeight},chat_blink:function(){Pe=!0,$(".chat-link").attr("style","color: grey !important;"),setTimeout(function(){$(".chat-link").attr("style","color: white !important;"),setTimeout(function(){Pe&&z.chat_blink()},1e3)},1e3)}},Y={conf_pass:void 0,user_pass:void 0,tmp_pass:"",init:function(){"/"!=window.location.pathname&&("https:"!=location.protocol?document.cookie=Z.toLowerCase()+"=;path=/"+Z.toLowerCase()+";expires="+new Date(0).toUTCString():document.cookie=Z.toLowerCase()+"=;path=/"+Z.toLowerCase()+";secure;expires="+new Date(0).toUTCString());try{conf_arr=Y.decrypt(Y.getCookie("_opt"),"_opt")}catch(e){conf_arr=Y.decrypt(Y.create_cookie("_opt"),"_opt")}if("/"!=window.location.pathname){try{Y.conf_pass=Y.decrypt(Y.getCookie(Z.toLowerCase()),Z.toLowerCase())}catch(e){Y.conf_pass=Y.decrypt(Y.create_cookie(Z.toLowerCase()),Z.toLowerCase())}G.change_enabled(conf_arr.remote),100!=conf_arr.width&&xt.set_width(conf_arr.width),void 0!==conf_arr.name&&""!==conf_arr.name&&z.namechange(conf_arr.name)}},decrypt:function(e,t){void 0===Y.getCookie(t)&&(e=Y.create_cookie(t));var a=btoa("0103060703080703080701")+btoa("0103060703080703080701");a=a.substring(0,32),a=btoa(a);var n=CryptoJS.AES.decrypt(e,a,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});return $.parseJSON(n.toString(CryptoJS.enc.Utf8))},decrypt_pass:function(e){var t=btoa(D.id)+btoa(D.id);return t=t.substring(0,32),t=btoa(t),CryptoJS.AES.decrypt(e,t,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8)},encrypt:function(e,t){var a=JSON.stringify(e),n=btoa("0103060703080703080701")+btoa("0103060703080703080701");n=n.substring(0,32),n=btoa(n);var i=CryptoJS.AES.encrypt(a,n,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7}),s=new Date;s.setFullYear(s.getFullYear()+1),"https:"!=location.protocol?document.cookie=t+"="+i.toString()+";expires="+s.toGMTString()+";path=/;":document.cookie=t+"="+i.toString()+";secure;expires="+s.toGMTString()+";path=/;"},get_volume:function(){return Y.decrypt(Y.getCookie("_opt"),"_opt").volume},get_offline:function(){return void 0!=Y.decrypt(Y.getCookie("_opt"),"_opt").offline?Y.decrypt(Y.getCookie("_opt"),"_opt").offline:(Y.set_offline(!1),!1)},set_volume:function(e){conf_arr.volume=e,Y.encrypt(conf_arr,"_opt")},create_cookie:function(e){cookie_object="_opt"==e?{volume:100,width:100,remote:!0,name:"",offline:!1}:{passwords:{}};var t=JSON.stringify(cookie_object),a=btoa("0103060703080703080701")+btoa("0103060703080703080701");a=a.substring(0,32),a=btoa(a);var n=CryptoJS.AES.encrypt(t,a,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7}),i=new Date;return i.setFullYear(i.getFullYear()+1),"https:"!=location.protocol?document.cookie=e+"="+n.toString()+";expires="+i.toGMTString()+";path=/;":document.cookie=e+"="+n.toString()+";secure;expires="+i.toGMTString()+";path=/;",Y.getCookie(e)},set_pass:function(e,t){Y.conf_pass.passwords[e]=t,Y.encrypt(Y.conf_pass,e)},remove_pass:function(e){delete Y.conf_pass.passwords[e],Y.encrypt(Y.conf_pass,e.toLowerCase())},set_userpass:function(e,t){Y.conf_pass.passwords.userpass=t,Y.encrypt(Y.conf_pass,e)},remove_userpass:function(e){delete Y.conf_pass.passwords.userpass,Y.encrypt(Y.conf_pass,e.toLowerCase())},set_name:function(e){conf_arr.name=encodeURIComponent(e).replace(/\W/g,""),Y.encrypt(conf_arr,"_opt")},set_offline:function(e){conf_arr.offline=e,Y.encrypt(conf_arr,"_opt")},remove_name:function(){conf_arr.name="",Y.encrypt(conf_arr,"_opt")},get_pass:function(e){if(void 0!==Y.conf_pass)return Y.conf_pass.passwords[e]},get_userpass:function(e){return void 0!==Y.conf_pass?Y.conf_pass.passwords.userpass:""},set_remote:function(e){conf_arr.remote=e,Y.encrypt(conf_arr,"_opt")},get_remote:function(e){return conf_arr.remote},crypt_pass:function(e){Y.tmp_pass=e;var t=btoa(D.id)+btoa(D.id);t=t.substring(0,32),t=btoa(t);var a=btoa(Y.makeiv()),n=CryptoJS.AES.encrypt(e,CryptoJS.enc.Base64.parse(t),{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7,iv:CryptoJS.enc.Base64.parse(a)});return window.encrypted=n,n.toString()+"$"+a},makeiv:function(){for(var e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",a=0;a<16;a++)e+=t.charAt(Math.floor(Math.random()*t.length));return e},get_width:function(){return conf_arr.width},set_width:function(e){conf_arr.width=e,Y.encrypt(conf_arr,"_opt")},getCookie:function(e){var t="; "+document.cookie,a=t.split("; "+e+"=");if(2==a.length)return a.pop().split(";").shift()}},j=!0,R={blob_list:[],winter:(new Date).getMonth()>=10,times_rotated:0,all_channels:[],frontpage_function:function(e){j=!0,q.log("-----------"),q.log("Frontpage fetch"),q.log(e),q.log("------------"),R.all_channels=e.channels,R.populate_channels(e.channels,!0),R.set_viewers(e.viewers)},populate_channels:function(e,t){$("#channels").empty();for(var a,n=0,i=0;in?-1:is?-1:0},sortFunction_active:function(e,t){var a=e.accessed,n=t.accessed,i=e.count,s=t.count;return an?-1:is?-1:0},getCookie:function(e){for(var t=e+"=",a=document.cookie.split(";"),n=0;n=e.length||t>=20)&&(t=0);var a=e[t].id;if(void 0!==R.blob_list[t])setTimeout(function(){j&&($("#mega-background").css("background","url(data:image/png;base64,"+R.blob_list[t]+")"),$("#mega-background").css("background-size","200%"),$("#mega-background").css("opacity",1),$(".desktop-search").attr("placeholder",e[t].channel))},500);else{var n=new Image;n.src="/assets/images/thumbnails/"+a+".jpg",n.onerror=function(){$.ajax({type:"POST",data:{id:a},url:"/api/imageblob",success:function(a){setTimeout(function(){$("#mega-background").css("background","url(/assets/images/thumbnails/"+a+")"),$("#mega-background").css("background-size","200%"),$("#mega-background").css("opacity",1),$(".desktop-search").attr("placeholder",e[t].channel)},500)}})},n.onload=function(){$("#mega-background").css("background","url("+n.src+")"),$("#mega-background").css("background-size","200%"),$("#mega-background").css("opacity",1),$(".desktop-search").attr("placeholder",e[t].channel)}}V=setTimeout(function(){50==R.times_rotated&&j?(R.times_rotated=0,t=0,D.emit("frontpage_lists",{version:parseInt(localStorage.getItem("VERSION"))}),D.emit("get_userlists",Y.getCookie("_uI"))):j&&(R.times_rotated+=1,R.add_backdrop(e,t+1))},6e3)},start_snowfall:function(){setTimeout(function(){var e=Math.floor(Math.random()*window.innerWidth+1),t=document.createElement("div"),a=document.getElementsByClassName("mega")[0];t.className="snow",t.style.left=e+"px",t.style.top="0px",a.appendChild(t),R.fall_snow(t),R.start_snowfall()},800)},fall_snow:function(e){e.style.top=parseInt(e.style.top.replace("px",""))+2+"px",parseInt(e.style.top.replace("px",""))visibility"+e)},to_channel:function(e,t){$("#channel-load").css("display","block"),window.scrollTo(0,0),j=!1,e=e.toLowerCase(),clearTimeout(V),q.mobilecheck()&&(q.log("removing all listeners"),D.removeAllListeners()),$("#main-container").css("background-color","#2d2d2d"),$("#frontpage-viewer-counter").tooltip("remove"),$("#offline-mode").tooltip("remove"),$e=1,$.ajax({url:"/"+e,method:"get",data:{channel:e},success:function(n){""!==xt.player&&D.emit("change_channel",{channel:Z.toLowerCase()}),$("#frontpage_player").empty(),q.mobilecheck()&&(q.log("disconnecting"),D.disconnect()),t||(window.history.pushState("to the channel!","Title","/"+e),""==Ke&&(Ke=e),""==et&&(et=e),window.chan=e);var i=$(""+n+"
");$("select").material_select("destroy"),$(".mega").remove(),$(".mobile-search").remove(),$("main").attr("class","container center-align main"),$("#main-container").addClass("channelpage"),$("header").html($(i.find("header")).html()),0===$("#alreadychannel").length||q.mobilecheck()||void 0===xt.player?$("main").html($(i.find("main")).html()):($("#main-row").append($(i.find("#playlist").wrap("").parent().html())),$("#video-container").append($(i.find("#main_components").wrap("
").parent().html())),$("#main-row").append("
"),$("#player").removeClass("player_bottom"),$("#main-row").removeClass("frontpage_modified_heights"),$("#main_section_frontpage").remove(),$("#closePlayer").remove(),$("#player_bottom_overlay").remove()),$("#search").attr("placeholder","Find song on YouTube..."),$(".page-footer").addClass("padding-bottom-novideo"),Ne=!0,1==$("#alreadychannel").length?a():(bt=!0,a()),0===$("#alreadyfp").length&&$("head").append("
")}})}};String.prototype.capitalizeFirstLetter=function(){return this.charAt(0).toUpperCase()+this.slice(1)};var q={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,s=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},hslToRgb:function(e,t,a){function n(e,t,a){return a<0&&(a+=1),a>1&&(a-=1),a<1/6?e+6*(t-e)*a:a<.5?t:a<2/3?e+(t-e)*(2/3-a)*6:e}var i,s,o;if(0==t)i=s=o=a;else{var l=a<.5?a*(1+t):a+t-a*t,r=2*a-l;i=n(r,l,e+1/3),s=n(r,l,e),o=n(r,l,e-1/3)}return[255*i,255*s,255*o]},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()-ke>=2*be&&(D.removeAllListeners(),D.disconnect(),D.connect(),xt.setup_all_listeners()),ke=Date.now(),setTimeout(q.sample,be)},loadjsfile:function(e){if(-1==de.indexOf("["+e+"]")){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),de+="["+e+"]"}},msieversion:function(){return!!(window.navigator.userAgent.indexOf("MSIE ")>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),s=Math.min(r,g,b),o=(i+s)/2;if(i==s)a=n=0;else{var l=i-s;switch(n=o>.5?l/(2-i-s):l/(i+s),i){case r:a=(g-b)/l+(g.5&&t?o=.4:o<.65&&!t&&(o=.65),"hsl("+Math.floor(360*a)+", "+Math.floor(100*n)+"%, "+Math.floor(100*o)+"%)"},componentToHex:function(e){var t=e.toString(16);return 1==t.length?"0"+t:t},rgbToHex:function(e,t,a){return"#"+q.componentToHex(e)+q.componentToHex(t)+q.componentToHex(a)},upperFirst:function(e){return e.substring(0,1).toUpperCase()+e.substring(1).toLowerCase()},addClass:function(e,t){q.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"))}}))},firstY:null,lastY:null,currentY:null,vertScroll:!1,initAdjustment:0,touchstart:function(e){q.lastY=q.currentY=q.firstY=e.originalEvent.touches[0].pageY},touchmove:function(e){q.currentY=e.originalEvent.touches[0].pageY;var t=q.lastY-q.currentY;!q.vertScroll&&Math.abs(q.currentY-q.firstY)>30&&(q.vertScroll=!0,q.initAdjustment=q.currentY-q.firstY),q.vertScroll&&(window.scrollBy(0,t+q.initAdjustment),q.lastY=q.currentY+t)},touchend:function(e){q.vertScroll=!1,q.firstY=null,q.currentY=null,q.vertScroll=!1,q.initAdjustment=0,q.currentY=null},invertColor:function(e){if(0===e.indexOf("#")&&(e=e.slice(1)),3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)throw new Error("Invalid HEX color.");var t=(255-parseInt(e.slice(0,2),16)).toString(16),a=(255-parseInt(e.slice(2,4),16)).toString(16),n=(255-parseInt(e.slice(4,6),16)).toString(16);return"#"+padZero(t)+padZero(a)+padZero(n)},padZero:function(e,t){return t=t||2,(new Array(t).join("0")+e).slice(-t)}};Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;e0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id})):(Ke=Z,J.populate_list(e.playlist),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}));break;case"added":J.added_song(e.value),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}),nt=[],it=0;break;case"deleted":J.deleted_song(e.value,e.removed),nt=[],it=0;break;case"vote":Ze||(J.voted_song(e.value,e.time),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id})),nt=[],it=0;break;case"song_change":"/"!=window.location.pathname&&J.song_change(e.time,e.remove),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}),nt=[],it=0}},insertAtBeginning:function(e,t){var a=0==J.page?"":"none",n=J.generateSong(e,t,!1,!0,!1,a,!1);$("#wrapper").append(n)},insertAtIndex:function(e,t,a){var n=J.getIndexOfSong(e.id),i="none";if(!e.now_playing){n>=J.page&&n div:nth-child("+n+")").after(s);var o=$("#wrapper").children()[n];$(o).css("display",i),"inline-block"==i&&$("#wrapper").children().length>=J.page+J.can_fit+1?$($("#wrapper").children()[J.page+J.can_fit]).css("display","none"):n=0?$($("#wrapper").children()[J.page]).css("display","inline-block"):$("#wrapper").children().length>J.page+J.can_fit&&$($("#wrapper").children()[J.page+J.can_fit-1]).css("display","inline-block"),a&&J.page>0&&$($("#wrapper").children()[J.page-1]).css("display","none"),t&&setTimeout(function(){$(o).css("transform","translateX(0%)"),setTimeout(function(){$(o).removeClass("side_away")},300)},5)}},populate_list:function(e,t){if(q.mobilecheck()||Ee?Ee?(J.can_fit=Math.round($("#wrapper").height()/91)+1,J.element_height=$("#wrapper").height()/J.can_fit-4):(J.can_fit=Math.round(($(window).height()-$(".tabs").height()-$("header").height()-64-8)/71)+1,J.element_height=($(window).height()-$(".tabs").height()-$("header").height()-64-8)/J.can_fit-5):(J.can_fit=Math.round($("#wrapper").height()/71)+1,J.element_height=$("#wrapper").height()/J.can_fit-5.3),J.element_height<55.2&&(J.can_fit=J.can_fit-1,J.element_height=55.2,J.can_fit=Math.round(($(window).height()-$(".tabs").height()-$("header").height()-64-8)/71),J.element_height=($(window).height()-$(".tabs").height()-$("header").height()-64-8)/J.can_fit-5),void 0===ee&&(ee=$("#list-song-html").html()),ut=e,Ze&&!t)for(var a=0;a1?($.each(ut,function(e,t){if(!t.now_playing){var a=J.generateSong(t,!1,Ie,!0,!1,"",!0);$("#wrapper").append(a)}}),$("#wrapper").children().length>J.can_fit&&!$("#pageButtons").length?($('').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||($('').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")),J.dynamicContentPage(-10)):(J.empty=!0,$("#wrapper").html("The playlist is empty."),$("#pageButtons").length||$('').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*=J.can_fit)>J.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")),J.page+J.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(J.page/J.can_fit+1))},dynamicContentPage:function(e){1==e?($("#wrapper").children().slice(J.page,J.page+J.can_fit).hide(),J.page=J.page+J.can_fit,$("#wrapper").children().slice(J.page,J.page+J.can_fit).css("display","inline-block"),J.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")),J.page+J.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(J.page,J.page+J.can_fit).hide(),J.page=Math.floor(($("#wrapper").children().length-1)/J.can_fit)*J.can_fit,$("#wrapper").children().slice(J.page,J.page+J.can_fit).css("display","inline-block"),J.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")),J.page+J.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(J.page,J.page+J.can_fit).hide(),J.page=0,$("#wrapper").children().slice(J.page,J.page+J.can_fit).css("display","inline-block"),0==J.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")),J.page+J.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(J.page-J.can_fit,J.page).css("display","inline-block"),$("#wrapper").children().slice(J.page,J.page+J.can_fit).hide(),J.page=J.page-J.can_fit<0?0:J.page-J.can_fit,0==J.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")),J.page+J.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(J.page/J.can_fit+1)},added_song:function(e){var t;if(void 0!=e){if(0!==ut.length&&(t=ut.pop()),ut.push(e),J.sortList(),t&&ut.push(t),$("#suggested-"+e.id).length>0){Qe-=1,Qe<0&&(Qe=0);var a=Qe>9?"9+":Qe;$(".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(),J.empty&&(J.empty=!1),$("#empty-channel-message").remove(),J.insertAtIndex(e,!0),$($("#wrapper").children()[J.page+J.can_fit]).css("display","none"),$("#wrapper").children().length>J.page+J.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=J.getIndexOfSong(e);$("#wrapper").children()[a];a=0?($($("#wrapper").children()[J.page]).css("height",0),$($("#wrapper").children()[J.page]).css("display","inline-block"),$($("#wrapper").children()[J.page]).css("height",J.element_height)):$("#wrapper").children().length>J.page+J.can_fit&&($($("#wrapper").children()[J.page+J.can_fit]).css("height",0),$($("#wrapper").children()[J.page+J.can_fit]).css("display","inline-block"),$($("#wrapper").children()[J.page+J.can_fit]).css("height",J.element_height)),J.page>=$("#wrapper").children().length-1?(J.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")):J.page+J.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")),J.page<=a&&J.page-J.can_fit<=a?($("#"+e).addClass("side_away"),$("#"+e).find(".mobile-delete").remove(),$("#"+e).css("transform","translateX(-100%)"),setTimeout(function(){$("#"+e).remove()},300)):$("#"+e).remove(),ut.splice(J.getIndexOfSong(e),1),xt.sendNext({title:ut[0].title,videoId:ut[0].id})}catch(t){ut.splice(J.getIndexOfSong(e),1),J.empty||($("#"+e).remove(),a=0?$($("#wrapper").children()[J.page-1]).css("display","inline-block"):$("#wrapper").children().length>J.page+J.can_fit&&$($("#wrapper").children()[J.page+(J.can_fit-1)]).css("display","inline-block"),xt.sendNext({title:ut[0].title,videoId:ut[0].id}))}ut.length<=2&&(J.empty=!0,$("#wrapper").html("The playlist is empty.")),$("#suggested-"+e).remove(),J.page,J.can_fit,$("#wrapper").children().length,J.page>=$("#wrapper").children().length&&J.dynamicContentPage(-1),It.checkUserEmpty()},voted_song:function(e,t){var a=J.getIndexOfSong(e),n=ut[a];ut[a].votes+=1,ut[a].added=t,J.sortList(),$("#"+e).remove(),J.insertAtIndex(n,!1)},song_change:function(e,t){try{var a=ut.length-1;$("#wrapper").children()[0].remove(),ut.length<=1&&(J.empty=!0,$("#wrapper").html("The playlist is empty.")),ut[0].now_playing=!0,ut[0].votes=0,ut[0].guids=[],ut[0].added=e,t?delete ut[a]:ut[a].now_playing=!1,q.log("---------------------------"),q.log("---SONG ON FIRST INDEX-----"),q.log(ut[0]),q.log("---------------------------"),ut.push(ut.shift()),t||J.insertAtIndex(ut[$("#wrapper").children().length],!1,!0)}catch(e){}},vote:function(e,t){return!Ze||"del"==t&&Q&&!X&&""!=re?D.emit("vote",{channel:Z,id:e,type:t,adminpass:""==re?"":Y.crypt_pass(re),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}):"pos"==t?J.voted_song(e,(new Date).getTime()/1e3):J.deleted_song(e),!0},skip:function(){return Ze?xt.playNext():D.emit("skip",{pass:""==re?"":Y.crypt_pass(re),id:ft,channel:Z.toLowerCase(),userpass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}),!0},exportToSpotify:function(){$.ajax({type:"GET",url:"https://api.spotify.com/v1/me",headers:{Authorization:"Bearer "+De.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 "+De.access_token,"Content-Type":"application/json"},data:JSON.stringify({name:Z.toLowerCase()+" - Zoff",public:!0}),success:function(e){var a=e.id;$.each(ut,function(e,n){J.searchSpotify(n,a,t)})}})}})},searchSpotify:function(e,t,a){var n=e.title,i=e.title.toLowerCase().replace("-"," ");i.startsWith("the")&&(i=i.replace("the","")),i=i.replace(" hd",""),i=i.replace("official hd video",""),i=i.replace("unofficial video",""),i=i.replace("studio footage",""),i=i.replace("great song",""),i=i.replace("-"," "),i=i.replace("-"," "),i=i.replace(" hq"," "),i=i.replace("lyric video",""),i=i.replace("lyrics video",""),i=i.replace("album version",""),i=i.replace("drive original movie soundtrack",""),i=i.replace("original movie soundtrack",""),i=i.replace("live sessions",""),i=i.replace("audio only",""),i=i.replace("audio",""),i=i.replace("(new)",""),i=i.replace(" by "," "),i=i.replace(" vs "," "),i=i.replace("(full)"," "),i=i.replace("(video)"," "),i=i.replace("&"," "),i=i.replace("with lyrics",""),i=i.replace("lyrics",""),i=i.replace("w/",""),i=i.replace("w/",""),i=i.replace("official video",""),i=i.replace("studio version",""),i=i.replace("official music video",""),i=i.replace("music video",""),i=i.replace("musicvideo",""),i=i.replace("original video",""),i=i.replace("full version",""),i=i.replace("full song",""),i=i.replace("(official)",""),i=i.replace("official",""),i=i.replace("(original)",""),i=i.replace("("," "),i=i.replace(")"," "),i=i.replace("|",""),i=i.replace("feat."," "),i=i.replace("feat"," "),i=i.replace("ft."," "),i=i.replace("["," "),i=i.replace("]"," "),i=i.replace(" free ",""),i=i.replace(" hd",""),i=i.replace("original mix"," "),i=i.replace("radio edit"," "),i=i.replace("pop version"," "),i=i.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," "),i=encodeURIComponent(i),$.ajax({type:"GET",url:"https://api.spotify.com/v1/search?q="+i+"&type=track",headers:{Authorization:"Bearer "+De.access_token},async:!0,statusCode:{429:function(n){console.log(n.getAllResponseHeaders());var i=n.getResponseHeader("Retry-After");console.log(i),i||(i=5),i=parseInt(i,10),q.log("Retry-After",i),setTimeout(function(){J.searchSpotify(e,t,a)},1e3*i)}},error:function(n){if(429==n.status){console.log(n.getAllResponseHeaders());var i=n.getResponseHeader("Retry-After");console.log(i),i||(i=5),i=parseInt(i,10),q.log("Retry-After",i),setTimeout(function(){J.searchSpotify(e,t,a)},1e3*i)}},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)&&"."!=i.substring(i.length-1)&&(t.name=t.name.substring(0,t.name.length-1)),decodeURIComponent(i).indexOf(t.artists[0].name.toLowerCase())>=0&&decodeURIComponent(i).indexOf(t.name.toLowerCase())>=0)return s=!0,J.uris.push(t.uri),q.log("Found",i),!1;for(var a=t.name.split(" "),e=0;e=0||"&"==a[e]&&i.indexOf("and")>=0)&&i.indexOf(a[e])<0)return!0;return s=!0,J.uris.push(t.uri),q.log("Found",i),!1}),s||(J.not_found.push(n),J.num_songs=J.num_songs+1,q.log("Didn't find",n)),J.num_songs+J.uris.length==ut.length){if(J.uris.length>100){for(;J.uris.length>100;)J.addToSpotifyPlaylist(J.uris.slice(0,100),t,a),J.uris=J.uris.slice(100,J.uris.length);J.addToSpotifyPlaylist(J.uris,t,a),$("#playlist_loader_export").addClass("hide")}else J.addToSpotifyPlaylist(J.uris,t,a),$("#playlist_loader_export").addClass("hide");0==$(".exported-spotify-list").length&&$(".exported-list").append(""+Z+""),$.each(J.not_found,function(e,t){var a=$(""+ze+"
");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 "+De.access_token,"Content-Type":"application/json"},data:JSON.stringify({uris:e}),error:function(n){var i=t,s=e,o=a;setTimeout(function(){J.addToSpotifyPlaylist(s,i,o)},3e3)},success:function(e){q.log("Added songs")}})},exportToYoutube:function(){$(".exported-list-container").removeClass("hide"),$("#playlist_loader_export").removeClass("hide"),$.ajax({type:"POST",url:"https://www.googleapis.com/youtube/v3/playlists?part=snippet",headers:{Authorization:"Bearer "+Ue.access_token,"Content-Type":"application/json"},data:JSON.stringify({snippet:{title:q.upperFirst(Z.toLowerCase()),description:"Playlist exported from zoff"}}),success:function(e){var t=e.id;J.addToYoutubePlaylist(t,ut,0,"https://www.googleapis.com/youtube/v3/playlistItems?part=snippet")},error:function(e){q.log(e)}})},addToYoutubePlaylist:function(e,t,a,n){var i=JSON.stringify({snippet:{playlistId:e,resourceId:{kind:"youtube#video",videoId:t[a].id}}});$.ajax({type:"POST",url:n,headers:{Authorization:"Bearer "+Ue.access_token,"Content-Type":"application/json"},data:i,success:function(i){q.log("Added video: "+t[a].id+" to playlist id "+e),a==t.length-1?(q.log("All videoes added!"),q.log("url: https://www.youtube.com/playlist?list="+e),$(".exported-list").append(""+Z+""),$("#playlist_loader_export").addClass("hide"),$(".current_number").addClass("hide")):($(".current_number").removeClass("hide"),$(".current_number").text(a+1+" of "+t.length),J.addToYoutubePlaylist(e,t,a+1,n))}})},importOldList:function(e){var t="",a=0;playlist_url="lists/"+e+".json",yt=$.parseJSON($.ajax({type:"GET",url:playlist_url,async:!1}).responseText),$.each(yt.songs,function(e,n){t+=n.id+",",a>45&&(Tt.addVideos(t),t="",a=0),a++}),Tt.addVideos(t),document.getElementById("search").value=""},sortList:function(){ut.sort(q.predicate({name:"votes",reverse:!0},{name:"added",reverse:!1},{name:"title",reverse:!1}))},show:function(){q.mobilecheck()||(K?(K=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.me/"+Z.toLowerCase())):(K=!0,$("#toptitle").html("Zoff"),$("#chan").removeClass("bigChan"),$("#chan").html(Z)))},generateSong:function(e,t,a,n,i,s,o){void 0===ee&&(ee=$("#list-song-html").html());var l,r,c=e.id,d=e.title,p=e.votes,u="background-image:url('//img.youtube.com/vi/"+c+"/mqdefault.jpg');",g=$(""+ee+"
"),h="style";if(t&&(g.find(".list-song").css("transform","translateX(100%)"),g.find(".list-song").addClass("side_away")),g.find(".list-song").css("height",J.element_height),X||g.find(".card-action").removeClass("hide"),1==p&&g.find(".vote-text").text("vote"),a&&(u="//img.youtube.com/vi/"+c+"/mqdefault.jpg",h="data-original"),n){g.find(".list-votes").text(p),g.find("#list-song").attr("data-video-id",c),g.find("#list-song").attr("data-video-type","song"),g.find("#list-song").attr("id",c),g.find(".vote-container").attr("title",d),($("#wrapper").children().length>=J.can_fit&&o||"none"==s)&&g.find(".card").css("display","none"),l=".vote-container",r="delete_button";var m=q.secondsToOther(e.duration);g.find(".card-duration").text(q.pad(m[0])+":"+q.pad(m[1]))}else if(!n){g.find(".suggested_remove").removeClass("hide"),g.find(".vote-text").text(""),g.find(".card-duration").text(q.pad(e.duration[0])+":"+q.pad(e.duration[1]));var f="user";l=".add-suggested",i?r="del_user_suggested":(r="del_suggested",f="system"),g.find(".vote-container").attr("class","clickable add-suggested"),g.find(".add-suggested").attr("title",d),g.find(".delete_button").addClass(r),g.find(l).attr("data-video-title",d),g.find(l).attr("data-video-length",e.length),g.find(l).attr("data-added-by",f),g.find("#list-song").attr("data-video-type","suggested"),g.find("#list-song").attr("data-video-id",c),g.find("#list-song").attr("id","suggested-"+c),g.find(".list-image").attr("class",g.find(".list-image").attr("class").replace("list-image","list-suggested-image"))}return g.find(".mobile-delete").remove(),g.find(".list-title").text(d),g.find(".list-title").attr("title",d),g.find(l).attr("data-video-id",c),g.find(".list-image").attr(h,u),g.find(".list-suggested-image").attr(h,u),g.find("."+r).attr("data-video-id",c),g.html()},getIndexOfSong:function(e){try{return indexes=$.map(ut,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)}},W=3,Z=void 0===window.chan?$("#chan").html():window.chan,X=!0,Q=0,K=!0,ee=$("#list-song-html").html(),te=!1,ae="***REMOVED***",ne=!1,ie=/P((([0-9]*\.?[0-9]*)Y)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)W)?(([0-9]*\.?[0-9]*)D)?)?(T(([0-9]*\.?[0-9]*)H)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)S)?)?/,se=[],oe=!1,le=0,j=1,re="",ce=!1,de="",pe=!1,ue=1,ge="",he=!1,me=!1,fe=!1,ye=!1,ve=!1,_e=!1,$e=1,we=!1,be=6e3,ke=Date.now(),Ce=!1,xe=!1,Se="",Te=-1,Ie=!1,Ee=!1,Le=!0,Be=!1,Me=!1,Ae=!1,Pe=!1,Ne=!1,De={},Ve=!1,Oe="",ze="",Ye=300,je=600,Re="&autoplay",qe=!1,Ue={},He=!1,Fe=!1,Ge="808080",Je=!1,We=!1,Ze=!1,Xe=!1,Qe=0,Ke="",et="",tt=!1,at="",nt=[],it=0,st="";if(void 0===localStorage.debug){localStorage.debug=!1}var ot,lt,rt,ct,dt,pt,ut,se,gt,ht,mt,ue,ft,yt,vt,_t,$t,D,wt={"sync disconnect on unload":!0,secure:!0,"force new connection":!0},bt=!1,kt=!1;try{navigator.serviceWorker.getRegistration("/").then(function(e){e&&e.unregister()})}catch(e){}$.ajaxPrefilter(function(e,t,a){e.async=!0}),$().ready(function(){localStorage.getItem("VERSION")&&parseInt(localStorage.getItem("VERSION"))==W||localStorage.setItem("VERSION",W),bt||"/"==window.location.pathname?kt||"/"!=window.location.pathname||t():a(),q.mobilecheck()&&D.on("guid",function(e){st=e}),D.on("connect",function(){qe&&(qe=!1,$(".connect_error").fadeOut(function(){$(".connect_error").remove(),Materialize.toast("Connected!",2e3,"green lighten"),Ze&&D.emit("offline",{status:!0,channel:void 0!=Z?Z.toLowerCase():""}),void 0!==Y.get_pass(Z.toLowerCase())&&""!==Y.get_pass(Z.toLowerCase())&&D.emit("password",{password:Y.crypt_pass(Y.get_pass(Z.toLowerCase())),channel:Z.toLowerCase()})}))}),D.on("self_ping",function(){void 0!=Z&&""!=Z.toLowerCase()&&D.emit("self_ping",{channel:Z.toLowerCase()})}),o();try{$.ajax({type:"GET",url:"https://api.github.com/users/zoff-music/received_events",success:function(e){for(var t=0;t"+e[0].created_at.substring(0,10)+": "+e[0].actor.display_login+"
"+e[0].payload.commits[0].sha.substring(0,10)+": "+e[0].payload.commits[0].message+"
J.can_fit||ee&&$($("#wrapper").children()[J.page+e]).css("display","none"),J.can_fit=e,J.element_height=$("#wrapper").height()/J.can_fit-5.3,$(".list-song").css("height",J.element_height+"px"),C(),$("#controls").length>0&&!q.mobilecheck()?$("#seekToDuration").css("top",$("#controls").position().top-55):$("#controls").length>0&&$("#seekToDuration").css("top",$("#controls").position().top-20)}}),$(document).on("click",".result-object",function(e){var t=$(e.target);if("9?"9+":Qe;$(".suggested-link span.badge.new.white").hasClass("hide")||0!=s||$(".suggested-link span.badge.new.white").addClass("hide"),$(".suggested-link span.badge.new.white").text(s)}$("#suggested-"+t).remove()}),$(document).on("click",".del_suggested",function(e){var t=$(this).attr("data-video-id");$("#suggested-"+t).remove()}),$(document).on("click",".del_user_suggested",function(e){var t=$(this).attr("data-video-id");$("#suggested-"+t).remove(),(Qe-=1)<0&&(Qe=0);var a=Qe>9?"9+":Qe;$(".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),J.vote(t,"del")}),$(document).on("click","#toast-container",function(){$(this).fadeOut(function(){$(this).remove()})}),$(document).on("click","#embed-area",function(){this.select()}),$(document).on("click",".brand-logo-navigate",function(e){e.preventDefault(),window.history.pushState("to the frontpage!","Title","/"),P()}),$(document).on("click","#player_bottom_overlay",function(){R.to_channel(Z.toLowerCase(),!1)}),$(document).keydown(function(e){if("/"!=window.location.pathname)if(91==e.keyCode||17==e.keyCode)Je=!0;else if(Je&&70==e.keyCode)Je=!1,We=!We,e.preventDefault(),We?($("#find_div").toggleClass("hide"),$("#find_input").focus(),at=""):($("#find_div").toggleClass("hide"),$("#find_input").val(""),$("#find_input").blur(),$(".highlight").removeClass("highlight"),nt=[],it=0,at="");else if(32!=e.keyCode||!$(".search-container").hasClass("hide")||"/"==window.location.pathname||$("#text-chat-input").is(":focus")||$("#password").is(":focus")||$("#user-pass-input").is(":focus")||$("#chan_thumbnail").is(":focus")||$("#chan_description").is(":focus")||$("#contact-form-from").is(":focus")||$("#contact-form-message").is(":focus")||$("#remote_channel").is(":focus")||$("#import").is(":focus")||$("#find_input").is(":focus")||$("#import_spotify").is(":focus"))Je=!1;else{if(1==xt.player.getPlayerState())return e.preventDefault(),xt.player.pauseVideo(),!1;if(2==xt.player.getPlayerState()||5==xt.player.getPlayerState())return e.preventDefault(),xt.player.playVideo(),!1}}),$(document).on("click","#close_find_form_button",function(e){e.preventDefault(),Je=!1,We=!1,$("#find_div").toggleClass("hide"),$("#find_input").val(""),$("#find_input").blur(),$(".highlight").removeClass("highlight"),nt=[],it=0,at=""}),$(document).keyup(function(e){91!=e.keyCode&&17!=e.keyCode||We||(Je=!1)}),$(document).on("submit","#find_form",function(e){if(e.preventDefault(),this.find_value.value!=at&&(at=this.find_value.value,nt=[],it=0),0==nt.length){var t=this;it=0,nt=$.map(ut,function(e,a){if(e.title.toLowerCase().indexOf(t.find_value.value.toLowerCase())>=0&&a!=ut.length-1)return a}),$("#num_found").text(it+1),$("#of_total_found").text(nt.length)}else it+=1,nt.length-10&&nt[it]!=ut.length-1){$(".highlight").removeClass("highlight");var a=Math.floor(nt[it]/J.can_fit);$($("#wrapper").children()[nt[it]]).addClass("highlight"),J.dynamicContentPageJumpTo(a)}else $(".highlight").removeClass("highlight"),q.log("none found")});var Ct={id:"",get_input:function(e){""===Ct.id?Ct.set_id(e.toLowerCase()):Ct.set_channel(e.toLowerCase())},set_id:function(e){Ct.id=e,$("#pausebutton_remote").attr("disabled",!1),$("#skipbutton_remote").attr("disabled",!1),$("#playbutton_remote").attr("disabled",!1),$("#skipbutton_remote").attr("disabled",!1),$("#remote_channel").val(""),$("#remote_channel").attr("placeholder","Change channel"),$("#remote_header").html("Controlling "+e),$("#volume-control-remote").css("display","inline-block"),$(".slider-vol-mobile").attr("style","display: inline-block !important")},set_channel:function(e){D.emit("id",{id:Ct.id,type:"channel",value:e})},play_remote:function(){D.emit("id",{id:Ct.id,type:"play",value:"mock"})},pause_remote:function(){D.emit("id",{id:Ct.id,type:"pause",value:"mock"})},skip_remote:function(){D.emit("id",{id:Ct.id,type:"skip",value:"mock"})},initiate_volume:function(){$("#volume-control-remote").slider({min:0,max:100,value:100,range:"min",animate:!0,stop:function(e,t){D.emit("id",{id:Ct.id,type:"volume",value:t.value}),q.log("volume")}})}},xt={loaded:!0,before_load:"",after_load:"",player:"",stopInterval:!1,fireplace:"",youtube_listener:function(e){var t;Ee&&e.np&&window.parentWindow&&window.parentOrigin&&(window.parentWindow.postMessage({type:"np",title:e.np[0].title},window.parentOrigin),ut.length>0&&xt.sendNext({title:ut[0].title,videoId:ut[0].id}));try{t=xt.player.getPlayerState()}catch(e){t=null}if((!Ze&&(null!=t||Ne)||Ze&&(null==t||Ne)||!Ze&&(null==t||Ne)||Ze&&-1==t)&&(!Ze||et!=Z)||Ze&&void 0==ft){et=Z,Ne=!1,xt.loaded=!1,q.log("--------youtube_listener--------"),q.log("Received: "),q.log(e),q.log("paused variable: "+_e),q.log("mobile_beginning variable: "+ct);try{q.log("getVideoUrl(): "+xt.player.getVideoUrl().split("v=")[1])}catch(e){}if(q.log("video_id variable: "+ft),q.log("---------------------------------"),e.np){if(_e)xt.getTitle(e.np[0].title,ue),q.mobilecheck()||xt.notifyUser(e.np[0].id,e.np[0].title),Fe||xt.stopVideo(),ft=e.np[0].id,se=e.conf[0],time=e.time,vt=time-se.startTime,_t=e.np[0].title,duration=e.np[0].duration,xt.setBGimage(ft);else if(!_e){void 0===$t?$t=e.np[0].id:$t!=ft&&($t=ft),ft=e.np[0].id,se=e.conf[0],time=e.time,vt=time-se.startTime,_t=e.np[0].title,duration=e.np[0].duration,ct&&q.mobilecheck()&&0===vt&&!Fe&&(vt=1);try{ut[0].id!=ft||ct||J.song_change(ut[0].added),It.fetchYoutubeSuggests(ft)}catch(e){}if(xt.getTitle(_t,ue),xt.setBGimage(ft),pe&&!window.MSStream)try{var a;try{a=xt.player.getVideoUrl().split("v=")[1]!=ft}catch(e){a=!0}(a||Fe)&&(xt.loadVideoById(ft,duration),q.mobilecheck()||xt.notifyUser(ft,_t),xt.seekTo(vt),_e&&!Fe&&xt.pauseVideo()),_e||(ct&&!Fe||xt.playVideo(),Be||xt.durationSetter()),(xt.player.getDuration()>vt||0===xt.player.getDuration()||Fe||xt.player.getCurrentTime()!=vt)&&xt.seekTo(vt),xt.after_load=ft,xt.loaded||setTimeout(function(){xt.loaded=!0},500)}catch(e){Fe&&(xt.loadVideoById(ft,duration),xt.seekTo(vt)),Be||Fe||xt.durationSetter()}else xt.getTitle(_t,ue)}}else{document.getElementById("song-title").innerHTML="Empty channel. Add some songs!",document.title="Zoff - the shared YouTube based radio",$("#channel-load").css("display","none"),window.MSStream||Fe||$("#player_overlay").hasClass("hide")&&$("#player_overlay").removeClass("hide");try{Fe||xt.stopVideo()}catch(e){}}}else Be||xt.durationSetter(),duration=xt.player.getDuration()},onPlayerStateChange:function(e){q.log("-------onPlayerStateChange------"),q.log("New state\nState: "),q.log(e);try{q.log("Duration: "+xt.player.getDuration(),"Current time: "+xt.player.getCurrentTime()),q.log("getVideoUrl(): "+xt.player.getVideoUrl().split("v=")[1])}catch(e){}switch(q.log("video_id variable: "+ft),q.log("---------------------------------"),e.data){case YT.PlayerState.UNSTARTED:break;case YT.PlayerState.ENDED:we=!1,_e=!1,Ze?xt.playNext():D.emit("end",{id:ft,channel:Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))});break;case YT.PlayerState.PLAYING:window.MSStream||($("#player").css("opacity","1"),q.mobilecheck()||$("#channel-load").css("display","none")),we=!0,beginning&&q.mobilecheck()&&!Fe&&(beginning=!1,ct=!1),Ee||"/"==window.location.pathname||Fe||q.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")),_e&&!Ze&&(D.emit("pos",{channel:Z.toLowerCase(),pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))}),_e=!1);break;case YT.PlayerState.PAUSED:Fe||(beginning&&ct&&($("#playpause").css("visibility","visible"),$("#playpause").css("pointer-events","all"),$("#channel-load").css("display","none")),_e=!0,"/"!=window.location.pathname&&St.play_pause_show(),ct=!0);break;case YT.PlayerState.BUFFERING:}},playVideo:function(){Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"playVideo"}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:_t,image:"https://img.youtube.com/vi/"+ft+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+ft+"/mqdefault.jpg"),$("#pause").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):xt.player.playVideo()},pauseVideo:function(){Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"pauseVideo"}),$("#play").hasClass("hide")&&($("#play").toggleClass("hide"),$("#pause").toggleClass("hide"))):xt.player.pauseVideo()},seekTo:function(e){Fe?U.sendMessage("urn:x-cast:zoff.me",{type:"seekTo",seekTo:e}):Ze?xt.player.seekTo(0):xt.player.seekTo(e)},loadVideoById:function(e,t){Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:e,channel:Z.toLowerCase()}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:_t,image:"https://img.youtube.com/vi/"+e+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+e+"/mqdefault.jpg")):xt.player.loadVideoById({videoId:e,startSeconds:0,endSeconds:t})},stopVideo:function(){if(Fe)U.sendMessage("urn:x-cast:zoff.me",{type:"stopVideo"});else try{xt.player.stopVideo()}catch(e){}},setVolume:function(e){Fe?U.setVolume(e/100):xt.player.setVolume(e)},playNext:function(){var e=ut[0];ft=e.id,time=(new Date).getTime(),_t=e.title,duration=e.duration,xt.getTitle(_t,ue),xt.setBGimage(ft),Fe?(U.sendMessage("urn:x-cast:zoff.me",{type:"loadVideo",videoId:ft,channel:Z.toLowerCase()}),chrome.cast.media.GenericMediaMetadata({metadataType:"GENERIC",title:_t,image:"https://img.youtube.com/vi/"+ft+"/mqdefault.jpg"}),chrome.cast.Image("https://img.youtube.com/vi/"+ft+"/mqdefault.jpg")):xt.loadVideoById(ft,duration),J.channel_function({type:"song_change",time:time})},sendNext:function(e){Fe&&U.sendMessage("urn:x-cast:zoff.me",{type:"nextVideo",title:e.title,videoId:e.videoId}),Ee&&window.parentWindow&&window.parentOrigin&&window.parentWindow.postMessage({type:"nextVideo",title:e.title},window.parentOrigin)},getTitle:function(e,t){var a=decodeURIComponent(e);if("/"!=window.location.pathname){var n=document.getElementById("song-title"),i=document.getElementById("viewers");n.innerHTML=a,i.innerHTML="visibility "+t,n.title=a,Fe&&($("#player_overlay").css("background","url(https://img.youtube.com/vi/"+ft+"/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=a+" • Zoff / "+Z},errorHandler:function(e){fe||(5==e.data||100==e.data||101==e.data||150==e.data?(curr_playing=xt.player.getVideoUrl().replace("https://www.youtube.com/watch?v=",""),D.emit("skip",{error:e.data,id:ft,pass:""==re?"":Y.crypt_pass(re),channel:Z.toLowerCase(),userpass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))})):void 0!==ft&&xt.loadVideoById(ft,duration))},onPlayerReady:function(e){try{beginning=!0,pe=!0,window.MSStream||(q.mobilecheck()&&($("#playpause").css("visibility","hidden"),$("#playpause").css("pointer-events","none"),$("#player").css("opacity","1")),$(".video-container").removeClass("no-opacity"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),xt.loadVideoById(ft,duration),!Le||q.mobilecheck()&&!Fe||xt.playVideo(),Be||xt.durationSetter(),Ee?setTimeout(function(){xt.player.seekTo(vt),Le||(xt.player.pauseVideo(),St.play_pause_show())},1e3):xt.seekTo(vt)),xt.readyLooks(),St.initYoutubeControls(xt.player),St.initSlider(),xt.player.setVolume(Y.get_volume())}catch(e){}},readyLooks:function(){xt.setBGimage(ft)},setBGimage:function(e){if(void 0!==e&&!Ee){var t=new Image;t.onload=function(){var e=new ColorThief,a=e.getColor(t);"/"!=window.location.pathname&&(document.getElementById("main-container").style.backgroundColor=q.rgbToHsl(a,!0),$("meta[name=theme-color]").attr("content",q.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),!q.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&&!Ee){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(){c(),l(),u(),h(),m()},onYouTubeIframeAPIReady:function(){xt.player=new YT.Player("player",{videoId:ft,playerVars:{rel:"0",wmode:"transparent",controls:"0",fs:"0",iv_load_policy:"3",theme:"light",color:"white",showinfo:0},events:{onReady:xt.onPlayerReady,onStateChange:xt.onPlayerStateChange,onError:xt.errorHandler}})},createFireplacePlayer:function(){xt.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:xt.onFireplaceReady,onStateChange:xt.onFireplaceChange}})},onFireplaceReady:function(){xt.fireplace.playVideo()},onFireplaceChange:function(e){switch(e.data){case 0:xt.fireplace.seekTo(0),xt.fireplace.playVideo();break;case 2:xt.fireplace.playVideo()}},durationSetter:function(){try{ye||void 0===duration||(xt.stopInterval||(Be=!0),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=void 0!==xt.player.getCurrentTime()?Math.floor(xt.player.getCurrentTime()):vt,currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=q.pad(minutes)+":"+q.pad(seconds)+" / "+q.pad(dMinutes)+":"+q.pad(dSeconds),per=100/duration*currDurr,per>=100?per=100:0===duration&&(per=0),Ee&&window.parentWindow&&window.parentOrigin&&window.parentWindow.postMessage({type:"duration",duration:xt.player.getCurrentTime(),full_duration:xt.player.getDuration(),percent:per},window.parentOrigin),me||$("#bar").width(per+"%"))}catch(e){}xt.stopInterval||setTimeout(xt.durationSetter,1e3)},loadPlayer:function(){if(1==$("script[src='https://www.youtube.com/iframe_api']").length)try{xt.onYouTubeIframeAPIReady()}catch(e){console.error("Seems YouTube iFrame script isn't correctly loaded. Please reload the page.")}else gt=document.createElement("script"),gt.src="https://www.youtube.com/iframe_api",ht=document.getElementsByTagName("script")[0],ht.parentNode.insertBefore(gt,ht)}},St={stopInterval:!1,initYoutubeControls:function(){q.mobilecheck()&&!window.MSStream&&$("#controls").appendTo("#playbar"),St.initControls()},initControls:function(){document.getElementById("volume-button").addEventListener("click",St.mute_video),document.getElementById("playpause").addEventListener("click",St.play_pause),document.getElementById("volume-button-overlay").addEventListener("click",St.mute_video),document.getElementById("playpause-overlay").addEventListener("click",St.play_pause),document.getElementById("fullscreen").addEventListener("click",St.fullscreen)},initSlider:function(){try{vol=Y.get_volume()}catch(e){}$("#volume").slider({min:0,max:100,value:vol,range:"min",animate:!0,slide:function(e,t){St.setVolume(t.value);try{Y.set_volume(t.value)}catch(e){}}}),St.choose_button(vol,!1)},fullscreen:function(){var e=document.getElementById("player"),t=e.requestFullScreen||e.mozRequestFullScreen||e.webkitRequestFullScreen;t&&t.bind(e)()},play_pause:function(){Fe?St.play_pause_show():xt.player.getPlayerState()==YT.PlayerState.PLAYING?(xt.pauseVideo(),q.mobilecheck()&&!window.MSStream&&(document.getElementById("player").style.display="none",$(".video-container").toggleClass("click-through"),$(".page-footer").toggleClass("padding-bottom-extra"))):xt.player.getPlayerState()!=YT.PlayerState.PAUSED&&xt.player.getPlayerState()!==YT.PlayerState.ENDED&&xt.player.getPlayerState()!==YT.PlayerState.CUED||(xt.playVideo(),q.mobilecheck()&&!window.MSStream&&(document.getElementById("player").style.display="block",$(".video-container").toggleClass("click-through"),$(".page-footer").toggleClass("padding-bottom-extra")))},play_pause_show:function(){Fe?$("#play").hasClass("hide")?xt.pauseVideo():$("#pause").hasClass("hide")&&xt.playVideo():(1==document.getElementById("pause").className.split(" ").length&&($("#pause").toggleClass("hide"),$("#pause-overlay").toggleClass("hide")),2==document.getElementById("play").className.split(" ").length&&($("#play").toggleClass("hide"),$("#play-overlay").toggleClass("hide")))},settings:function(){$("#qS").toggleClass("hide")},changeQuality:function(e){xt.player.getPlaybackQuality!=e&&(xt.player.setPlaybackQuality(e),xt.player.getPlaybackQuality()),$("#qS").toggleClass("hide")},mute_video:function(){xt.player.isMuted()?(Fe&&U.sendMessage("urn:x-cast:zoff.me",{type:"unMute"}),xt.player.unMute(),St.choose_button(xt.player.getVolume(),!1)):(Fe&&U.sendMessage("urn:x-cast:zoff.me",{type:"mute"}),St.choose_button(0,!0),xt.player.mute())},setVolume:function(e){xt.setVolume(e),St.choose_button(e,!1),xt.player.isMuted()&&xt.player.unMute()},choose_button:function(e,t){t?(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")),1==document.getElementById("v-low").className.split(" ").length&&($("#v-low").toggleClass("hide"),$("#v-low-overlay").toggleClass("hide")),2==document.getElementById("v-mute").className.split(" ").length&&($("#v-mute").toggleClass("hide"),$("#v-mute-overlay").toggleClass("hide"))):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=xt.player.getPlayerState(),button=document.getElementById("playpause"),state==YT.PlayerState.PLAYING?xt.pauseVideo():state==YT.PlayerState.PAUSED&&xt.playVideo()},volumeOptions:function(){Fe||(xt.player.isMuted()?(xt.player.unMute(),vol=xt.player.getVolume(),$("#volume").slider("value",xt.player.getVolume())):(xt.player.mute(),$("#volume").slider("value",0)))},hoverMute:function(e){vol=xt.player.getVolume()}},Tt={submitArray:[],submitArrayExpected:null,showSearch:function(){$("#search-wrapper").toggleClass("hide"),q.mobilecheck()&&$(".search_input").focus(),$("#song-title").toggleClass("hide"),$("#results").empty(),"close"==$("#search-btn i").html()?$("#search-btn i").html("search"):$("#search-btn i").html("close"),$("#search").focus()},search:function(e,t,a){if(void 0!==lt&&void 0!==rt||(lt=$("#temp-results-container"),rt=$("#empty-results-container").html()),$(".search_results").html(""),""!==e){ne=!0;var n=encodeURIComponent(e),i="https://www.googleapis.com/youtube/v3/search?key="+ae+"&videoEmbeddable=true&part=id&fields=items(id)&type=video&order=viewCount&safeSearch=none&maxResults=25";i+="&q="+n,le&&(i+="&videoCategoryId=10");var s="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";if(a)var i="https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&relatedToVideoId="+n+"&type=video&key="+ae,s="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";q.contains($(".search_loader_spinner").attr("class").split(" "),"active")||$(".search_loader_spinner").addClass("active"),q.contains($("#results").attr("class").split(" "),"hide")&&$("#results").removeClass("hide"),$.ajax({type:"GET",url:i,dataType:"jsonp",success:function(a){0===a.items.length?($(""+rt+"
").appendTo($("#results")).show("blind",83.33),q.contains($(".search_loader_spinner").attr("class").split(" "),"active")&&$(".search_loader_spinner").removeClass("active")):a.items&&($.each(a.items,function(e,t){s+=t.id.videoId+","}),$.ajax({type:"GET",url:s,dataType:"jsonp",success:function(a){var n="",i=$(lt);$.each(a.items,function(e,t){var a=t.contentDetails.duration;if(secs=Tt.durationToSeconds(a),!longsongs||secs<720){mt=t.snippet.title,enc_title=mt,pt=t.id,a=a.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s"),thumb=t.snippet.thumbnails.medium.url;var s=i;s.find(".search-title").text(mt),s.find(".result_info").text(a),s.find(".thumb").attr("src",thumb),s.find("#add-many").attr("data-video-id",pt),s.find("#add-many").attr("data-video-title",enc_title),s.find("#add-many").attr("data-video-length",secs),s.find("#temp-results").attr("data-video-id",pt),s.find("#temp-results").attr("data-video-title",enc_title),s.find("#temp-results").attr("data-video-length",secs),s.find(".open-externally").attr("href","https://www.youtube.com/watch?v="+pt),void 0!=s.html()&&(n+=s.html())}}),n.length>0?($(""+n+"
").appendTo($("#results")).show("blind",83.33*(a.items.length-1)),q.contains($(".search_loader_spinner").attr("class").split(" "),"active")&&$(".search_loader_spinner").removeClass("active"),$(".add-many").click(function(e){return e.preventDefault(),e.stopPropagation(),!1})):t?($(""+rt+"
").appendTo($("#results")).show("blind",83.33),q.contains($(".search_loader_spinner").attr("class").split(" "),"active")&&$(".search_loader_spinner").removeClass("active")):Tt.search(e,!0)}}))}})}else $(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},backgroundSearch:function(e,t,a,n,i){var s=encodeURIComponent(e+" "+t),o="https://www.googleapis.com/youtube/v3/search?key="+ae+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10&videoCategoryId=10";o+="&q="+s;var l="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";t=t.split(" ");var r=e.split("-");r=r.join(" ").split(" "),$.ajax({type:"GET",url:o,dataType:"jsonp",success:function(i){if(0===i.items.length){Tt.readySubmit(!1,{totalLength:n-1}),q.log("------------------------------"),q.log("NO MATCH FOR:"),q.log("Spotify title: "+e+" "+t.join(" ")),q.log("Spotify length: "+a),q.log("------------------------------");var s=$(""+Oe+"
");s.find(".extra-add-text").text(e+" - "+t.join(" ")),s.find(".extra-add-text").attr("title",e+" - "+t.join(" ")),s.find(".extra-button-search").attr("data-text",e+" - "+t.join(" ")),$(".not-imported-container").append(s.html()),$(".not-imported").removeClass("hide")}else i.items.length>0&&($.each(i.items,function(e,t){l+=t.id.videoId+","}),$.ajax({type:"GET",url:l,dataType:"jsonp",success:function(i){if(i.items.length>0){var s=!1;if($.each(i.items,function(a,i){var o=Tt.durationToSeconds(i.contentDetails.duration),l=!1;if($.each(r,function(a,n){return-1!=i.snippet.title.toLowerCase().indexOf(n.toLowerCase())&&-1==i.snippet.title.toLowerCase().indexOf("cover")&&-1==e.toLowerCase().indexOf("cover")&&(-1==i.snippet.title.toLowerCase().indexOf("remix")&&-1==e.toLowerCase().indexOf("remix")||-1!=i.snippet.title.toLowerCase().indexOf("remix")&&-1!=e.toLowerCase().indexOf("remix")||-1!=i.snippet.title.toLowerCase().indexOf(t[0].toLowerCase())||-1!=i.snippet.channelTitle.toLowerCase().indexOf(t[0].toLowerCase())||-1!=i.snippet.channelTitle.toLowerCase().indexOf("vevo"))||(l=!0),!1}),!l)return s=!0,Tt.readySubmit(!0,{id:i.id,title:i.snippet.title,duration:o,totalLength:n-1}),!1}),!s){Tt.readySubmit(!1,{totalLength:n-1}),q.log("------------------------------"),q.log("NO MATCH FOR:"),q.log("Spotify title: "+e+" "+t.join(" ")),q.log("Spotify length: "+a),q.log("------------------------------");var o=$(""+Oe+"
");o.find(".extra-add-text").text(e+" - "+t.join(" ")),o.find(".extra-add-text").attr("title",e+" - "+t.join(" ")),o.find(".extra-button-search").attr("data-text",e+" - "+t.join(" ")),$(".not-imported-container").append(o.html()),$(".not-imported").removeClass("hide")}}}}))}})},readySubmit:function(e,t){null===Tt.submitArrayExpected&&(Tt.submitArrayExpected=t.totalLength),e?Tt.submitArray.push(t):Tt.submitArrayExpected-=1,Tt.submitArray.length-1==Tt.submitArrayExpected&&($.each(Tt.submitArray,function(e,t){Tt.submit(t.id,t.title,t.duration,!0,e,Tt.submitArray.length-1)}),document.getElementById("import_spotify").disabled=!1,$("#import_spotify").removeClass("hide"),$("#playlist_loader_spotify").addClass("hide"),Tt.submitArray=[],Tt.submitArrayExpected=null)},submitAndClose:function(e,t,a){Tt.submit(e,t,a,!1,0,1),$("#results").html(""),Tt.showSearch(),document.getElementById("search").value="",$("#results").html="",$(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},importPlaylist:function(e,t){token="";var a,n;void 0!==t&&(token="&pageToken="+t),playlist_url="https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+ae+"&playlistId="+e+token,He?(n="html",a={"Content-Type":"application/json",Authorization:"Bearer "+Ue.access_token}):(a={},n="jsonp"),$.ajax({type:"GET",url:playlist_url,dataType:n,headers:a,success:function(a){if(a.error)if("playlistItemsNotAccessible"==a.error.errors[0].reason){var n=S(29);window.callback=function(a){Ue=a,Ue.state==n?(He=!0,setTimeout(function(){He=!1,Ue={}},1e3*Ue.expires_in),Tt.importPlaylist(e,t)):(Ue="",console.error("Nonce doesn't match")),youtube_window.close(),window.callback=""},youtube_window=window.open("/o_callback#youtube=true&nonce="+n,"","width=600, height=600")}else q.log(a.error),document.getElementById("import").disabled=!1,$("#playlist_loader").addClass("hide"),$("#import").removeClass("hide"),A(),Materialize.toast("It seems you've entered a invalid url.",4e3);else{var i="";"string"==typeof a&&(a=$.parseJSON(a)),$.each(a.items,function(e,t){i+=t.contentDetails.videoId+","}),Tt.addVideos(i,!0),a.nextPageToken&&Tt.importPlaylist(e,a.nextPageToken),document.getElementById("import").value=""}}})},importSpotifyPlaylist:function(e){$.ajax({url:e,headers:{Authorization:"Bearer "+De.access_token},success:function(e){$.each(e.items,function(t,a){Tt.backgroundSearch(a.track.name,a.track.artists.map(function(e){return e.name}).join(" "),Math.floor(a.track.duration_ms/1e3),e.total,t+e.offset)}),e.next&&Tt.importSpotifyPlaylist(e.next)},error:function(){document.getElementById("import_spotify").disabled=!1,$("#import_spotify").removeClass("hide"),$("#playlist_loader_spotify").addClass("hide"),A(),Materialize.toast("It seems you've entered a invalid url.",4e3)}})},addVideos:function(e,t){var a="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id=";a+=e,$.ajax({type:"POST",url:a,dataType:"jsonp",success:function(e){var a=0,n=[];$.each(e.items,function(e,i){var s=Tt.durationToSeconds(i.contentDetails.duration);(!longsongs||s<720)&&(enc_title=i.snippet.title,a+=1,n.push({id:i.id,enc_title:enc_title,duration:s,playlist:t}))}),$.each(n,function(e,t){Tt.submit(t.id,t.enc_title,t.duration,t.playlist,e,a)})}})},submit:function(e,t,a,n,i,s){if(Ze&&document.getElementsByName("addsongs")[0].checked&&document.getElementsByName("addsongs")[0].disabled){var o=[];o=$.map(ut,function(t,a){if(t.id==e)return a}),0==o.length?J.channel_function({type:"added",value:{added:(new Date).getTime()/1e3,guids:[1],id:e,title:t,duration:a,playlist:!1,now_playing:!1,votes:1}}):J.vote(e,"pos")}else D.emit("add",{id:e,title:t,adminpass:""==re?"":Y.crypt_pass(re),list:Z.toLowerCase(),duration:a,playlist:n,num:i,total:s,pass:Ee?"":Y.crypt_pass(Y.get_userpass(Z.toLowerCase()))})},durationToSeconds:function(e){var t=e.match(ie);return hours=parseInt(t[12])||0,minutes=parseInt(t[14])||0,seconds=parseInt(t[16])||0,60*hours*60+60*minutes+seconds}},It={catchUserSuggests:function(e,t){Qe+=t?1:e.length;var a=Qe>9?"9+":Qe;if($(".suggested-link span.badge.new.white").hasClass("hide")&&Qe>0&&$(".suggested-link span.badge.new.white").removeClass("hide"),$(".suggested-link span.badge.new.white").text(a),t)It.createSuggested(e);else for(var n in e)It.createSuggested(e[n]);It.checkUserEmpty()},createSuggested:function(e){var t=q.secondsToOther(e.duration),a=e.id,n=e.title,i=J.generateSong({id:a,title:n,length:e.duration,duration:t},!1,!1,!1,!0);$("#user-suggest-html").append(i)},fetchYoutubeSuggests:function(e){var t="https://www.googleapis.com/youtube/v3/search?part=snippet&relatedToVideoId="+e+"&type=video&key="+ae,a="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+ae+"&id=";$.ajax({type:"GET",url:t,dataType:"jsonp",success:function(e){$.each(e.items.slice(0,5),function(e,t){a+=t.id.videoId+","}),$.ajax({type:"GET",url:a,dataType:"jsonp",success:function(e){$("#suggest-song-html").empty(),$.each(e.items,function(e,t){var a=t.contentDetails.duration,n=Tt.durationToSeconds(a);a=q.secondsToOther(Tt.durationToSeconds(a));var i=t.id,s=t.snippet.title;$("#suggest-song-html").append(J.generateSong({id:i,title:s,length:n,duration:a},!1,!1,!1))})}})}})},checkUserEmpty:function(){0===$("#user-suggest-html").children().length?q.contains($("#user_suggests").attr("class").split(" "),"hide")||$("#user_suggests").addClass("hide"):$("#user_suggests").removeClass("hide")}}}();
\ No newline at end of file
diff --git a/server/public/assets/js/chat.js b/server/public/assets/js/chat.js
index e645c2f3..6d27d15c 100755
--- a/server/public/assets/js/chat.js
+++ b/server/public/assets/js/chat.js
@@ -65,7 +65,7 @@ var Chat = {
} else if(data.value.startsWith("/removename")){
Chat.removename();
} else if($(".chat-tab-li a.active").attr("href") == "#all_chat"){
- socket.emit("all,chat", data.value);
+ socket.emit("all,chat", {channel: chan.toLowerCase(), data: data.value});
} else {
socket.emit("chat", {channel: chan.toLowerCase(), data: data.value, pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))});
}
diff --git a/server/router.js b/server/routing/router.js
similarity index 99%
rename from server/router.js
rename to server/routing/router.js
index 67e0389c..290eb8c3 100644
--- a/server/router.js
+++ b/server/routing/router.js
@@ -2,7 +2,7 @@ var express = require('express');
var router = express.Router();
const path = require('path');
var nodemailer = require('nodemailer');
-var mailconfig = require('./mailconfig.js');
+var mailconfig = require('../mailconfig.js');
router.use(function(req, res, next) {
next(); // make sure we go to the next routes and don't stop here
diff --git a/server/server.js b/server/server.js
index 4f0224c7..db4f8a54 100755
--- a/server/server.js
+++ b/server/server.js
@@ -1,3 +1,5 @@
+VERSION = 3;
+
var server;
var add = "";
const path = require('path');
@@ -67,29 +69,31 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
}));
app.use(cookieParser());
-var VERSION = 3;
-var io = require('socket.io')(server, {'pingTimeout': 25000}); //, "origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*" + add)});
-var request = require('request');
-var mongojs = require('mongojs');
-var db = mongojs(mongo_db_cred.config);
-var crypto = require('crypto');
-var node_cryptojs = require('node-cryptojs-aes');
-var router = require('./router.js');
-var CryptoJS = node_cryptojs.CryptoJS;
-var emojiStrip = require('emoji-strip');
-var Filter = require('bad-words');
-var filter = new Filter({ placeHolder: 'x'});
+/* Starting DB and socketio */
+io = require('socket.io')(server, {'pingTimeout': 25000}); //, "origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*" + add)});
+db = require('./handlers/db.js');
+var socketIO = require('./handlers/io.js');
+socketIO();
-var port = 8080;
-var lists = {};
-var offline_users = [];
-var unique_ids = [];
-var names = {names: []};
-var locks = {};
-var skipped = {};
-var tot_view = 0;
+request = require('request');
+/* Globally needed "libraries" and files */
+Functions = require('./handlers/functions.js');
+ListChange = require('./handlers/list_change.js');
+Chat = require('./handlers/chat.js');
+List = require('./handlers/list.js');
+Suggestions = require('./handlers/suggestions.js');
+ListSettings = require('./handlers/list_settings.js');
+Frontpage = require('./handlers/frontpage.js');
+crypto = require('crypto');
+node_cryptojs = require('node-cryptojs-aes');
+CryptoJS = node_cryptojs.CryptoJS;
+emojiStrip = require('emoji-strip');
+Filter = require('bad-words');
+filter = new Filter({ placeHolder: 'x'});
+var router = require('./routing/router.js');
+var port = 8080;
server.listen(port, function () {
console.log('Server listening at port %d', port);
@@ -116,1592 +120,13 @@ app.use('/service-worker.js', function(req, res) {
app.use('/', router);
app.use('/assets', express.static(publicPath + '/assets'));
-
-
-/*process.on('uncaughtException', function(e){
-console.log("\n" + new Date().toString() + "\n", e.stack || e);
-process.exit(1);
-})*/
-
db.on('error',function(err) {
console.log("\n" + new Date().toString() + "\n Database error: ", err);
});
-db.collection("frontpage_lists").update({viewers: {$gt: 0}}, {$set: {"viewers": 0}}, {multi: true}, function(err, docs) {});
-
-io.on('connection', function(socket){
- socket.emit("get_list");
-
- var guid = hash_pass(socket.handshake.headers["user-agent"] + socket.handshake.address + socket.handshake.headers["accept-language"]);
-
- socket.on('close', function() {
- console.log("closing socket");
- });
-
- socket.on('pinging', function() {
- socket.emit("ok");
- });
-
- var socketid = socket.id;
- var coll;
- var in_list = false;
- var short_id = uniqueID(socketid,4);
- var offline = false;
- //names.push(name);
- unique_ids.push(short_id);
- var name;
- var chromecast_object = false;
- if(names[guid] === undefined){
- name = get_name(guid);
- }
- else
- name = names[guid];
-
- socket.emit("guid", guid);
-
- socket.on('self_ping', function(msg) {
- var channel = msg.channel;
- if(offline) {
- offline_users.push(guid);
- } else {
- if(lists[channel] == undefined) {
- lists[channel] = [];
- }
- lists[channel].push(guid);
-
- db.collection("frontpage_lists").update({"_id": msg.channel}, {$inc: {viewers: 1}}, function(err, docs){});
- }
- tot_view += 1
- });
-
- socket.on('chromecast', function(msg) {
- try {
- if(typeof(msg) == "object" && msg.hasOwnProperty("guid") && msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("channel")) {
- if(lists[msg.channel].indexOf(msg.guid) > -1) {
- guid = msg.guid;
- socketid = msg.socket_id;
- coll = msg.channel;
- in_list = true;
- chromecast_object = true;
- socket.join(coll);
- }
- }
- } catch(e) {
- return;
- }
- });
-
- socket.on("get_userlists", function(id) {
- db.collection("frontpage_lists_" + id).find(function(err, docs) {
- socket.emit("userlists", [docs]);
- });
- });
-
- socket.on("get_spread", function(){
- socket.emit("spread_listeners", {offline: offline_users.length, total: tot_view, online_users: lists});
- });
-
- socket.on('suggest_thumbnail', function(msg){
- if(msg.thumbnail && msg.channel && msg.adminpass && msg.thumbnail.indexOf("i.imgur.com") > -1){
- msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
- if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
- var channel = msg.channel.toLowerCase();
- var hash = hash_pass(decrypt_string(socketid, msg.adminpass));
- db.collection(channel).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) {
- if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
- db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){
- socket.emit("toast", "suggested_thumbnail");
- });
- }
- } else {
- socket.emit("auth_required");
- }
- });
- } else {
- socket.emit("toast", "thumbnail_denied");
- }
- });
-
- socket.on('suggest_description', function(msg){
- if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){
- var channel = msg.channel.toLowerCase();
- var hash = hash_pass(decrypt_string(socketid, msg.adminpass));
- db.collection(channel).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) {
- if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
- db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){
- socket.emit("toast", "suggested_description");
- });
- }
- } else {
- socket.emit("auth_required");
- }
- });
- } else {
- socket.emit("toast", "description_denied");
- }
- });
-
- socket.on("offline", function(msg){
- if(!msg.hasOwnProperty('status') && !msg.hasOwnProperty('channel')) {
- socket.emit("update_required");
- return;
- }
- var status = msg.status;
- var channel = msg.channel;
- if(status){
- in_list = false;
- offline = true;
- if(channel != "") coll = channel;
- if(coll !== undefined && lists[coll] !== undefined && contains(lists[coll], guid))
- {
- var index = lists[coll].indexOf(guid);
- if(index != -1)
- {
- lists[coll].splice(index, 1);
- //socket.leave(coll);
- io.to(coll).emit("viewers", lists[coll].length);
- //io.to(coll).emit('chat', {from: name, msg: " left"});
- tot_view -= 1;
- }
-
- remove_from_array(names.names, name);
- delete names[guid];
-
- }
-
- remove_from_array(unique_ids, short_id);
- if(!contains(offline_users, guid) && coll != undefined)
- {
- offline_users.push(guid);
- tot_view += 1;
- }
- } else {
- offline = false;
- if(contains(offline_users, guid))
- {
- var index = offline_users.indexOf(guid);
- if(index != -1){
- offline_users.splice(index, 1);
- tot_view -= 1;
- }
- }
- check_inlist(coll, guid, socket, names[guid], offline);
- }
- });
-
- socket.on('namechange', function(data)
- {
- if(typeof(data) !== "string") return;
- data = encodeURIComponent(data).replace(/\W/g, '').replace(/[^\x00-\x7F]/g, "");
- old_name = names[guid];
- new_name = change_name(data, guid, name);
- if(new_name == name || new_name === false) return;
- else if(data.length < 9 && data.indexOf(" ") == -1 && data.length >= 4)
- {
- remove_from_array(names.names, old_name);
- delete names[guid];
- name = new_name;
- names[guid] = new_name;
- names.names.push(new_name);
- io.to(coll).emit('chat', {from: old_name, msg: " changed name to " + new_name});
- io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + new_name, channel: coll});
- }
- });
-
- socket.on("removename", function()
- {
- old_name = names[guid];
- new_name = rndName(guid, 8);
- if(old_name != new_name){
- name = new_name;
- names[guid] = name;
- remove_from_array(names.names, old_name);
- io.to(coll).emit('chat', {from: old_name, msg: " changed name to " + new_name});
- io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + new_name, channel: coll});
- }
- });
-
- socket.on('chat', function (msg) {
- if(typeof(data) !== 'object' && !msg.hasOwnProperty('data') && !msg.hasOwnProperty('channel') && !msg.hasOwnProperty('pass')) {
- socket.emit('update_required');
- return;
- }
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) {
- var data = msg.data;
- check_inlist(coll, guid, socket, names[guid], offline);
- if(data !== "" && data !== undefined && data !== null &&
- data.length < 151 && data.replace(/\s/g, '').length){
- if(names[guid] === undefined){
- name = get_name(guid);
- } else name = names[guid];
- io.to(coll).emit('chat', {from: names[guid], msg: ": " + data});
- }
- } else {
- socket.emit('auth_required');
- }
- });
- });
-
- socket.on("all,chat", function(data)
- {
- if(typeof(data) !== 'string') {
- socket.emit('update_required');
- return;
- }
- check_inlist(coll, guid, socket, names[guid], offline);
- if(data !== "" && data !== undefined && data !== null &&
- data.length < 151 && data.replace(/\s/g, '').length){
- if(names[guid] === undefined){
- name = get_name(guid);
- } else name = names[guid];
- io.sockets.emit('chat.all', {from: names[guid], msg: ": " + data, channel: coll});
- }
- });
-
- socket.on('frontpage_lists', function(msg)
- {
-
- if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) {
- socket.emit("update_required");
- }
-
- in_list = false;
-
- db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){
- socket.emit("playlists", {channels: docs, viewers: tot_view});
- });
- });
-
- socket.on('now_playing', function(list, fn)
- {
- if(typeof(list) !== 'string' || typeof(fn) !== 'function') {
- socket.emit('update_required');
- return;
- }
- db.collection(list).find({now_playing:true}, function(err, docs){
- if(docs.length === 0){
- fn("No song currently playing");
- return;
- }
- var title = docs[0].title;
- //socket.emit("now_playing", title);
- if(title === undefined) fn("No song currently playing");
- else fn(title);
- });
- });
-
- socket.on('id', function(arr)
- {
- if(typeof(arr) == 'object')
- io.to(arr.id).emit(arr.id, {type: arr.type, value: arr.value});
- });
-
- socket.on('list', function(msg)
- {
- if(typeof(msg) === 'object' && msg !== undefined && msg !== null && msg.hasOwnProperty("channel") && msg.hasOwnProperty('pass'))
- {
-
- if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) {
- socket.emit("update_required");
- }
-
- try {
- var list = msg.channel;
- if(list.length == 0) return;
- coll = emojiStrip(list).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
- var pass = decrypt_string(socketid, msg.pass);
- db.collection('frontpage_lists').find({"_id": coll}, function(err, docs){
- if(docs.length == 1)
- {
- db.collection(coll).find({views: {$exists: true}}, function(err, docs) {
- if(docs.length == 0 || (docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) {
- if(docs.length > 0 && docs[0].hasOwnProperty('userpass') && docs[0].userpass != "" && docs[0].userpass == pass) {
- socket.emit("auth_accepted", {value: true});
- }
- in_list = true;
- socket.join(coll);
- socket.join(short_id);
- socket.emit("id", short_id);
- check_inlist(coll, guid, socket, name, offline);
- io.to(coll).emit("viewers", lists[coll] == undefined ? 0 : lists[coll].length);
-
- send_list(coll, socket, true, false, true);
-
- } else {
- socket.emit("auth_required");
- }
- });
- } else{
- db.createCollection(coll, function(err, docs){
- db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":get_time(), "views": [], "vote": false, "desc": ""}, function(err, docs){
- send_list(coll, socket, true, false, true);
- db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": get_time()});
- });
- });
- }
- });
- } else {
- socket.emit('update_required');
- }
- });
-
- socket.on('end', function(obj)
- {
- if(typeof(obj) !== 'object') {
- return;
- }
- id = obj.id;
- if(id !== undefined && id !== null && id !== "")
- {
- if(coll === undefined) {
- try {
- coll = obj.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
-
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, obj.pass)))) {
-
- check_inlist(coll, guid, socket, name, offline);
- db.collection(coll).find({now_playing:true}, function(err, np){
- if(err !== null) console.log(err);
- if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- var startTime = docs[0].startTime;
- if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=get_time()+5)
- {
- db.collection(coll).remove({now_playing:true}, function(err, docs){
- change_song_post(coll);
- db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:-1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){});
- });
- }else{
- if(startTime+parseInt(np[0].duration)<=get_time()+5)
- {
- change_song(coll, false, id);
- }
- }
- });
- }
- });
- } else {
- socket.emit("auth_required");
- }
- });
- } else {
- socket.emit('update_required');
- }
- });
-
- socket.on('add', function(arr)
- {
- if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration)))
- {
- //if(arr.length == 5) coll = arr[4];
- if(coll !== undefined) {
- try {
- coll = arr.list;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
-
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, arr.pass)))) {
-
- check_inlist(coll, guid, socket, name, offline);
-
- var id = arr.id;
- var title = arr.title;
- var hash = hash_pass(decrypt_string(socketid, arr.adminpass));
- var duration = parseInt(arr.duration);
- var full_list = arr.playlist;
- var last = arr.num == arr.total - 1;
- var num = arr.num;
- var total = arr.total;
- db.collection(coll).find({views:{$exists:true}}, function(err, docs)
- {
- conf = docs;
- if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
- docs[0].addsongs === false))
- {
- db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){
- if(docs !== null && docs.length === 0)
- {
- var guids = full_list === true ? [] : [guid];
- var votes;
- var added;
- if(full_list) {
- var time = get_time()-total;
- time = time.toString();
- var total_len = total.toString().length;
- var now_len = num.toString().length;
- var to_add = num.toString();
- while(now_len < total_len) {
- to_add = "0" + to_add;
- now_len = to_add.length;
- }
- time = time.substring(0, time.length - total_len);
- time = time + to_add;
- time = parseInt(time);
- added = time;
- votes = 0;
- } else {
- added = get_time();
- votes = 1;
- }
-
- db.collection(coll).find({now_playing:true}, function(err, docs){
- if((docs !== null && docs.length === 0)){
- np = true;
- if(full_list && num === 0){
- np = true;
- //var time = get_time() - total - 1;
- time = time.toString();
- total += 1;
- var total_len = total.toString().length;
- var now_len = total.toString().length;
- var to_add = total.toString();
- while(now_len < total_len) {
- to_add = "0" + to_add;
- now_len = to_add.length;
- }
- time = time.substring(0, time.length - total_len);
- time = parseInt(time).toString() + to_add;
- time = parseInt(time);
- added = time;
- votes = 0;
- } else if(full_list) {
- np = false;
- }
- } else {
- np = false;
- }
- db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, {upsert: true}, function(err, docs){
- if(np)
- {
- send_list(coll, undefined, false, true, false);
- db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: get_time()}});
- send_play(coll, undefined);
- //io.to(coll).emit("channel", "song_change", get_time()]);
- update_frontpage(coll, id, title);
- //io.to(coll).emit("channel", ["added", {"_id": "asd", "added":added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}]);
- } else {
- io.to(coll).emit("channel", {type: "added", value: {"_id": "asd", "added":added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}});
- }
- db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){});
- getNextSong(coll);
- });
- if(!full_list) {
- socket.emit("toast", "addedsong");
- } else if(full_list && last) {
- socket.emit("toast", "addedplaylist");
- }
- });
- } else if(!full_list) {
- vote(coll, id, guid, socket, full_list, last);
- if(full_list && last) {
- socket.emit("toast", "addedplaylist");
- }
- } else if(full_list && last) {
- socket.emit("toast", "addedplaylist");
- }
- });
- } else if(!full_list) {
- db.collection(coll).find({id: id}, function(err, docs) {
- if(docs.length === 0) {
- db.collection(coll).update({id: id}, {$set:{
- "added":get_time(),
- "guids": [guid],
- "id":id,
- "now_playing": false,
- "title":title,
- "votes":1,
- "duration":duration,
- "type":"suggested"}
- },
- {upsert:true}, function(err, docs){
- socket.emit("toast", "suggested");
- io.to(coll).emit("suggested", {id: id, title: title, duration: duration});
- });
- } else if(docs[0].now_playing === true){
- socket.emit("toast", "alreadyplay");
- } else{
- if(conf[0].vote === false) vote(coll, id, guid, socket, full_list, last);
- else socket.emit("toast", "listhaspass");
- }
- });
- //socket.emit("toast", "listhaspass");
- } else if (full_list){
- if(arr.num == 0) {
- socket.emit("toast", "listhaspass");
- }
- }
- });
- } else {
- socket.emit("auth_required");
- }
- });
- } else {
- socket.emit('update_required');
- }
- });
-
- socket.on('delete_all', function(msg) {
- if(typeof(msg) == 'object' && msg.hasOwnProperty('channel') && msg.hasOwnProperty('adminpass') && msg.hasOwnProperty('pass')) {
- var hash = hash_pass(decrypt_string(socketid, msg.adminpass));
- var hash_userpass = decrypt_string(socketid, msg.pass);
-
- if(coll !== undefined) {
- try {
- coll = msg.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- db.collection(coll).find({views: {$exists: true}}, function(err, conf) {
- if(conf.length == 1 && conf) {
- conf = conf[0];
- if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || (conf.userpass != "" && conf.userpass == hash_userpass))) {
- db.collection(coll).remove({views: {$exists: false}}, {multi: true}, function(err, succ) {
- send_list(coll, false, true, true, true);
- db.collection("frontpage_lists").update({_id: coll}, {$set: {count: 0, accessed: get_time()}}, {upsert: true}, function(err, docs) {});
- socket.emit("toast", "deleted_songs");
- });
- } else {
- socket.emit("toast", "listhaspass");
- }
- }
- });
- } else {
- socket.emit("update_required");
- return;
- }
- })
-
- socket.on('vote', function(msg)
- {
- if(typeof(msg) === 'object' && msg !== undefined && msg !== null)
- {
-
- if(coll !== undefined) {
- try {
- coll = msg.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- if(coll == "" || coll == undefined || coll == null || !msg.hasOwnProperty("adminpass") || !msg.hasOwnProperty("pass") || !msg.hasOwnProperty("id")) {
- socket.emit("update_required");
- return;
- }
-
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) {
-
- check_inlist(coll, guid, socket, name, offline);
-
- if(msg.type == "del")
- del(msg, socket, socketid);
- else
- {
- var id = msg.id;
- var hash = hash_pass(decrypt_string(socketid, msg.adminpass));
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
- docs[0].vote === false))
- {
- vote(coll, id, guid, socket, false, false);
- }else{
- socket.emit("toast", "listhaspass");
- }
- });
- }
- } else {
- socket.emit("auth_required");
- }
- });
- } else {
- socket.emit('update_required');
- }
- });
-
- socket.on('password', function(inp)
- {
- if(inp !== undefined && inp !== null && inp !== "")
- {
- pw = inp.password;
- opw = inp.password;
- try {
- coll = inp.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
-
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
-
- uncrypted = pw;
- pw = decrypt_string(socketid, pw);
-
- check_inlist(coll, guid, socket, name, offline);
-
- if(inp.oldpass)
- {
- opw = inp.oldpass;
- }
- opw = decrypt_string(socketid, opw);
-
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs !== null && docs.length !== 0)
- {
- if(docs[0].adminpass === "" || docs[0].adminpass == hash_pass(opw))
- {
- db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:hash_pass(pw)}}, function(err, docs){
- if(inp.oldpass)
- socket.emit("toast", "changedpass");
- else
- socket.emit("toast", "correctpass");
- socket.emit("pw", true);
- });
- }else
- socket.emit("toast", "wrongpass");
- }
- });
- } else {
- socket.emit('update_required');
- }
- });
-
- socket.on('skip', function(list)
- {
- //if(1==2)
- if(list !== undefined && list !== null && list !== "")
- {
- if(coll !== undefined) {
- try {
- coll = list.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
-
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == decrypt_string(socketid, list.userpass)))) {
-
- check_inlist(coll, guid, socket, name, offline);
-
- adminpass = "";
- video_id = list.id;
- err = list.error;
- var error = false;
- var video_id;
- if(err != "5" && err != "100" && err != "101" && err != "150")
- {
- adminpass = list.pass;
- }else if(err == "5" || err == "100" || err == "101" || err == "150"){
- error = true;
- }
-
- if(adminpass !== undefined && adminpass !== null && adminpass !== "")
- hash = hash_pass(decrypt_string(socketid, adminpass));
- else
- hash = "";
-
- db.collection(coll).find({views: {$exists:true}}, function(err, docs){
-
- if(docs !== null && docs.length !== 0)
- {
- if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error)
- {
- if((lists[coll].length/2 <= docs[0].skips.length+1 && !contains(docs[0].skips, guid) && lists[coll].length != 2) ||
- (lists[coll].length == 2 && docs[0].skips.length+1 == 2 && !contains(docs[0].skips, guid)) ||
- (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip))
- {
- //if(!locks[coll] || locks[coll] == undefined){
- locks[coll] = true;
- change_song(coll, error, video_id);
- socket.emit("toast", "skip");
- io.to(coll).emit('chat', {from: name, msg: " skipped"});
- //}
- }else if(!contains(docs[0].skips, guid)){
- db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){
- if(lists[coll].length == 2)
- to_skip = 1;
- else
- to_skip = (Math.ceil(lists[coll].length/2) - docs[0].skips.length-1);
- socket.emit("toast", to_skip + " more are needed to skip!");
- socket.broadcast.to(coll).emit('chat', {from: name, msg: " voted to skip"});
- });
- }else{
- socket.emit("toast", "alreadyskip");
- }
- }else
- socket.emit("toast", "noskip");
- }
- });
- } else {
- socket.emit("auth_required");
- }
- });
- } else {
- socket.emit('update_required');
- }
- });
-
- socket.on('conf', function(params)
- {
- if(params !== undefined && params !== null && params !== "" &&
- params.hasOwnProperty('voting') &&
- params.hasOwnProperty('addsongs') &&
- params.hasOwnProperty('longsongs') &&
- params.hasOwnProperty('frontpage') &&
- params.hasOwnProperty('allvideos') &&
- params.hasOwnProperty('removeplay') &&
- params.hasOwnProperty('adminpass') &&
- params.hasOwnProperty('skipping') &&
- params.hasOwnProperty('shuffling') &&
- params.hasOwnProperty('channel'))
- {
- if(coll !== undefined) {
- try {
- coll = params.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
-
- check_inlist(coll, guid, socket,name, offline);
-
- var voting = params.voting;
- var addsongs = params.addsongs;
- var longsongs = params.longsongs;
- var frontpage = params.frontpage;
- var allvideos = params.allvideos;
- var removeplay = params.removeplay;
- var adminpass = params.adminpass;
- var skipping = params.skipping;
- var shuffling = params.shuffling;
- var userpass = decrypt_string(socketid, params.userpass);
-
- if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) {
- userpass = "";
- } else if(params.userpass_changed && userpass != "") {
- frontpage = false;
- }
- var description = "";
- var hash;
- if(params.description) description = params.description;
-
- if(adminpass !== "") {
- hash = hash_pass(decrypt_string(socketid, adminpass));
- } else {
- hash = adminpass;
- }
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) {
- var obj = {
- addsongs:addsongs,
- allvideos:allvideos,
- frontpage:frontpage,
- skip:skipping,
- vote:voting,
- removeplay:removeplay,
- shuffle:shuffling,
- longsongs:longsongs,
- adminpass:hash,
- desc: description,
- };
- if(params.userpass_changed) {
- obj["userpass"] = userpass;
- } else if (frontpage) {
- obj["userpass"] = "";
- }
- db.collection(coll).update({views:{$exists:true}}, {
- $set:obj
- }, function(err, docs){
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs[0].adminpass !== "") docs[0].adminpass = true;
- if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
- else docs[0].userpass = false;
- io.to(coll).emit("conf", docs);
- socket.emit("toast", "savedsettings");
-
- db.collection("frontpage_lists").update({_id: coll}, {$set:{
- frontpage:frontpage, accessed: get_time()}
- },
- {upsert:true}, function(err, docs){});
- });
- });
- } else {
- socket.emit("toast", "wrongpass");
- }
- });
- } else {
- socket.emit('update_required');
- }
- });
-
- socket.on('shuffle', function(msg)
- {
- if(msg.hasOwnProperty('adminpass') && msg.adminpass !== undefined && msg.adminpass !== null)
- {
-
- if(coll !== undefined) {
- try {
- coll = msg.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
-
- check_inlist(coll, guid, socket, name, offline);
- var hash;
- if(msg.adminpass === "") hash = msg.adminpass;
- else hash = hash_pass(decrypt_string(socketid, msg.adminpass));
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, msg.pass)))) {
- if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false))
- {
- db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
- if(!docs){
- send_list(coll, undefined, false, true, false, true);
- socket.emit("toast", "shuffled");
-
- return;
- }else{
- num = Math.floor(Math.random()*1000000);
- db.collection(coll).update({id:docs.id}, {$set:{added:num}});
- }
- });
- }else
- socket.emit("toast", "wrongpass");
- } else {
- socket.emit("auth_required");
- }
- });
-
- var complete = function(tot, curr){
- if(tot == curr)
- {
- send_list(coll, undefined, false, true, false);
- getNextSong(coll);
- }
- };
-
- }else
- socket.emit("toast", "wrongpass");
- });
-
- socket.on('change_channel', function(obj)
- {
- if(coll === undefined && obj !== undefined && obj.channel !== undefined){
- try {
- coll = obj.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
- left_channel(coll, guid, name, short_id, in_list, socket, true);
- });
-
- socket.on('disconnect', function()
- {
- left_channel(coll, guid, name, short_id, in_list, socket, false);
- });
-
- socket.on('disconnected', function()
- {
- left_channel(coll, guid, name, short_id, in_list, socket, false);
- });
-
- socket.on('reconnect_failed', function()
- {
- left_channel(coll, guid, name, short_id, in_list, socket, false);
- });
-
- socket.on('connect_timeout', function()
- {
- left_channel(coll, guid, name, short_id, in_list, socket, false);
- });
-
- socket.on('error', function()
- {
- left_channel(coll, guid, name, short_id, in_list, socket, false);
- });
-
- socket.on('pos', function(obj)
- {
-
- if(coll !== undefined) {
- try {
- coll = obj.channel;
- if(coll.length == 0) return;
- coll = emojiStrip(coll).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- } catch(e) {
- return;
- }
- }
-
- if(coll == "" || coll == undefined || coll == null) {
- socket.emit("update_required");
- return;
- }
-
- db.collection(coll).find({views: {$exists: true}}, function(err, docs) {
- if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == decrypt_string(socketid, obj.pass)))) {
- check_inlist(coll, guid, socket, name, offline);
- send_play(coll, socket);
- } else {
- socket.emit("auth_required");
- }
- });
- });
-});
-
-send_ping();
-
-function decrypt_string(socket_id, pw){
- try {
- /*
- var key = (new Buffer(socket_id).toString('base64')) + (new Buffer(socket_id).toString('base64'));
- key = key.substring(0,32);
- var decrypted = CryptoJS.AES.decrypt(
- pw, key,
- {
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7
- }
- );
-
- return decrypted.toString(CryptoJS.enc.Utf8);*/
- var input = pw.split("$");
- pw = input[0];
- var testKey = ((new Buffer(socket_id).toString('base64')) + (new Buffer(socket_id).toString('base64'))).substring(0,32);
- var keyNew = (new Buffer(testKey)).toString('base64');
- var encrypted = CryptoJS.enc.Base64.parse(pw);
- var key = CryptoJS.enc.Base64.parse(keyNew);
- var iv = CryptoJS.enc.Base64.parse(input[1]);
- var decrypted = CryptoJS.enc.Utf8.stringify(
- CryptoJS.AES.decrypt({
- ciphertext: encrypted
- },
- key,
- // edit: changed to Pkcs5
- {
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7,
- iv: iv,
- }));
- return decrypted;
- } catch(e) {
- return "";
- }
-}
-
-function send_ping() {
- lists = {};
- offline_users = [];
- tot_view = 0;
- db.collection("frontpage_lists").update({viewers: {$ne: 0}}, {$set: {"viewers": 0}}, {multi: true}, function(err, docs) {
- io.emit("self_ping");
- setTimeout(send_ping, 4000);
- });
-}
-
-function left_channel(coll, guid, name, short_id, in_list, socket, change)
-{
- if(lists[coll] !== undefined && contains(lists[coll], guid))
- {
- var index = lists[coll].indexOf(guid);
- if(index != -1)
- {
- lists[coll].splice(index, 1);
- db.collection("frontpage_lists").update({"_id": coll}, {$inc: {"viewers": -1}}, function() {
- socket.leave(coll);
- io.to(coll).emit("viewers", lists[coll].length);
- io.to(coll).emit('chat', {from: name, msg: " left"});
- tot_view -= 1;
- });
- }
- if(!change) {
- remove_from_array(names.names, name);
- delete names[guid];
- }
- }
- if(contains(offline_users, guid))
- {
- var index = offline_users.indexOf(guid);
- if(index != -1){
- offline_users.splice(index, 1);
- tot_view -= 1;
- }
- }
-
- remove_from_array(unique_ids, short_id);
-}
-
-function remove_from_array(array, element){
- if(contains(array, element)){
- var index = array.indexOf(element);
- if(index != -1)
- array.splice(index, 1);
- }
-}
-
-function get_name(guid){
- if(names[guid] !== undefined) return names[guid];
-
- var name = rndName(guid, 8);
- while(contains(names.names, name)){
- name = name + "_";
- }
-
- names[guid] = name;
- names.names.push(name);
- return name;
-}
-
-function change_name(name, guid, oldname){
-
- if(name.length > 9) return oldname;
-
- if(names[guid] == name) return false;
- if(contains(names.names, name)){
- return change_name(name + "_", guid, oldname);
- }else{
- return name;
- }
-}
-
-function update_frontpage(coll, id, title) {
- db.collection("frontpage_lists").update({_id: coll}, {$set: {
- id: id,
- title: title,
- accessed: get_time()}
- },{upsert: true}, function(err, returnDocs){});
-}
-
-function del(params, socket, socketid) {
- if(params.id){
- var coll = emojiStrip(params.channel).toLowerCase();
- //coll = decodeURIComponent(coll);
- coll = coll.replace("_", "");
- coll = encodeURIComponent(coll).replace(/\W/g, '');
- coll = filter.clean(coll);
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- if(docs !== null && docs.length !== 0 && docs[0].adminpass == hash_pass(decrypt_string(socketid, params.adminpass)))
- {
- db.collection(coll).find({id:params.id}, function(err, docs){
- dont_increment = true;
- if(docs[0]){
- if(docs[0].type == "suggested"){
- dont_increment = false;
- }
- db.collection(coll).remove({id:params.id}, function(err, docs){
- socket.emit("toast", "deletesong");
- io.to(coll).emit("channel", {type:"deleted", value: params.id});
- if(dont_increment) db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){});
- });
- }
- });
-
- }
- });
- }
-}
-
-function check_inlist(coll, guid, socket, name, offline)
-{
- if(!offline && coll != undefined){
- if(lists[coll] === undefined)
- {
- lists[coll] = [];
- lists[coll].push(guid);
- db.collection("frontpage_lists").update({"_id": coll}, {$inc: {"viewers": 1}}, function(){
- io.to(coll).emit("viewers", lists[coll].length);
- socket.broadcast.to(coll).emit('chat', {from: name, msg: " joined"});
-
- tot_view += 1;
- });
- }else if(!contains(lists[coll], guid))
- {
- lists[coll].push(guid);
- db.collection("frontpage_lists").update({"_id": coll}, {$inc: {"viewers": 1}}, function(){
- io.to(coll).emit("viewers", lists[coll].length);
- socket.broadcast.to(coll).emit('chat', {from: name, msg: " joined"});
- tot_view += 1;
- });
- }
- } else {
- if(!contains(offline_users, guid) && coll != undefined)
- {
- offline_users.push(guid);
- tot_view += 1;
- }
- }
-}
-
-function hash_pass(adminpass) {
- return crypto.createHash('sha256').update(adminpass).digest('base64');
-}
-
-function vote(coll, id, guid, socket, full_list, last) {
- db.collection(coll).find({id:id, now_playing: false}, function(err, docs){
- if(docs !== null && docs.length > 0 && !contains(docs[0].guids, guid))
- {
- db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:get_time()}, $push :{guids: guid}}, function(err, docs)
- {
- if((full_list && last) || (!full_list))
- socket.emit("toast", "voted");
- io.to(coll).emit("channel", {type: "vote", value: id, time: get_time()});
-
- getNextSong(coll);
- });
- }else
- {
- socket.emit("toast", "alreadyvoted");
- }
- });
-}
-
-function getNextSong(coll) {
- db.collection(coll).aggregate([{
- $match:{
- views:{
- $exists: false
- },
- type:{
- $ne: "suggested"
- }
- }
- }, {
- $sort:{
- now_playing: 1,
- votes:-1,
- added:1,
- title: 1
- }
- }, {
- $limit:1
- }], function(err, doc) {
- if(doc.length == 1) {
- io.to(coll).emit("next_song", {videoId: doc[0].id, title: doc[0].title});
- }
- });
-}
-
-
-function change_song(coll, error, id) {
- db.collection(coll).find({views:{$exists:true}}, function(err, docs){
- var startTime = docs[0].startTime;
- if(docs !== null && docs.length !== 0)
- {
- db.collection(coll).aggregate([{
- $match:{
- views:{
- $exists: false
- },
- type:{
- $ne: "suggested"
- }
- }
- }, {
- $sort:{
- now_playing: -1,
- votes:-1,
- added:1,
- title: 1
- }
- }, {
- $limit:2
- }], function(err, now_playing_doc){
- if((id && id == now_playing_doc[0].id) || !id) {
- //db.collection(coll).find({now_playing:true}, function(err, now_playing_doc){
- if(error){
- request('http://img.youtube.com/vi/'+now_playing_doc[0].id+'/mqdefault.jpg', function (err, response, body) {
- if (err || response.statusCode == 404) {
- db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
- var next_song;
- if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
- change_song_post(coll, next_song);
- io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
- db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){});
- });
- } else {
- if(skipped[coll] != get_time()){
- skipped[coll] = get_time();
- db.collection(coll).update({now_playing:true, id:id}, {
- $set:{
- now_playing:false,
- votes:0,
- guids:[]
- }
- },{multi:true}, function(err, docs){
- var next_song;
- if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
- if(docs.n >= 1) change_song_post(coll, next_song);
- });
- }
- }
- });
-
- } else if(docs[0].removeplay === true){
- db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
- var next_song;
- if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
- change_song_post(coll, next_song);
- io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
- db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){});
- });
- } else {
- if(skipped[coll] != get_time()){
- //skipped[coll] = get_time();
- db.collection(coll).update({now_playing:true, id:id}, {
- $set:{
- now_playing:false,
- votes:0,
- guids:[]
- }
- },{multi:true}, function(err, docs){
- var next_song;
- if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
- //if(docs.n >= 1)
- change_song_post(coll, next_song);
- });
- }
- }
- } else {
- return;
- }
- });
- }
- });
-}
-
-function change_song_post(coll, next_song)
-{
- db.collection(coll).aggregate([{
- $match:{
- now_playing:false,
- type:{
- $ne: "suggested"
- }
- }
- }, {
- $sort:{
- votes:-1,
- added:1,
- title: 1
- }
- }, {
- $limit:2
- }], function(err, docs){
- if(docs !== null && docs.length > 0){
- var id = docs[0].id;
- if(next_song && next_song != id) {
- if((docs.length == 2 && next_song == docs[1].id)) {
- id = docs[1].id;
- } else {
- return;
- }
- }
- db.collection(coll).update({id:id},{
- $set:{
- now_playing:true,
- votes:0,
- guids:[],
- added:get_time()
- }
- }, function(err, returnDocs){
- db.collection(coll).update({views:{$exists:true}},{
- $set:{
- startTime:get_time(),
- skips:[]
- }
- }, function(err, returnDocs){
- db.collection(coll).find({views:{$exists:true}}, function(err, conf){
- io.to(coll).emit("channel", {type: "song_change", time: get_time(), remove: conf[0].removeplay});
- send_play(coll);
- locks[coll] = false;
- update_frontpage(coll, docs[0].id, docs[0].title);
- });
- });
- });
- }
- });
-}
-
-function send_list(coll, socket, send, list_send, configs, shuffled)
-{
- db.collection(coll).find({views:{$exists:true}}, function(err, conf){
- db.collection(coll).find({views:{$exists:false}, type: {$ne: "suggested"}}, function(err, docs)
- {
- if(docs.length > 0) {
- db.collection(coll).find({now_playing: true}, function(err, np_docs) {
- if(np_docs.length == 0) {
- db.collection(coll).aggregate([{
- $match:{
- views:{
- $exists: false
- },
- type:{
- $ne: "suggested"
- }
- }
- }, {
- $sort:{
- now_playing: -1,
- votes:-1,
- added:1,
- title: 1
- }
- }, {
- $limit:1
- }], function(err, now_playing_doc){
- if(now_playing_doc[0].now_playing == false) {
- db.collection(coll).update({id:now_playing_doc[0].id}, {
- $set:{
- now_playing:true,
- votes:0,
- guids:[],
- added:get_time()
- }
- }, function(err, returnDocs){
- db.collection(coll).update({views:{$exists:true}}, {
- $set:{
- startTime: get_time(),
- skips:[]
- }
- }, function(err, returnDocs){
- update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title);
- send_list(coll, socket, send, list_send, configs, shuffled);
- });
- });
- }
- });
- } else {
- if(list_send) {
- io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
- } else if(!list_send) {
- socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
- }
- if(socket === undefined && send) {
- send_play(coll);
- } else if(send) {
- send_play(coll, socket);
- }
- }
- });
- } else {
- if(list_send) {
- io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
- } else if(!list_send) {
- socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
- }
- if(socket === undefined && send) {
- send_play(coll);
- } else if(send) {
- send_play(coll, socket);
- }
- }
- });
-
-
- if(configs)
- {
- if(conf[0].adminpass !== "") conf[0].adminpass = true;
- if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true;
- else conf[0].userpass = false;
- io.to(coll).emit("conf", conf);
- }
- });
- if(socket){
- db.collection(coll).find({type:"suggested"}).sort({added: 1}, function(err, sugg){
- socket.emit("suggested", sugg);
- });
- }
-}
-
-function send_play(coll, socket)
-{
- db.collection(coll).find({now_playing:true}, function(err, np){
- db.collection(coll).find({views:{$exists:true}}, function(err, conf){
- if(err !== null) console.log(err);
- try{
- if(get_time()-conf[0].startTime > np[0].duration){
- change_song(coll, false, np[0].id);
- }else if(conf !== null && conf !== undefined && conf.length !== 0)
- {
- if(conf[0].adminpass !== "") conf[0].adminpass = true;
- if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true;
- else conf[0].userpass = false;
- toSend = {np: np, conf: conf, time: get_time()};
- if(socket === undefined) {
- io.to(coll).emit("np", toSend);
- getNextSong(coll)
- } else {
- socket.emit("np", toSend);
- }
- }
- } catch(e){
- if(socket) {
- socket.emit("np", {});
- } else {
- io.to(coll).emit("np", {});
- }
- }
- });
- });
-}
-
-function get_time()
-{
- var d = new Date();
- var time = Math.floor(d.getTime() / 1000);
- return time;
-}
-
-function contains(a, obj) {
- try{
- var i = a.length;
- while (i--) {
- if (a[i] === obj) {
- return true;
- }
- }
- return false;
- }catch(e){
- return false;
- }
-}
-
-function rndName(seed, len) {
- var vowels = ['a', 'e', 'i', 'o', 'u'];
- consts = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y'];
- //len = 8;
- len = Math.floor(len);
- word = '';
- is_vowel = false;
- var arr;
- for (var i = 0; i < len; i++) {
- if (is_vowel) arr = vowels;
- else arr = consts;
- is_vowel = !is_vowel;
- word += arr[(seed[i%seed.length].charCodeAt()+i) % (arr.length-1)];
- }
- return word;
-}
-
-function uniqueID(seed, minlen){
- var len = minlen;
- var id = rndName(seed, minlen);
-
- while( contains(unique_ids, id) && len<=8){
- id = rndName(String(len)+id, len);
- len += 0.1; // try 10 times at each length
- }
- return id;
-}
+/* Resetting usernames, and connected users */
+db.collection("user_names").remove({"guid": {$exists: true}}, {multi: true, upsert: true}, function(err, docs){});
+db.collection("user_names").update({"_id": "all_names"}, {$set: {names: []}}, {multi: true, upsert: true}, function(err, docs){});
+db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true, upsert: true}, function(err, docs){});
+db.collection("connected_users").update({"_id": "total_users"}, {$set: {total_users: 0}}, {multi: true, upsert: true}, function(err, docs) {});
+db.collection("frontpage_lists").update({viewers: {$ne: 0}}, {$set: {"viewers": 0}}, {multi: true, upsert: true}, function(err, docs) {});