mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
3 lines
70 KiB
JavaScript
Executable File
3 lines
70 KiB
JavaScript
Executable File
!function(){function e(){var e=!0;M=$("#chan").html(),$e=B.mobilecheck();var t=B.mobilecheck()?"left":"right";if(window.onpopstate=function(e){k()},_(),"zoff.no"==window.location.hostname?add="https://zoff.no":add=window.location.hostname,void 0!==qe&&(qe.stopInterval=!1),$("ul.playlist-tabs").tabs(),$("ul.playlist-tabs-loggedIn").tabs(),$(".chatTabs").tabs(),$("#settings").sideNav({menuWidth:300,edge:t,closeOnClick:!1}),$(".collapsible").collapsible({accordion:!0}),v(de),we=$("#temp-results-container"),be=$("#empty-results-container").html(),pe=$(".not-imported-container").html(),$(".not-imported-container").empty(),$(".video-container").resizable({start:function(e,t){$("iframe").css("pointer-events","none")},stop:function(e,t){$("iframe").css("pointer-events","auto"),E.set_width($(this).width())},handles:"e",minWidth:350}),(void 0===Ae||B.mobilecheck())&&(e=!1,Ae=io.connect(""+add+":8880",ze)),0===$("#alreadychannel").length||B.mobilecheck())o(),n(),a(),i();else{$("#channel-load").css("display","none"),$("#player").css("opacity","1"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),qe.readyLooks(),He.initYoutubeControls(qe.player),He.initSlider(),qe.player.setVolume(E.get_volume()),$(".video-container").removeClass("no-opacity");var r="https://remote."+window.location.hostname+"/"+ke;$("#code-text").text(ke),$("#code-qr").attr("src","https://chart.googleapis.com/chart?chs=221x221&cht=qr&choe=UTF-8&chld=L|1&chl="+r),$("#code-link").attr("href",r)}e&&Ae.emit("list",M.toLowerCase()),/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream?(document.getElementById("search").blur(),$("#channel-load").css("display","none")):(window.onYouTubeIframeAPIReady=qe.onYouTubeIframeAPIReady,(""===qe.player||void 0===qe.player||B.mobilecheck())&&qe.loadPlayer()),B.mobilecheck()&&Ye.initiate_volume(),s(),c(),l(),B.mobilecheck()||0!==$("#alreadychannel").length||p(),B.msieversion()||Notification.requestPermission(),$(".search_input").focus(),B.sample(),$("#results").hover(function(){$("div.result").removeClass("hoverResults"),te=0},function(){}),$("#search").focus(),$("#embed-button").css("display","inline-block"),$("#embed-area").val(f(ge,me,ue)),$("#search").attr("placeholder","Find song on YouTube...")}function t(){Ae.on("connect_failed",function(){B.log("Connection Failed"),he||(he=!0,Materialize.toast("Error connecting to server, please wait..",1e8,"red lighten connect_error"))}),Ae.on("connect_error",function(){B.log("Connection Failed."),he||(he=!0,Materialize.toast("Error connecting to server, please wait..",1e8,"red lighten connect_error"))})}function o(){Ae.on("np",qe.youtube_listener)}function n(){Ae.on("get_list",function(){Ae.emit("list",M.toLowerCase())})}function a(){Ae.on("suggested",function(e){var t=!0;void 0===e.id&&(t=!1),Fe.catchUserSuggests(e,t)})}function i(){Ae.on("viewers",function(e){W=e,void 0!==Pe&&qe.getTitle(Pe,W)})}function s(){Ae.on("toast",I.toast),Ae.on("pw",I.pw),Ae.on("conf",I.conf)}function l(){Ae.on("chat.all",T.allchat),Ae.on("chat",T.channelchat)}function c(){Ae.on("channel",P.channel_function)}function d(){Ae.on("playlists",Re.frontpage_function)}function p(){Ae.on("id",L.host_listener)}function u(e){Ae.on(e,L.host_on_action)}function m(){localStorage.debug=!0}function h(){localStorage.debug=!1}function f(e,t,o){return'<embed src="https://zoff.no/embed.html#'+M.toLowerCase()+e+'" width="'+t+'px" height="'+o+'px">'}function y(e){for(var t="",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_",n=0;n<e;n++)t+=o.charAt(Math.floor(Math.random()*o.length));return t}function v(e){e?(B.log("------------------------"),B.log("Spotify is authenticated"),B.log("access_token: "+ce.access_token),B.log("token_type:"+ce.token_type),B.log("expires_in: "+ce.expires_in),B.log("------------------------"),$(".spotify_authenticated").css("display","block"),$(".spotify_unauthenticated").css("display","none")):(B.log("----------------------------"),B.log("Spotify is not authenticated"),B.log("----------------------------"),$(".spotify_authenticated").css("display","none"),$(".spotify_unauthenticated").css("display","block"))}function w(e){search_input=$(".search_input").val(),code=e.keyCode||e.which,40!=code&&38!=code&&13!=code&&39!=code&&37!=code&&17!=code&&16!=code&&225!=code&&18!=code&&(clearTimeout(_e),search_input.length<3&&$("#results").html(""),13==code?Ue.search(search_input):_e=setTimeout(function(){Ue.search(search_input)},1e3))}function _(){$("#facebook-code-link").attr("href","https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/"+M.toLowerCase()),$("#facebook-code-link").attr("onclick","window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/"+M.toLowerCase()+"', 'Share Playlist','width=600,height=300'); return false;"),$("#twitter-code-link").attr("href","http://twitter.com/intent/tweet?url=https://zoff.no/"+M.toLowerCase()+"&text=Check%20out%20this%20playlist%20"+M.toLowerCase()+"%20on%20Zöff!&via=zoffmusic"),$("#twitter-code-link").attr("onclick","window.open('http://twitter.com/intent/tweet?url=https://zoff.no/"+M.toLowerCase()+"/&text=Check%20out%20this%20playlist%20"+M.toLowerCase()+"%20on%20Zöff!&via=zoffmusic','Share Playlist','width=600,height=300'); return false;"),$("#qr-code-link").attr("href","//chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https://zoff.no/"+M.toLowerCase()+"&choe=UTF-8&chld=L%7C1"),$("#qr-code-image-link").attr("src","//chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https://zoff.no/"+M.toLowerCase()+"&choe=UTF-8&chld=L%7C1")}function k(){var e=window.location.href.split("/");"#!"==e[3].substr(0,1)||""===e[3]||5==e.length&&"#"==e[4].substr(0,1)?""===e[3]&&($("#channel-load").css("display","block"),window.scrollTo(0,0),qe.stopInterval=!0,I.display_logged_out(),I.beginning=!0,ee=!1,ie=!1,$("#embed-button").css("display","none"),$.ajax({url:"php/nochan.php",success:function(e){if(B.mobilecheck()?(Ae.removeAllListeners(),Ae.disconnect()):(Ae.removeEventListener("chat.all"),Ae.removeEventListener("chat"),Ae.removeEventListener("conf"),Ae.removeEventListener("pw"),Ae.removeEventListener("toast"),Ae.removeEventListener("channel")),document.getElementById("volume-button").removeEventListener("click",He.mute_video),document.getElementById("playpause").removeEventListener("click",He.play_pause),document.getElementById("fullscreen").removeEventListener("click",He.fullscreen),B.mobilecheck()&&(Ee="",Pe=""),$("meta[name=theme-color]").attr("content","#2D2D2D"),B.mobilecheck()){try{qe.player.destroy()}catch(e){}qe.player="",document.title="Zöff"}else $("main").append("<a id='closePlayer' title='Close Player'>X</a>"),$("#playbar").remove(),$("#playlist").remove(),$(".ui-resizable-handle").remove(),$("#main_components").remove(),$("#player").addClass("player_bottom"),$("#main-row").addClass("frontpage_modified_heights"),$("#player").css("opacity","1"),$("#video-container").removeClass("no-opacity"),$("#main-row").prepend("<div id='player_bottom_overlay' title='To Channel' class='player player_bottom'></div>");$(".drag-target").remove(),$("#sidenav-overlay").remove(),$("main").attr("class","center-align container"),$("body").attr("id",""),$("body").attr("style",""),$("header").html($($(e)[59]).html()),$($(e)[61]).insertAfter("header"),$($(e)[63]).insertAfter(".mega"),B.mobilecheck()?$("main").html($($(e)[67]).html()):$("main").append($($($(e)[67]).html())[0]),$(".page-footer").removeClass("padding-bottom-extra"),$(".page-footer").removeClass("padding-bottom-novideo"),$("#favicon").attr("href","static/images/favicon.png"),1==$("#alreadyfp").length?S():(je=!0,U=!0,S()),0===$("#alreadychannel").length&&$("head").append("<div id='alreadychannel'></div"),$("#channel-load").css("display","none")}})):(Ae.emit("change_channel"),I.beginning=!0,M=e[3].replace("#",""),$("#chan").html(B.upperFirst(M)),A=!0,Ae.emit("list",M.toLowerCase()))}function C(){$("#facebook-code-link").attr("href","https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/"),$("#facebook-code-link").attr("onclick","window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/', 'Share Zöff','width=600,height=300'); return false;"),$("#twitter-code-link").attr("href","http://twitter.com/intent/tweet?url=https://zoff.no/&text=Check%20out%20Zöff!&via=zoffmusic"),$("#twitter-code-link").attr("onclick","window.open('http://twitter.com/intent/tweet?url=https://zoff.no/&text=Check%20out%20Zöff!&via=zoffmusic','Share Playlist','width=600,height=300'); return false;"),$("#qr-code-link").attr("href","//chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https://zoff.no/&choe=UTF-8&chld=L%7C1"),$("#qr-code-image-link").attr("src","//chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https://zoff.no/&choe=UTF-8&chld=L%7C1")}function S(){var e=new Date;Re.blob_list=[],3==e.getMonth()&&1==e.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)&&Re.to_channel(t[3],!0)},De=$("#channel-list-container").html(),C();var t={secure:!0,"force new connection":!0};"zoff.no"==window.location.hostname?add="https://zoff.no":add=window.location.hostname,(void 0===Ae||B.mobilecheck())&&(Ae=io.connect(""+add+":8880",t)),(0===$("#alreadyfp").length||B.mobilecheck())&&d(),window.socket=Ae,Ae.emit("frontpage_lists"),$("#channel-load").css("display","none"),"#donation"==window.location.hash&&(window.location.hash="#",$("#donation").openModal()),localStorage.ok_cookie||Materialize.toast("We're using cookies to enhance your experience! <a class='waves-effect waves-light btn light-green' href='#' id='cookieok' style='cursor:pointer;pointer-events:all;'> ok</a>",1e4);var o=0;document.getElementById("zicon").addEventListener("click",function(){o+=10,document.getElementById("zicon").style.paddingLeft=o+"%",o>=100&&(window.location.href="http://etys.no")}),!B.mobilecheck()&&Re.winter&&Re.start_snowfall()}var I={beginning:!0,toast:function(e){switch(e){case"addedsong":e=B.rnd(["I added your song","Your song has been added","Yay, more songs!","Thats a cool song!","I added that song for you","I see you like adding songs..."]);break;case"addedplaylist":e=B.rnd(["I added the playlist","Your playlist has been added","Yay, many more songs!","Thats a cool playlist!","I added all the songs for you","I see you like adding songs.."]),document.getElementById("import").disabled=!1,$("#playlist_loader").addClass("hide"),$("#import").removeClass("hide");break;case"savedsettings":e=B.rnd(["I've saved your settings","I stored all your settings","Your settings have been stored in a safe place"]);break;case"wrongpass":e=B.rnd(["That's not the right password!","Wrong! Better luck next time...","You seem to have mistyped the password","Incorrect. Have you tried meditating?","Nope, wrong password!","Wrong password. The authorities have been notified."]),E.remove_pass(M.toLowerCase()),I.display_logged_out(),A=!0;break;case"shuffled":e=B.rnd(["♫ You stir me right round, baby. ♫","♫ Stir, stir, stir my boat ♫","I vigorously stirred your playlist!","I hope you like your list stirred, not shaken.","I shuffled your playlist with the cosmic background radiation as a seed. Enjoy.","100% randomized, for your listening pleasure!","I hope you enjoy your fresh playlist!"]);break;case"deletesong":e=B.rnd(["Your song is now in a better place...","You won't be seeing any more of that video...","EXTERMINATE! EXTERMINATE! EXTERMINATE!","I killed it with fire","Thanks for deleting that song. I didn't like it anyways...","Removed song securely."]);break;case"voted":e=B.rnd(["You voted!","You vote like a boss","Voting is the key to democracy","May you get your song to the very top!","I love that song! I vouch for you.","Only you vote that good","I like the way you vote...","Up the video goes!","Voted Zöff for president","Only 999 more to go!"]);break;case"alreadyvoted":e=B.rnd(["You can't vote twice on that song!","I see you have voted on that song before","One vote per person!","I know you want to hear your song, but have patience!","I'm sorry, but I can't let you vote twice, Dave."]);break;case"skip":e=B.rnd(["The song was skipped","I have skipped a song","Skipped to the beat","Skipmaster3000","They see me skippin', they hatin'"]);break;case"listhaspass":e=B.rnd(["I'm sorry, but you have to be an admin to do that!","Only admins can do that","You're not allowed to do that, try logging in!","I can't let you do that","Please log in to do that"]),E.remove_pass(M.toLowerCase()),I.display_logged_out(),A=!0;break;case"noskip":e=B.rnd(["Only Admins can skip songs, peasant!","You have to log in to skip songs on this channel","Try clicking the settings icon and logging in before you skip"]);break;case"alreadyskip":e=B.rnd(["Skipping is democratic, only one vote per person!","More people have to vote to skip, not just you!","Get someone else to skip too! You can't do it on yourself."]);break;case"notyetskip":e="Skipping is disabled the first 10 seconds.";break;case"correctpass":e="Correct password. You now have access to the sacred realm of The Admin.";break;case"changedpass":e="Your password has been changed!";break;case"suggested":e="Your song was suggested!";break;case"alreadyplay":e="Seems the song you want is already playing. No fooling the system!"}Materialize.toast(e,4e3)},pw:function(e){A=!1,F=e,names=["vote","addsongs","longsongs","frontpage","allvideos","removeplay","skip","shuffle"],E.set_pass(M.toLowerCase(),E.decrypt_pass(e));for(var t=0;t<names.length;t++)$("input[name="+names[t]+"]").attr("disabled",!1);$(".card-action").removeClass("hide"),$("#admin-lock").removeClass("mdi-action-lock"),$("#password").val(""),$("#password").attr("placeholder","Change channel password"),B.contains($(".playlist-tabs").attr("class").split(" "),"hide")||($(".playlist-tabs-loggedIn").removeClass("hide"),$(".playlist-tabs").addClass("hide")),B.contains($("#admin-lock").attr("class").split(" "),"mdi-action-lock-open")||$("#admin-lock").addClass("mdi-action-lock-open clickable"),$("ul.playlist-tabs-loggedIn").tabs("select_tab",$(".playlist-tabs li a.active").attr("href").substring(1))},conf:function(e){E.init(),I.set_conf(e[0]),void 0!==E.get_pass(M.toLowerCase())&&I.beginning&&""!==E.get_pass(M.toLowerCase())&&(Ae.emit("password",{password:E.crypt_pass(E.get_pass(M.toLowerCase())),channel:M.toLowerCase()}),I.beginning=!1)},pass_save:function(){A?Ae.emit("password",{password:E.crypt_pass(CryptoJS.SHA256(document.getElementById("password").value).toString()),channel:M.toLowerCase()}):Ae.emit("password",{password:E.crypt_pass(CryptoJS.SHA256(document.getElementById("password").value).toString()),channel:M.toLowerCase(),oldpass:E.crypt_pass(E.get_pass(M.toLowerCase()))})},log_out:function(){E.get_pass(M.toLowerCase())?(E.remove_pass(M.toLowerCase()),I.display_logged_out(),Materialize.toast("Logged out",4e3)):Materialize.toast("Not logged in",4e3)},display_logged_out:function(){for(A=!0,F="",names=["vote","addsongs","longsongs","frontpage","allvideos","removeplay","skip","shuffle"],document.getElementById("password").value="",te=0;te<names.length;te++)$("input[name="+names[te]+"]").attr("disabled",!0);B.contains($("#admin-lock").attr("class").split(" "),"mdi-action-lock")||$("#admin-lock").addClass("mdi-action-lock"),B.contains($(".playlist-tabs-loggedIn").attr("class").split(" "),"hide")||($(".playlist-tabs-loggedIn").addClass("hide"),$(".playlist-tabs").removeClass("hide")),0===$(".card-action").length||B.contains($(".card-action").attr("class").split(" "),"hide")||$(".card-action").addClass("hide"),"#suggestions"==$(".playlist-tabs-li a.active").attr("href")?($("ul.playlist-tabs").tabs("select_tab","wrapper"),$("ul.playlist-tabs-loggedIn").tabs("select_tab","wrapper"),$("#wrapper").removeClass("tabs_height")):$("ul.playlist-tabs").tabs("select_tab",$(".playlist-tabs-loggedIn li a.active").attr("href").substring(1)),$("#admin-lock").removeClass("mdi-action-lock-open clickable"),$("#password").attr("placeholder","Enter channel password")},save:function(){I.submitAdmin(document.getElementById("adminForm").elements)},set_conf:function(e){H=e.allvideos,longsongs=e.longsongs,names=["vote","addsongs","longsongs","frontpage","allvideos","removeplay","skip","shuffle"],""!==e.adminpass&&A?z=!0:(z=!1,!B.mobilecheck());for(var t=0;t<names.length;t++)document.getElementsByName(names[t])[0].checked=e[names[t]]===!0,$("input[name="+names[t]+"]").attr("disabled",z);z?0===$(".mdi-action-lock").length&&I.display_logged_out():z||void 0!==E.get_pass(M.toLowerCase())||(B.contains($(".playlist-tabs").attr("class").split(" "),"hide")||($(".playlist-tabs-loggedIn").removeClass("hide"),$(".playlist-tabs").addClass("hide")),$("#password").attr("placeholder","Create channel password"))},submitAdmin:function(e){voting=e.vote.checked,addsongs=e.addsongs.checked,longsongs=e.longsongs.checked,U=e.frontpage.checked,allvideos=e.allvideos.checked,removeplay=e.removeplay.checked,skipping=e.skip.checked,shuffling=e.shuffle.checked,configs=[voting,addsongs,longsongs,U,allvideos,removeplay,F,skipping,shuffling],Ae.emit("conf",configs)},hide_settings:function(){$("#settings").sideNav("hide")},shuffle:function(){Ae.emit("shuffle",void 0!==F?F:"")},get_admin:function(){return[A,z]}},T={namechange:function(e){Ae.emit("namechange",e),E.set_name(e)},removename:function(){Ae.emit("removename"),E.remove_name()},chat:function(e){e.value.length>150||(e.value.startsWith("/name ")?T.namechange(e.value.substring(6)):e.value.startsWith("/removename")?T.removename():"#all_chat"==$(".chat-tab-li a.active").attr("href")?Ae.emit("all,chat",e.value):Ae.emit("chat",e.value),e.value="")},allchat:function(e){D||":"!=e.msg.substring(0,1)||se||($("#favicon").attr("href","static/images/highlogo.png"),D=!0,O=!0,le=!0,re||T.chat_blink()),document.hidden&&$("#favicon").attr("href","static/images/highlogo.png");var t=B.intToARGB(B.hashCode(e.from));if(t.length<6)for(x=t.length;x<6;x++)t="0"+t;t=B.hexToRgb(t.substring(0,6));var o=B.rgbToHsl([t.r,t.g,t.b],!1);$("#chatall").append("<li title='"+e.channel+"''><span style='color:"+o+";'>"+e.from+"</span></li>");var n=document.createTextNode(e.msg);$("#chatall li:last")[0].appendChild(n),document.getElementById("chatall").scrollTop=document.getElementById("chatall").scrollHeight},channelchat:function(e){D||":"!=e.msg.substring(0,1)||se||($("#favicon").attr("href","static/images/highlogo.png"),O=!0,le=!0,re||T.chat_blink());var t=B.intToARGB(B.hashCode(e.from));if(t.length<6)for(x=t.length;x<6;x++)t="0"+t;t=B.hexToRgb(t.substring(0,6));var o=B.rgbToHsl([t.r,t.g,t.b],!1);$("#chatchannel").append("<li><span style='color:"+o+";'>"+e.from+"</span></li>");var n=document.createTextNode(e.msg);$("#chatchannel li:last")[0].appendChild(n),document.getElementById("chatchannel").scrollTop=document.getElementById("chatchannel").scrollHeight},chat_blink:function(){re=!0,$(".chat-link").attr("style","color: grey !important;"),setTimeout(function(){$(".chat-link").attr("style","color: white !important;"),setTimeout(function(){re&&T.chat_blink()},1e3)},1e3)}},E={conf_pass:void 0,init:function(){document.cookie=M.toLowerCase()+"=; path=/"+M.toLowerCase()+"; expires="+new Date(0).toUTCString();try{conf_arr=E.decrypt(E.getCookie("_opt"),"_opt")}catch(e){conf_arr=E.decrypt(E.create_cookie("_opt"),"_opt")}try{E.conf_pass=E.decrypt(E.getCookie(M.toLowerCase()),M.toLowerCase())}catch(e){E.conf_pass=E.decrypt(E.create_cookie(M.toLowerCase()),M.toLowerCase())}L.change_enabled(conf_arr.remote),100!=conf_arr.width&&qe.set_width(conf_arr.width),void 0!==conf_arr.name&&""!==conf_arr.name&&T.namechange(conf_arr.name)},decrypt:function(e,t){void 0===E.getCookie(t)&&(e=E.create_cookie(t));var o=CryptoJS.AES.decrypt(e,"0103060703080703080701",{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});return $.parseJSON(o.toString(CryptoJS.enc.Utf8))},decrypt_pass:function(e){var t=CryptoJS.AES.decrypt(e,Ae.id,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});return t.toString(CryptoJS.enc.Utf8)},encrypt:function(e,t){var o=JSON.stringify(e),n=CryptoJS.AES.encrypt(o,"0103060703080703080701",{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7}),a=new Date;a.setFullYear(a.getFullYear()+1),document.cookie=t+"="+n.toString()+";expires="+a.toGMTString()+";path=/;"},encrypt_string:function(e){var t=CryptoJS.AES.encrypt(e,Ae.id,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});return t.toString()},get_volume:function(){return E.decrypt(E.getCookie("_opt"),"_opt").volume},set_volume:function(e){conf_arr.volume=e,E.encrypt(conf_arr,"_opt")},create_cookie:function(e){"_opt"==e?cookie_object={volume:100,width:100,remote:!0,name:""}:cookie_object={passwords:{}};var t=JSON.stringify(cookie_object),o=CryptoJS.AES.encrypt(t,"0103060703080703080701",{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7}),n=new Date;return n.setFullYear(n.getFullYear()+1),document.cookie=e+"="+o.toString()+";expires="+n.toGMTString()+";path=/;",E.getCookie(e)},set_pass:function(e,t){E.conf_pass.passwords[e]=t,E.encrypt(E.conf_pass,e)},remove_pass:function(e){delete E.conf_pass.passwords[e],E.encrypt(E.conf_pass,e.toLowerCase())},set_name:function(e){conf_arr.name=encodeURIComponent(e).replace(/\W/g,""),E.encrypt(conf_arr,"_opt")},remove_name:function(){conf_arr.name="",E.encrypt(conf_arr,"_opt")},get_pass:function(e){if(void 0!==E.conf_pass)return E.conf_pass.passwords[e]},set_remote:function(e){conf_arr.remote=e,E.encrypt(conf_arr,"_opt")},get_remote:function(e){return conf_arr.remote},crypt_pass:function(e){var t=CryptoJS.AES.encrypt(e,Ae.id,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});return t.toString()},get_width:function(){return conf_arr.width},set_width:function(e){conf_arr.width=e,E.encrypt(conf_arr,"_opt")},getCookie:function(e){var t="; "+document.cookie,o=t.split("; "+e+"=");if(2==o.length)return o.pop().split(";").shift()}},B={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 function(t){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|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|xda|xiino/i.test(t)||/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(t.substr(0,4)))&&(e=!0)}(navigator.userAgent||navigator.vendor||window.opera),e},predicate:function(){for(var e,t,o,n=[],a=arguments.length,i=function(e,t){return e===t?0:e<t?-1:1},s=function(e,t){var o=i,n=i;return e&&(n=function(t,n){return o(e(t),e(n))}),t?function(e,t){return-1*n(e,t)}:n},l=0;l<a;l++)e=arguments[l],"string"==typeof e?(t=e,o=i):(t=e.name,o=s(e.primer,e.reverse)),n.push({name:t,cmp:o});return function(t,o){for(var i,s,l=0;l<a&&(s=0,e=n[l],i=e.name,s=e.cmp(t[i],o[i]),0===s);l++);return s}},hashCode:function(e){for(var t=0,o=0;o<e.length;o++)t=e.charCodeAt(o)+((t<<5)-t);return t},intToARGB:function(e){return(e>>24&255).toString(16)+(e>>16&255).toString(16)+(e>>8&255).toString(16)+(255&e).toString(16)},hexToRgb:function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null},pad:function(e){return e<10?"0"+Math.floor(e):Math.floor(e)},contains:function(e,t){for(var o=e.length;o--;)if(e[o]===t)return!0;return!1},sample:function(){Date.now()-K>=2*X&&(Ae.removeAllListeners(),Ae.disconnect(),Ae.connect(),qe.setup_all_listeners()),K=Date.now(),setTimeout(B.sample,X)},loadjsfile:function(e){if(J.indexOf("["+e+"]")==-1){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),J+="["+e+"]"}},msieversion:function(){var e=window.navigator.userAgent,t=e.indexOf("MSIE ");return!!(t>0||navigator.userAgent.match(/Trident.*rv\:11\./))},getRandomInt:function(e,t){return Math.floor(Math.random()*(t-e))+e},rgbToHsl:function(e,t){r=e[0],g=e[1],b=e[2],r/=255,g/=255,b/=255;var o,n,a=Math.max(r,g,b),i=Math.min(r,g,b),s=(a+i)/2;if(a==i)o=n=0;else{var l=a-i;switch(n=s>.5?l/(2-a-i):l/(a+i),a){case r:o=(g-b)/l+(g<b?6:0);break;case g:o=(b-r)/l+2;break;case b:o=(r-g)/l+4}o/=6}return s>.5&&t?s=.5:s<.65&&!t&&(s=.65),"hsl("+Math.floor(360*o)+", "+Math.floor(100*n)+"%, "+Math.floor(100*s)+"%)"},componentToHex:function(e){var t=e.toString(16);return 1==t.length?"0"+t:t},rgbToHex:function(e,t,o){return"#"+B.componentToHex(e)+B.componentToHex(t)+B.componentToHex(o)},upperFirst:function(e){return e.substring(0,1).toUpperCase()+e.substring(1).toLowerCase()},addClass:function(e,t){B.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"),e=$("#contact-form-from").val(),t=$("#contact-form-message").val(),$("#contact-container").empty(),newWindow=window.open("mailto:contact@zoff.no?Subject=Contact%20Zoff&Body="+t,"_blank"),$("#contact-container").html("Something went wrong, sorry about that. You could instead try with your own mail-client: <a title='Open in client' href='mailto:contact@zoff.no?Subject=Contact%20Zoff&Body="+t+"'>contact@zoff.no</a>"),setTimeout(function(){newWindow.close()},500))}};$(document).on("submit","#contact-form",function(e){e.preventDefault();var t=$("#contact-form-message").val(),o=$("#contact-form-from").val();B.send_mail(o,t)}),Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;e<t;e++)this[e]&&this[e].parentElement&&this[e].parentElement.removeChild(this[e])},String.prototype.startsWith=function(e,t){return t=t||0,this.indexOf(e,t)===t};var L={enabled:!0,old_id:null,host_listener:function(e){null===L.old_id?L.old_id=e:(Ae.removeAllListeners(e),ee=!1,L.old_id=e);var t="https://remote."+window.location.hostname+"/"+e;$("#code-text").text(e),$("#code-qr").attr("src","https://chart.googleapis.com/chart?chs=221x221&cht=qr&choe=UTF-8&chld=L|1&chl="+t),$("#code-link").attr("href",t),ee||(ee=!0,u(e))},host_on_action:function(e){enabled&&("volume"==e.type?($("#volume").slider("value",e.value),qe.player.setVolume(e.value),localStorage.setItem("volume",e.value),He.choose_button(e.value,!1)):"channel"==e.type?(Ae.emit("change_channel"),I.beginning=!0,M=e.value.toLowerCase(),$("#chan").html(B.upperFirst(M)),A=!0,Ae.emit("list",M.toLowerCase()),window.history.pushState("object or string","Title","/"+M.toLowerCase())):"pause"==e.type?qe.player.pauseVideo():"play"==e.type?qe.player.playVideo():"skip"==e.type&&P.skip())},change_enabled:function(e){enabled=e,document.getElementsByName("remote_switch")[0].checked=enabled}},P={empty:!1,channel_function:function(e){switch(e.type){case"list":P.populate_list(e.playlist);break;case"added":P.added_song(e.value);break;case"deleted":P.deleted_song(e.value);break;case"vote":P.voted_song(e.value,e.time);break;case"song_change":"/"!=window.location.pathname&&P.song_change(e.time)}},insertAtBeginning:function(e,t){var o=P.generateSong(e,t,!1,!0,!1);$("#wrapper").append(o)},insertAtIndex:function(e,t){var o=P.getIndexOfSong(e.id);if(!e.now_playing){var n=P.generateSong(e,t,!1,!0,!1);0===o?$("#wrapper").prepend(n):$("#wrapper > div:nth-child("+o+")").after(n)}var a=$("#wrapper").children()[o];t&&setTimeout(function(){$(a).css("height",66)},5)},populate_list:function(e){void 0===j&&(j=$("#list-song-html").html()),Ce=e,P.sortList(),$("#wrapper").empty(),B.log("---------------------------"),B.log("---------FULL PLAYLIST-----"),B.log(Ce),B.log("---------------------------"),Ce.length>1?($.each(Ce,function(e,t){t.now_playing||$("#wrapper").append(P.generateSong(t,!1,oe,!0))}),oe&&(B.mobilecheck()?$(".list-image").lazyload({}):($(".list-image").lazyload({container:$("#wrapper")}).removeClass("lazy"),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1))):(P.empty=!0,$("#wrapper").append("<span id='empty-channel-message'>The playlist is empty.</span>")),$("#settings").css("visibility","visible"),$("#settings").css("opacity","1"),$("#wrapper").css("opacity","1")},added_song:function(e){now_playing=Ce.pop(),Ce.push(e),P.sortList(),Ce.push(now_playing),$("#suggested-"+e.id).remove(),P.empty&&(P.empty=!1),$("#empty-channel-message").remove(),P.insertAtIndex(e,!0)},deleted_song:function(e){var t=P.getIndexOfSong(e),o=$("#wrapper").children()[t];try{o.style.height=0,setTimeout(function(){$("#"+e).remove(),Ce.splice(P.getIndexOfSong(e),1)},305),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1}catch(t){Ce.splice(P.getIndexOfSong(e),1),P.empty||$("#wrapper").children()[$("#wrapper").children().length-1].remove()}Ce.length<=2&&(P.empty=!0,$("#wrapper").append("<span id='empty-channel-message'>The playlist is empty.</span>")),$("#suggested-"+e).remove(),Fe.checkUserEmpty()},voted_song:function(e,t){var o=P.getIndexOfSong(e),n=Ce[o];Ce[o].votes+=1,Ce[o].added=t,P.sortList(),$("#"+e).remove(),P.insertAtIndex(n,!1)},song_change:function(e){var t=Ce.length-1;Ce[0].now_playing=!0,Ce[0].votes=0,Ce[0].guids=[],Ce[0].added=e,Ce[t].now_playing=!1,B.log("---------------------------"),B.log("---SONG ON FIRST INDEX-----"),B.log(Ce[0]),B.log("---------------------------");try{Ce.push(Ce.shift()),P.empty||$("#wrapper").children()[0].remove(),0===$("#wrapper").children().length&&(P.empty=!0,$("#wrapper").append("<span id='empty-channel-message'>The playlist is empty.</span>")),P.insertAtIndex(Ce[t-1],!1),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1}catch(e){}},vote:function(e,t){return Ae.emit("vote",{channel:M,id:e,type:t,adminpass:F}),!0},skip:function(){return Ae.emit("skip",{pass:F,id:Ee,channel:M.toLowerCase()}),!0},exportToYoutube:function(){var e="https://www.googleapis.com/youtube/v3/playlists?part=snippet";$.ajax({type:"POST",url:e,headers:{Authorization:"Bearer "+fe.access_token,"Content-Type":"application/json"},data:JSON.stringify({snippet:{title:M.toLowerCase(),description:"Playlist exported from zoff"}}),success:function(e){
|
|
var t=0,o=e.id;$.each(Ce,function(e,n){var a="https://www.googleapis.com/youtube/v3/playlistItems?part=snippet";$.ajax({type:"POST",url:a,headers:{Authorization:"Bearer "+fe.access_token,"Content-Type":"application/json"},data:JSON.stringify({snippet:{playlistId:o,resourceId:{kind:"youtube#video",videoId:n.id}}}),success:function(e){B.log("Added video: "+n.id+" to playlist id "+o),t==Ce.length-1&&(B.log("All videoes added!"),B.log("url: https://www.youtube.com/playlist?list="+o),$(".exported-list").append("<h5>Exported URL:</h5>"),$(".exported-list").append("<a target='_blank' class='btn orange exported-playlist' href='https://www.youtube.com/playlist?list="+o+"'>"+M+"</a>"),$("#playlist_loader_export").addClass("hide"),$(".exported-list-container").removeClass("hide")),t+=1}})})},error:function(e){B.log(e)}})},importOldList:function(e){var t="",o=0;playlist_url="lists/"+e+".json",Be=$.parseJSON($.ajax({type:"GET",url:playlist_url,async:!1}).responseText),$.each(Be.songs,function(e,n){t+=n.id+",",o>45&&(Ue.addVideos(t),t="",o=0),o++}),Ue.addVideos(t),document.getElementById("search").value=""},sortList:function(){Ce.sort(B.predicate({name:"votes",reverse:!0},{name:"added",reverse:!1},{name:"title",reverse:!1}))},show:function(){B.mobilecheck()||(N?(N=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.no/"+M.toLowerCase())):(N=!0,$("#toptitle").html("Zöff"),$("#chan").removeClass("bigChan"),$("#chan").html(M)))},generateSong:function(e,t,o,n,a){var i,s,l=e.id,r=e.title,c=e.votes,d="background-image:url('//img.youtube.com/vi/"+l+"/mqdefault.jpg');",p=$("<div>"+j+"</div>"),u="style";return t&&p.find("#list-song").css("height",0),A||p.find(".card-action").removeClass("hide"),1==c&&p.find(".vote-text").text("vote"),o&&(d="//img.youtube.com/vi/"+l+"/mqdefault.jpg",u="data-original"),n?(p.find(".list-votes").text(c),p.find("#list-song").attr("id",l),p.find(".vote-container").attr("title",r),i=".vote-container",s="del"):n||(p.find(".vote-text").text(e.duration),i=".add-suggested",s=a?"del_user_suggested":"del_suggested",p.find(".vote-container").attr("class","clickable add-suggested"),p.find(".add-suggested").attr("title",r),p.find("#del").attr("id",s),p.find(i).attr("data-video-title",r),p.find(i).attr("data-video-length",e.length),p.find("#list-song").attr("id","suggested-"+l),p.find(".list-image").attr("class",p.find(".list-image").attr("class").replace("list-image","list-suggested-image"))),p.find(".list-title").text(r),p.find(".list-title").attr("title",r),p.find(i).attr("data-video-id",l),p.find(".list-image").attr(u,d),p.find(".list-suggested-image").attr(u,d),p.find("#"+s).attr("data-video-id",l),p.html()},getIndexOfSong:function(e){return indexes=$.map(Ce,function(t,o){if(t.id==e)return o}),indexes[0]},scrollTop:function(){$("#wrapper").scrollTop(0)},scrollBottom:function(){$("#wrapper").scrollTop($("#wrapper")[0].scrollHeight)}},M=void 0===window.chan?$("#chan").html():window.chan,A=!0,z=0,N=!0,j=$("#list-song-html").html(),D=!1,O=!1,V="***REMOVED***",Y=!1,R=/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)?)?/,q=[],H=0,U=1,F="",J="",G=!1,W=1,Z=!1,Q=!1,X=6e3,K=Date.now(),ee=!1,te=-1,oe=!0,ne=!1,ae=!0,ie=!1,se=!1,le=!1,re=!1,ce={},de=!1,pe="",ue=300,me=600,ge="&autoplay",he=!1,fe={},ye=!1;if(void 0===localStorage.debug){var ve=!1;localStorage.debug=ve}var we,be,$e,_e,ke,Ce,q,Se,Ie,Te,xe,W,Ee,Be,Le,Pe,Me,Ae,ze={"sync disconnect on unload":!0,secure:!0,"force new connection":!0},Ne=!1,je=!1;navigator.serviceWorker?navigator.serviceWorker.register("/service-worker.js",{scope:"/"}).then(function(e){B.log(e)}).catch(function(e){console.error(e)}):B.log("Service Worker is not supported in this browser."),$().ready(function(){Ne||"/"==window.location.pathname?je||"/"!=window.location.pathname||S():e(),Ae.on("connect",function(){he&&(he=!1,$(".connect_error").fadeOut(function(){$(".connect_error").remove(),Materialize.toast("Connected!",2e3,"green lighten")}))}),t();try{Oe=$.ajax({type:"GET",url:"https://api.github.com/repos/zoff-music/zoff/commits",async:!1}).responseText,Oe=$.parseJSON(Oe),$("#latest-commit").html("Latest Commit: <br>"+Oe[0].commit.author.date.substring(0,10)+": "+Oe[0].committer.login+"<br><a href='"+Oe[0].html_url+"'>"+Oe[0].sha.substring(0,10)+"</a>: "+Oe[0].commit.message+"<br")}catch(e){B.log("Error with fetching GitHub commit info")}}),window.enable_debug=m,window.disable_debug=h,$(document).keyup(function(e){27==event.keyCode&&($("#results").html(""),B.contains($("#search-wrapper").attr("class").split(" "),"hide")||$("#search-wrapper").toggleClass("hide"),B.contains($("#song-title").attr("class").split(" "),"hide")&&$("#song-title").toggleClass("hide"),"mdi-navigation-close"==$("#search-btn i").attr("class")&&($("#search-btn i").toggleClass("mdi-navigation-close"),$("#search-btn i").toggleClass("mdi-action-search")),$("#results").toggleClass("hide"))}),$(document).on("click","#cookieok",function(){$(this).fadeOut(function(){$(this).remove(),localStorage.ok_cookie=!0})}),$(document).on("click",".connect_error",function(e){e.preventDefault(),$(this).fadeOut(function(){$(this).remove(),he=!1})}),$(document).on("click",".extra-button-search",function(e){e.preventDefault(),$("#search").val($(this).attr("data-text")),Ue.search($(this).attr("data-text"))}),$(document).on("click",".extra-button-delete",function(e){e.preventDefault(),$(this).parent().remove(),0===$(".not-imported-container").children().length&&$(".not-imported").toggleClass("hide")}),$(document).on("click","#closePlayer",function(e){e.preventDefault(),Ae.emit("change_channel");try{qe.player.destroy()}catch(e){}Ae.removeEventListener("np"),Ae.removeEventListener("id"),Ae.removeEventListener(ke),$("#alreadychannel").remove(),qe.player="",document.title="Zöff",$("#closePlayer").remove()}),$(document).on("click","#toast-container",function(){$(".toast").fadeOut(function(){$(".toast").remove()})}),$(document).on("click","#aprilfools",function(){$(".mega").css("-webkit-transform","rotate(0deg)"),$(".mega").css("-moz-transform","rotate(0deg)")}),$(document).on("keyup mouseup","#width_embed",function(){var e=$(this);me=e.val(),$("#embed-area").val(f(ge,me,ue))}),$(document).on("keyup mouseup","#height_embed",function(){var e=$(this);ue=e.val(),$("#embed-area").val(f(ge,me,ue))}),$(document).on("click",".chan-link",function(e){e.preventDefault(),Re.to_channel($(this).attr("href"),!1)}),$(document).on("click",".listen-button",function(e){""===$(".room-namer").val()&&(e.preventDefault(),Re.to_channel($(".room-namer").attr("placeholder")))}),$(document).on("submit",".channel-finder",function(e){return e.preventDefault(),Re.to_channel($(".room-namer").val()),!1}),$(document).on("submit",".channel-finder-mobile",function(e){return e.preventDefault(),Re.to_channel($("#search-mobile").val()),!1}),$(document).on("change","input[class=remote_switch_class]",function(){L.change_enabled(document.getElementsByName("remote_switch")[0].checked),E.set_remote(enabled)}),$(document).on("change","input[class=conf]",function(){I.save()}),$("#clickme").click(function(){qe.player.playVideo()}),$(document).on("click","#listExport",function(e){if(e.preventDefault(),B.log(Ce),$("#playlist_loader_export").removeClass("hide"),$(".youtube_export_button").addClass("hide"),ye)P.exportToYoutube();else{var t=y(29);window.callback=function(e){fe=e,fe.state==t?(ye=!0,setTimeout(function(){ye=!1,fe={}},1e3*fe.expires_in),P.exportToYoutube()):(fe="",console.error("Nonce doesn't match")),youtube_window.close(),window.callback=""},youtube_window=window.open("/o_callback#youtube=true&nonce="+t,"","width=600, height=600")}}),$(document).on("click","#listExportSpotify",function(e){e.preventDefault(),B.log(Ce)}),$(document).on("submit","#listImport",function(e){e.preventDefault();var t=$("#import").val().split("https://www.youtube.com/playlist?list=");""!==$("#import").val()&&2==t.length?(Ue.importPlaylist(t[1]),document.getElementById("import").value="",document.getElementById("import").disabled=!0,$("#import").addClass("hide"),$("#playlist_loader").removeClass("hide")):Materialize.toast("It seems you've entered a invalid url.",4e3),document.getElementById("import").value=""}),$(document).on("submit","#listImportSpotify",function(e){if(e.preventDefault(),de&&""!==$("#import_spotify").val()){var t=$("#import_spotify").val().split("https://open.spotify.com/user/");if(2==t.length){t=t[1].split("/");var o=t[0],n=t[2];document.getElementById("import_spotify").disabled=!0,$("#import_spotify").addClass("hide"),$("#playlist_loader_spotify").removeClass("hide"),Ue.importSpotifyPlaylist("https://api.spotify.com/v1/users/"+o+"/playlists/"+n+"/tracks")}else Materialize.toast("It seems you've entered a invalid url.",4e3)}document.getElementById("import_spotify").value=""}),$(window).focus(function(){$("#favicon").attr("href","static/images/favicon.png"),O=!1}),$(document).on("change","#autoplay",function(){ge=this.checked?"&autoplay":"",$("#embed-area").val(f(ge,me,ue))}),$(document).on("click","#playbutton_remote",function(e){e.preventDefault(),Ye.play_remote()}),$(document).on("click","#pausebutton_remote",function(e){e.preventDefault(),Ye.pause_remote()}),$(document).on("click","#skipbutton_remote",function(e){e.preventDefault(),Ye.skip_remote()}),$(document).on("submit","#remoteform",function(e){e.preventDefault(),Ye.get_input($("#remote_channel").val())}),$(document).on("click","#chat-btn",function(){$("#text-chat-input").focus(),$("#chat-btn i").css("opacity",1),clearInterval(Se),D=!1,O=!1,$("#favicon").attr("href","static/images/favicon.png")}),/iPad|iPhone|iPod/.test(navigator.userAgent)?$(document).on("keydown",".search_input",function(e){w(e)}):$(document).on("keyup",".search_input",function(e){w(e)}),$(document).on("click",".chat-tab",function(){$("#text-chat-input").focus()}),$(document).on("click","#skip",function(e){e.preventDefault(),P.skip()}),$(document).on("click","#chan",function(e){e.preventDefault(),P.show()}),$(document).on("submit","#adminForm",function(e){e.preventDefault(),I.pass_save()}),$(document).on("click",".chat-link",function(e){se=!0,O=!1,le=!1,$(".chat-link").attr("style","color: white !important;"),re=!1,$("#favicon").attr("href","static/images/favicon.png"),$("#chatPlaylist").css("display","block"),$("#wrapper").css("display","none"),$("#suggestions").css("display","none"),$("#text-chat-input").focus()}),$(document).on("click",".playlist-link",function(e){se=!1,$("#chatPlaylist").css("display","none"),$("#wrapper").css("display","block"),$("#suggestions").css("display","none")}),$(document).on("click",".suggested-link",function(e){se=!1,$("#chatPlaylist").css("display","none"),$("#wrapper").css("display","none"),$("#suggestions").css("display","block")}),$(document).on("click",".import-spotify-auth",function(e){e.preventDefault();var t=y(29);window.callback=function(e){ce=e,ce.state==t?(de=!0,v(!0),setTimeout(function(){de=!1,ce={},v(!1),$(".spotify_authenticated").css("display","none"),$(".spotify_unauthenticated").css("display","block")},1e3*ce.expires_in)):(ce={},console.error("States doesn't match")),spotify_window.close(),window.callback=""},spotify_window=window.open("/o_callback#spotify=true&nonce="+t,"","width=600, height=600")}),$(document).on("click",".import-youtube",function(e){e.preventDefault(),$(".youtube_unclicked").css("display","none"),$(".youtube_clicked").css("display","block")}),$(document).on("submit","#chatForm",function(e){e.preventDefault(),T.chat(document.getElementById("chatForm").input)}),$(document).on("click","#shuffle",function(e){e.preventDefault(),I.shuffle()}),$(document).on("click","#search-btn",function(e){e.preventDefault(),Ue.showSearch()}),$(document).on("click","#song-title",function(e){e.preventDefault(),Ue.showSearch()}),$(document).on("click","#admin-lock",function(e){e.preventDefault(),I.log_out()}),$(document).on("click","#closeSettings",function(e){e.preventDefault(),I.hide_settings()}),$(document).on("click",".result-object",function(e){var t=$(e.target),o=t.prop("outerHTML").substring(0,4);if("<i c"!=o){var n=$(this).attr("data-video-id"),a=$(this).attr("data-video-title"),i=$(this).attr("data-video-length");Ue.submitAndClose(n,a,i)}}),$(document).on("click","#add-many",function(e){var t=$(this).attr("data-video-id"),o=$(this).attr("data-video-title"),n=$(this).attr("data-video-length");Ue.submit(t,o,n)}),$(document).on("click",".vote-container",function(e){var t=$(this).attr("data-video-id");P.vote(t,"pos")}),$(document).on("click","#del",function(e){var t=$(this).attr("data-video-id");P.vote(t,"del")}),$(document).on("click",".add-suggested",function(e){var t=$(this).attr("data-video-id"),o=$(this).attr("data-video-title"),n=$(this).attr("data-video-length");Ue.submit(t,o,n),$("#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(),P.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","/"),k()}),$(document).on("click","#player_bottom_overlay",function(){Re.to_channel(M.toLowerCase(),!1)}),$(document).on("mousemove","#playlist",function(e){var t=e.pageY-this.offsetTop;t<=80&&t>=48&&$("#wrapper").scrollTop()>0?($("#top-button").removeClass("hide"),B.addClass("#bottom-button","hide")):t>=$("#playlist").height()-18&&$("#wrapper").scrollTop()<$("#wrapper")[0].scrollHeight-$("#wrapper").height()-1?($("#bottom-button").removeClass("hide"),B.addClass("#top-button","hide")):(B.addClass("#bottom-button","hide"),B.addClass("#top-button","hide"))}),$(document).on("mouseleave","#playlist",function(){B.addClass("#bottom-button","hide"),B.addClass("#top-button","hide")}),$(document).on("click","#top-button",function(){P.scrollTop()}),$(document).on("click","#bottom-button",function(){P.scrollBottom()});var De,Oe,Ae,Ve,Ye={id:"",get_input:function(e){""===Ye.id?Ye.set_id(e.toLowerCase()):Ye.set_channel(e.toLowerCase())},set_id:function(e){Ye.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","block")},set_channel:function(e){Ae.emit("id",{id:Ye.id,type:"channel",value:e})},play_remote:function(){Ae.emit("id",{id:Ye.id,type:"play",value:"mock"})},pause_remote:function(){Ae.emit("id",{id:Ye.id,type:"pause",value:"mock"})},skip_remote:function(){Ae.emit("id",{id:Ye.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){Ae.emit("id",{id:Ye.id,type:"volume",value:t.value}),B.log("volume")}})}},U=!0,Re={blob_list:[],winter:!1,times_rotated:0,frontpage_function:function(e){$("#channels").empty(),U=!0,Re.populate_channels(e.channels),Re.set_viewers(e.viewers)},populate_channels:function(e){var t,o="",n=0;1==e[0][5]&&(t=e.shift()),e.sort(Re.sortFunction),void 0!==t&&e.unshift(t),pre_card=$(De),B.mobilecheck()||Re.add_backdrop(e,0);for(var a in e){var i=e[a][3];if(n<12){var s=e[a][1],l=e[a][0],r="background-image:url('https://img.youtube.com/vi/"+s+"/hqdefault.jpg');",c=e[a][4],d=pre_card;1==e[a][5]?(d.find(".pin").attr("style","display:block;"),d.find(".card").attr("title","Pinned!")):(d.find(".pin").attr("style","display:none;"),d.find(".card").attr("title","")),d.find(".chan-name").text(i),d.find(".chan-name").attr("title",i),d.find(".chan-views").text(l),d.find(".chan-songs").text(c),d.find(".chan-bg").attr("style",r),d.find(".chan-link").attr("href",i),$("#channels").append(d.html())}o+="<option value='"+i+"'> ",n++}document.getElementById("preloader").style.display="none",document.getElementById("searches").innerHTML=o,$("#channels").fadeIn(800),$("#searchFrontpage").focus()},sortFunction:function(e,t){var o=e[0],n=t[0],a=e[4],i=t[4];return o<n?1:o>n?-1:a<i?1:a>i?-1:0},getCookie:function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var a=o[n];" "==a.charAt(0);)a=a.substring(1);if(0===a.indexOf(t))return a.substring(t.length,a.length)}return""},add_backdrop:function(e,t){(t>=e.length||t>=8)&&(t=0);var o=e[t][1];if(void 0!==Re.blob_list[t])setTimeout(function(){U&&($("#mega-background").css("background","url(data:image/png;base64,"+Re.blob_list[t]+")"),$("#mega-background").css("background-size","200%"),$("#mega-background").css("opacity",1),$("#searchFrontpage").attr("placeholder",e[t][3]))},500);else{var n=new Image;n.src="/static/images/thumbnails/"+o+".jpg",n.onerror=function(){$.ajax({type:"POST",data:{id:o},url:"/php/imageblob.php",success:function(o){Re.blob_list.push(o),setTimeout(function(){$("#mega-background").css("background","url(data:image/png;base64,"+o+")"),$("#mega-background").css("background-size","200%"),$("#mega-background").css("opacity",1),$("#searchFrontpage").attr("placeholder",e[t][3])},500)}})},n.onload=function(){$("#mega-background").css("background","url("+n.src+")"),$("#mega-background").css("background-size","200%"),$("#mega-background").css("opacity",1),$("#searchFrontpage").attr("placeholder",e[t][3])}}Ve=setTimeout(function(){50==Re.times_rotated&&U?(Re.times_rotated=0,t=0,Ae.emit("frontpage_lists")):U&&(Re.times_rotated+=1,Re.add_backdrop(e,t+1))},6e3)},start_snowfall:function(){setTimeout(function(){var e=Math.floor(Math.random()*window.innerWidth+1),t=document.createElement("div"),o=document.getElementsByClassName("mega")[0];t.className="snow",t.style.left=e+"px",t.style.top="0px",o.appendChild(t),Re.fall_snow(t),Re.start_snowfall()},800)},fall_snow:function(e){e.style.top=parseInt(e.style.top.replace("px",""))+2+"px",parseInt(e.style.top.replace("px",""))<document.getElementById("mega-background").offsetHeight-2.5?setTimeout(function(){Re.fall_snow(e)},50):e.remove()},set_viewers:function(e){if(e>0){var t=e>1?"listeners":"listener";$("#frontpage-viewer-counter").html(e+" "+t)}},to_channel:function(t,o){$("#channel-load").css("display","block"),window.scrollTo(0,0),U=!1,clearTimeout(Ve),B.mobilecheck()&&Ae.removeAllListeners(),$("body").css("background-color","#2d2d2d"),$.ajax({url:t+"/php/index.php",success:function(n){if(""!==qe.player&&Ae.emit("change_channel",{channel:M.toLowerCase()}),$("#frontpage_player").empty(),B.mobilecheck()&&Ae.disconnect(),o||(window.history.pushState("to the channel!","Title","/"+t),window.chan=t),$(".mega").remove(),$(".mobile-search").remove(),$("main").attr("class","container center-align main"),$("body").attr("id","channelpage"),$("header").html($($(n)[59]).html()),0===$("#alreadychannel").length||B.mobilecheck()||void 0===qe.player)$("main").html($($(n)[63]).html());else{var a=$($($($($(n)[63]).html())[0]).html());$("#main-row").append($(a[2]).wrap("<div>").parent().html()),$("#video-container").append($($($(a[0]).html())[4]).wrap("<div>").parent().html()),$("#main-row").append("<div id='playbar'></div>"),$("#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"),1==$("#alreadychannel").length?e():(Ne=!0,e()),0===$("#alreadyfp").length&&$("head").append("<div id='alreadyfp'></div>")}})}};String.prototype.capitalizeFirstLetter=function(){return this.charAt(0).toUpperCase()+this.slice(1)};var qe={loaded:!0,before_load:"",after_load:"",player:"",stopInterval:!1,youtube_listener:function(e){qe.loaded=!1,B.log("--------youtube_listener--------"),B.log("Received: "),B.log(e),B.log("paused variable: "+Z),B.log("mobile_beginning variable: "+$e);try{B.log("getVideoUrl(): "+qe.player.getVideoUrl().split("v=")[1])}catch(e){}if(B.log("video_id variable: "+Ee),B.log("---------------------------------"),e.np){void 0===Me?Me=e.np[0].id:Me!=Ee&&(Me=Ee),Ee=e.np[0].id,q=e.conf[0],time=e.time,Le=time-q.startTime,Pe=e.np[0].title,duration=e.np[0].duration,$e&&B.mobilecheck()&&0===Le&&(Le=1);try{Ce[0].id==Ee&&P.song_change(Ce[0].added),Fe.fetchYoutubeSuggests(Ee)}catch(e){}if(qe.getTitle(Pe,W),qe.setBGimage(Ee),G&&!window.MSStream)try{qe.player.getVideoUrl().split("v=")[1]!=Ee&&(qe.player.loadVideoById(Ee),qe.notifyUser(Ee,Pe),qe.player.seekTo(Le),Z&&qe.player.pauseVideo()),Z||($e||qe.player.playVideo(),ie||qe.durationSetter()),(qe.player.getDuration()>Le||0===qe.player.getDuration())&&qe.player.seekTo(Le),qe.after_load=Ee,qe.loaded||setTimeout(function(){qe.loaded=!0},500)}catch(e){ie||qe.durationSetter()}else qe.getTitle(Pe,W)}else{document.getElementById("song-title").innerHTML="Empty channel. Add some songs!",$("#player_overlay").height($("#player").height()),window.MSStream||$("#player_overlay").toggleClass("hide");try{qe.player.stopVideo()}catch(e){}}},onPlayerStateChange:function(e){B.log("-------onPlayerStateChange------"),B.log("New state\nState: "),B.log(e);try{B.log("Duration: "+qe.player.getDuration(),"Current time: "+qe.player.getCurrentTime()),B.log("getVideoUrl(): "+qe.player.getVideoUrl().split("v=")[1])}catch(e){}switch(B.log("video_id variable: "+Ee),B.log("---------------------------------"),e.data){case-1:break;case 0:Q=!1,Z=!1,Ae.emit("end",{id:Ee,channel:M.toLowerCase()});break;case 1:Q=!0,beginning&&B.mobilecheck()&&(qe.player.pauseVideo(),beginning=!1,$e=!1),ne||"/"==window.location.pathname||B.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")),Z&&(Ae.emit("pos",{channel:M.toLowerCase()}),Z=!1);break;case 2:Z=!0,"/"!=window.location.pathname&&He.play_pause_show(),$e=!0;break;case 3:}},getTitle:function(e,t){var o=t>1?"viewers":"viewer",n=decodeURIComponent(e);if("/"!=window.location.pathname){var a=document.getElementById("song-title"),i=document.getElementById("viewers");a.innerHTML=n,i.innerHTML=t+" "+o,a.title=n}document.title=n+" • Zöff / "+M},errorHandler:function(e){5==e.data||100==e.data||101==e.data||150==e.data?(curr_playing=qe.player.getVideoUrl().replace("https://www.youtube.com/watch?v=",""),Ae.emit("skip",{error:e.data,id:Ee,pass:F,channel:M.toLowerCase})):void 0!==Ee&&qe.player.loadVideoById(Ee)},onPlayerReady:function(e){$("#channel-load").css("display","none");try{beginning=!0,G=!0,window.MSStream||($("#player").css("opacity","1"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),qe.player.loadVideoById(Ee),ae&&!B.mobilecheck()&&qe.player.playVideo(),ie||qe.durationSetter(),ne?setTimeout(function(){qe.player.seekTo(Le),ae||(qe.player.pauseVideo(),He.play_pause_show())},1e3):qe.player.seekTo(Le)),qe.readyLooks(),He.initYoutubeControls(qe.player),He.initSlider(),qe.player.setVolume(E.get_volume()),$(".video-container").removeClass("no-opacity")}catch(e){}},readyLooks:function(){qe.setBGimage(Ee)},setBGimage:function(e){if(void 0!==e&&!ne){var t=new Image;t.onload=function(){var e=new ColorThief,o=e.getColor(t);"/"!=window.location.pathname&&(document.getElementsByTagName("body")[0].style.backgroundColor=B.rgbToHsl(o,!0),$("meta[name=theme-color]").attr("content",B.rgbToHex(o[0],o[1],o[2])))},t.crossOrigin="Anonymous",t.src="https://zoff.no:8080/https://img.youtube.com/vi/"+e+"/mqdefault.jpg"}},set_width:function(e){$(".video-container").width(e)},notifyUser:function(e,t){if(t=t.replace(/\\\'/g,"'").replace(/"/g,"'").replace(/&/g,"&"),"granted"===Notification.permission&&document.hidden){var o=new Notification("Now Playing",{body:t,icon:"http://i.ytimg.com/vi/"+e+"/mqdefault.jpg",iconUrl:"http://i.ytimg.com/vi/"+e+"/mqdefault.jpg"});o.onclick=function(e){window.focus(),this.cancel()},setTimeout(function(){o.close()},5e3)}},setup_all_listeners:function(){n(),o(),s(),l(),c()},onYouTubeIframeAPIReady:function(){qe.player=new YT.Player("player",{videoId:Ee,playerVars:{rel:"0",wmode:"transparent",controls:"0",iv_load_policy:"3",theme:"light",color:"white",showinfo:0},events:{onReady:qe.onPlayerReady,onStateChange:qe.onPlayerStateChange,onError:qe.errorHandler}})},durationSetter:function(){if(void 0!==duration)try{qe.stopInterval||(ie=!0),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=void 0!==qe.player.getCurrentTime()?Math.floor(qe.player.getCurrentTime()):Le,currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=B.pad(minutes)+":"+B.pad(seconds)+" <span id='dash'>/</span> "+B.pad(dMinutes)+":"+B.pad(dSeconds),per=100/duration*currDurr,per>=100?per=100:0===duration&&(per=0),$("#bar").width(per+"%")}catch(e){}qe.stopInterval||setTimeout(qe.durationSetter,1e3)},loadPlayer:function(){if(1==$("script[src='https://www.youtube.com/iframe_api']").length)try{qe.onYouTubeIframeAPIReady()}catch(e){console.error("Seems YouTube iFrame script isn't correctly loaded. Please reload the page.")}else Ie=document.createElement("script"),Ie.src="https://www.youtube.com/iframe_api",Te=document.getElementsByTagName("script")[0],Te.parentNode.insertBefore(Ie,Te)}},He={stopInterval:!1,initYoutubeControls:function(){!B.mobilecheck()||/iPad|iPhone|iPod/.test(navigator.userAgent)||window.MSStream||$("#controls").appendTo("#playbar"),He.initControls()},initControls:function(){document.getElementById("volume-button").addEventListener("click",He.mute_video),document.getElementById("playpause").addEventListener("click",He.play_pause),document.getElementById("fullscreen").addEventListener("click",He.fullscreen)},initSlider:function(){try{vol=E.get_volume()}catch(e){}$("#volume").slider({min:0,max:100,value:vol,range:"min",animate:!0,slide:function(e,t){He.setVolume(t.value);try{E.set_volume(t.value)}catch(e){}}}),He.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(){1==qe.player.getPlayerState()?(qe.player.pauseVideo(),!B.mobilecheck()||/iPad|iPhone|iPod/.test(navigator.userAgent)||window.MSStream||(document.getElementById("player").style.display="none",$(".video-container").toggleClass("click-through"),$(".page-footer").toggleClass("padding-bottom-extra"))):2!=qe.player.getPlayerState()&&0!==qe.player.getPlayerState()||(qe.player.playVideo(),!B.mobilecheck()||/iPad|iPhone|iPod/.test(navigator.userAgent)||window.MSStream||(document.getElementById("player").style.display="block",$(".video-container").toggleClass("click-through"),$(".page-footer").toggleClass("padding-bottom-extra")))},play_pause_show:function(){1==document.getElementById("pause").className.split(" ").length&&$("#pause").toggleClass("hide"),2==document.getElementById("play").className.split(" ").length&&$("#play").toggleClass("hide")},settings:function(){$("#qS").toggleClass("hide")},changeQuality:function(e){qe.player.getPlaybackQuality!=e&&(qe.player.setPlaybackQuality(e),qe.player.getPlaybackQuality()),$("#qS").toggleClass("hide")},mute_video:function(){qe.player.isMuted()?(qe.player.unMute(),He.choose_button(qe.player.getVolume(),!1)):(He.choose_button(0,!0),qe.player.mute())},setVolume:function(e){qe.player.setVolume(e),He.choose_button(e,!1),qe.player.isMuted()&&qe.player.unMute()},choose_button:function(e,t){t?(1==document.getElementById("v-full").className.split(" ").length&&$("#v-full").toggleClass("hide"),1==document.getElementById("v-medium").className.split(" ").length&&$("#v-medium").toggleClass("hide"),1==document.getElementById("v-low").className.split(" ").length&&$("#v-low").toggleClass("hide"),2==document.getElementById("v-mute").className.split(" ").length&&$("#v-mute").toggleClass("hide")):e>=0&&e<=33?(1==document.getElementById("v-full").className.split(" ").length&&$("#v-full").toggleClass("hide"),1==document.getElementById("v-medium").className.split(" ").length&&$("#v-medium").toggleClass("hide"),2==document.getElementById("v-low").className.split(" ").length&&$("#v-low").toggleClass("hide"),1==document.getElementById("v-mute").className.split(" ").length&&$("#v-mute").toggleClass("hide")):e>=34&&e<=66?(1==document.getElementById("v-full").className.split(" ").length&&$("#v-full").toggleClass("hide"),2==document.getElementById("v-medium").className.split(" ").length&&$("#v-medium").toggleClass("hide"),1==document.getElementById("v-low").className.split(" ").length&&$("#v-low").toggleClass("hide"),1==document.getElementById("v-mute").className.split(" ").length&&$("#v-mute").toggleClass("hide")):e>=67&&e<=100&&(2==document.getElementById("v-full").className.split(" ").length&&$("#v-full").toggleClass("hide"),1==document.getElementById("v-medium").className.split(" ").length&&$("#v-medium").toggleClass("hide"),1==document.getElementById("v-low").className.split(" ").length&&$("#v-low").toggleClass("hide"),1==document.getElementById("v-mute").className.split(" ").length&&$("#v-mute").toggleClass("hide"))},playPause:function(){state=qe.player.getPlayerState(),button=document.getElementById("playpause"),1==state?qe.player.pauseVideo():2==state&&qe.player.playVideo()},volumeOptions:function(){qe.player.isMuted()?(qe.player.unMute(),vol=qe.player.getVolume(),$("#volume").slider("value",qe.player.getVolume())):(qe.player.mute(),$("#volume").slider("value",0))},hoverMute:function(e){vol=qe.player.getVolume()}},Ue={submitArray:[],submitArrayExpected:null,showSearch:function(){$("#search-wrapper").toggleClass("hide"),B.mobilecheck()&&$(".search_input").focus(),$("#song-title").toggleClass("hide"),$("#results").toggleClass("hide"),$("#results").empty(),$("#search-btn i").toggleClass("mdi-navigation-close"),$("#search-btn i").toggleClass("mdi-action-search"),$("#search").focus()},search:function(e){if(void 0!==we&&void 0!==be||(we=$("#temp-results-container"),be=$("#empty-results-container").html()),$(".search_results").html(""),""!==e){Y=!0;var t=encodeURIComponent(e),o="https://www.googleapis.com/youtube/v3/search?key="+V+"&videoEmbeddable=true&part=id&fields=items(id)&type=video&order=viewCount&safeSearch=none&maxResults=25";o+="&q="+t,H&&(o+="&videoCategoryId=10");var n="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+V+"&id=";B.contains($("#search_loader").attr("class").split(" "),"hide")&&$("#search_loader").removeClass("hide"),B.contains($("#results").attr("class").split(" "),"hide")&&$("#results").removeClass("hide"),$.ajax({type:"GET",url:o,dataType:"jsonp",success:function(e){0===e.items.length?($("<div style='display:none;' id='mock-div'>"+be+"</div>").appendTo($("#results")).show("blind",83.33),B.contains($("#search_loader").attr("class").split(" "),"hide")||$("#search_loader").addClass("hide")):e.items&&($.each(e.items,function(e,t){n+=t.id.videoId+","}),$.ajax({type:"GET",url:n,dataType:"jsonp",success:function(e){var t="",o=$(we);$.each(e.items,function(e,n){var a=n.contentDetails.duration;if(secs=Ue.durationToSeconds(a),!longsongs||secs<720){xe=n.snippet.title,enc_title=xe,ke=n.id,a=a.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s"),thumb=n.snippet.thumbnails.medium.url;var i=o;i.find(".search-title").text(xe),i.find(".result_info").text(a),i.find(".thumb").attr("data-original",thumb),i.find("#add-many").attr("data-video-id",ke),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",ke),i.find("#temp-results").attr("data-video-title",enc_title),i.find("#temp-results").attr("data-video-length",secs),t+=i.html()}}),$("<div style='display:none;' id='mock-div'>"+t+"</div>").appendTo($("#results")).show("blind",83.33*(e.items.length-1)),setTimeout(function(){$(".thumb").lazyload({container:$("#results")})},250),B.contains($("#search_loader").attr("class").split(" "),"hide")||$("#search_loader").addClass("hide"),$(".add-many").click(function(e){return e.preventDefault(),e.stopPropagation(),!1})}}))}})}else $(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},backgroundSearch:function(e,t,o,n,a){var i=encodeURIComponent(e+" "+t),s="https://www.googleapis.com/youtube/v3/search?key="+V+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10";s+="&q="+i;var l="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+V+"&id=";t=t.split(" ");var r=e.split("-");r=r.join(" ").split(" "),$.ajax({type:"GET",url:s,dataType:"jsonp",success:function(a){if(0===a.items.length){Ue.readySubmit(!1,{totalLength:n-1}),B.log("------------------------------"),B.log("NO MATCH FOR:"),B.log("Spotify title: "+e+" "+t.join(" ")),B.log("Spotify length: "+o),B.log("------------------------------");var i=$("<div>"+pe+"</div>");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 a.items.length>0&&($.each(a.items,function(e,t){l+=t.id.videoId+","}),$.ajax({type:"GET",url:l,dataType:"jsonp",success:function(a){if(a.items.length>0){var i=!1;if($.each(a.items,function(o,a){var s=Ue.durationToSeconds(a.contentDetails.duration),l=!1;if($.each(r,function(o,n){return a.snippet.title.toLowerCase().indexOf(n.toLowerCase())!=-1&&a.snippet.title.toLowerCase().indexOf("cover")==-1&&e.toLowerCase().indexOf("cover")==-1&&(a.snippet.title.toLowerCase().indexOf("remix")==-1&&e.toLowerCase().indexOf("remix")==-1||a.snippet.title.toLowerCase().indexOf("remix")!=-1&&e.toLowerCase().indexOf("remix")!=-1||a.snippet.title.toLowerCase().indexOf(t[0].toLowerCase())!=-1||a.snippet.channelTitle.toLowerCase().indexOf(t[0].toLowerCase())!=-1||a.snippet.channelTitle.toLowerCase().indexOf("vevo")!=-1)||(l=!0),!1}),!l)return i=!0,Ue.readySubmit(!0,{id:a.id,title:a.snippet.title,duration:s,totalLength:n-1}),!1}),!i){Ue.readySubmit(!1,{totalLength:n-1}),B.log("------------------------------"),B.log("NO MATCH FOR:"),B.log("Spotify title: "+e+" "+t.join(" ")),B.log("Spotify length: "+o),B.log("------------------------------");var s=$("<div>"+pe+"</div>");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")}}}}))}})},readySubmit:function(e,t){null===Ue.submitArrayExpected&&(Ue.submitArrayExpected=t.totalLength),e?Ue.submitArray.push(t):Ue.submitArrayExpected-=1,Ue.submitArray.length-1==Ue.submitArrayExpected&&($.each(Ue.submitArray,function(e,t){Ue.submit(t.id,t.title,t.duration,!0,e,Ue.submitArray.length-1)}),document.getElementById("import_spotify").disabled=!1,$("#import_spotify").removeClass("hide"),$("#playlist_loader_spotify").addClass("hide"),Ue.submitArray=[],Ue.submitArrayExpected=null)},submitAndClose:function(e,t,o){Ue.submit(e,t,o,!1,0,1),$("#results").html(""),Ue.showSearch(),document.getElementById("search").value="",$("#results").html="",$(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},importPlaylist:function(e,t){token="";var o,n;void 0!==t&&(token="&pageToken="+t),playlist_url="https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+V+"&playlistId="+e+token,ye?(n="html",o={"Content-Type":"application/json",Authorization:"Bearer "+fe.access_token}):(o={},n="jsonp"),$.ajax({type:"GET",url:playlist_url,dataType:n,headers:o,success:function(o){if(o.error)if("playlistItemsNotAccessible"==o.error.errors[0].reason){var n=y(29);window.callback=function(o){fe=o,fe.state==n?(ye=!0,setTimeout(function(){ye=!1,fe={}},1e3*fe.expires_in),Ue.importPlaylist(e,t)):(fe="",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 B.log(o.error),document.getElementById("import").disabled=!1,$("#playlist_loader").addClass("hide"),$("#import").removeClass("hide"),Materialize.toast("It seems you've entered a invalid url.",4e3);else{var a="";"string"==typeof o&&(o=$.parseJSON(o)),$.each(o.items,function(e,t){a+=t.contentDetails.videoId+","}),Ue.addVideos(a,!0),o.nextPageToken&&Ue.importPlaylist(e,o.nextPageToken),document.getElementById("import").value=""}}})},importSpotifyPlaylist:function(e){$.ajax({url:e,headers:{Authorization:"Bearer "+ce.access_token},success:function(e){$.each(e.items,function(t,o){Ue.backgroundSearch(o.track.name,o.track.artists.map(function(e){return e.name}).join(" "),Math.floor(o.track.duration_ms/1e3),e.total,t+e.offset)}),e.next&&Ue.importSpotifyPlaylist(e.next)},error:function(){document.getElementById("import_spotify").disabled=!1,$("#import_spotify").removeClass("hide"),$("#playlist_loader_spotify").addClass("hide"),Materialize.toast("It seems you've entered a invalid url.",4e3)}})},addVideos:function(e,t){var o="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id=";o+=e,$.ajax({type:"POST",url:o,dataType:"jsonp",success:function(e){var o=0,n=[];$.each(e.items,function(e,a){var i=Ue.durationToSeconds(a.contentDetails.duration);(!longsongs||i<720)&&(enc_title=a.snippet.title,o+=1,n.push({id:a.id,enc_title:enc_title,duration:i,playlist:t}))}),$.each(n,function(e,t){Ue.submit(t.id,t.enc_title,t.duration,t.playlist,e,o)})}})},submit:function(e,t,o,n,a,i){Ae.emit("add",{id:e,title:decodeURIComponent(t),adminpass:F,list:M.toLowerCase(),duration:o,playlist:n,num:a,total:i})},durationToSeconds:function(e){var t=e.match(R);return hours=parseInt(t[12])||0,minutes=parseInt(t[14])||0,seconds=parseInt(t[16])||0,60*hours*60+60*minutes+seconds}},Fe={catchUserSuggests:function(e,t){if(t)Fe.createSuggested(e);else for(var o in e)Fe.createSuggested(e[o]);Fe.checkUserEmpty()},createSuggested:function(e){var t=e.duration,o=e.id,n=e.title,a=Math.floor(t/60),i=t-60*a;duration=a+"m "+i+"s";var s=P.generateSong({id:o,title:n,length:t,duration:duration},!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="+V,o="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+V+"&id=";$.ajax({type:"GET",url:t,dataType:"jsonp",success:function(e){$.each(e.items.slice(0,5),function(e,t){o+=t.id.videoId+","}),$.ajax({type:"GET",url:o,dataType:"jsonp",success:function(e){$("#suggest-song-html").empty(),$.each(e.items,function(e,t){var o=t.contentDetails.duration,n=Ue.durationToSeconds(o),a=t.id,i=t.snippet.title;o=o.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s"),$("#suggest-song-html").append(P.generateSong({id:a,title:i,length:n,duration:o},!1,!1,!1))})}})}})},checkUserEmpty:function(){var e=$("#user-suggest-html").children().length;0===e?B.contains($("#user_suggests").attr("class").split(" "),"hide")||$("#user_suggests").addClass("hide"):$("#user_suggests").removeClass("hide")}}}(); |