From 91fb7b2bc36beb804b96e4bbcd381f16ddb28a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Tue, 21 Jul 2015 21:39:11 +0200 Subject: [PATCH] Cleaned up a bunch of code, and reimplemented navigating through results with arrowkeys --- server/server.js | 7 +- static/css/style.css | 4 +- static/dist/main.min.js | 3 +- static/js/admin.js | 111 +++++++++----------- static/js/list.js | 227 ++++++++++++++++++++-------------------- static/js/listeners.js | 174 ++++++++++++++---------------- static/js/youtube.js | 61 ++++++----- 7 files changed, 285 insertions(+), 302 deletions(-) diff --git a/server/server.js b/server/server.js index 537b6383..4ecbb3ae 100755 --- a/server/server.js +++ b/server/server.js @@ -739,10 +739,11 @@ function contains(a, obj) { return false; } -function rndName(seed, endlen) { +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', 'z', 'tt', 'ch', 'sh']; - len = 8; + //len = 8; + len = Math.floor(len); word = ''; is_vowel = false; var arr; @@ -752,7 +753,7 @@ function rndName(seed, endlen) { is_vowel = !is_vowel; word += arr[(seed[i%seed.length].charCodeAt()+i) % arr.length-1]; } - return word.substring(0, Math.ceil(endlen)) + return word } function uniqueID(seed, minlen){ diff --git a/static/css/style.css b/static/css/style.css index 3e7c2f58..953fa78c 100755 --- a/static/css/style.css +++ b/static/css/style.css @@ -12,6 +12,7 @@ #toast-container{ left:2% !important; + pointer-events:none; } ::-webkit-scrollbar-track @@ -563,9 +564,10 @@ ul #chat-log{ max-height: 600px; overflow: overlay; } -.result:hover { +.result:hover, .hoverResults { background-color: rgba(0,0,0,0.4); } + .search-title{ height: 40px; } diff --git a/static/dist/main.min.js b/static/dist/main.min.js index 5f2c4163..ded3624c 100755 --- a/static/dist/main.min.js +++ b/static/dist/main.min.js @@ -1,2 +1 @@ -!function(){var e={admin_listener:function(){F.on("toast",function(t){switch(t){case"addedsong":t=o.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"savedsettings":t=o.rnd(["I've saved your settings","I stored all your settings","Your settings have been stored in a safe place"]);break;case"wrongpass":t=o.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."]),localStorage[C.toLowerCase()]&&localStorage.removeItem(C.toLowerCase()),e.display_logged_out(),I=!0;break;case"shuffled":t=o.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":t=o.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":t=o.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":t=o.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":t=o.rnd(["The song was skipped","I have skipped a song","Skipped to the beat","Skipmaster3000","They see me skippin', they hatin'"]);break;case"listhaspass":t=o.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"]);break;case"noskip":t=o.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":t=o.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":t="Skipping is disabled the first 10 seconds.";break;case"correctpass":t="Correct password. You now have access to the sacred realm of The Admin.";break;case"changedpass":t="Your password has been changed!"}Materialize.toast(t,4e3)}),F.on("pw",function(e){console.log("fuck"),I=!1,j=e,names=["vote","addsongs","longsongs","frontpage","allvideos","removeplay","skip","shuffle"];for(var t=0;t150||("#all_chat"==$(".tab a.active").attr("href")?F.emit("all,chat",e.value):F.emit("chat",e.value),e.value="")},allchat_listener:function(){F.on("chat.all",function(e){0!=$("#chat-bar").position().left?E||($("#favicon").attr("href","static/images/highlogo.png"),E=!0,B=!0,l=setInterval(t.chat_blink,2e3)):document.hidden&&($("#favicon").attr("href","static/images/highlogo.png"),B=!0);var n=o.intToARGB(o.hashCode(e[0])).substring(0,6);$("#chatall").append("
  • "+e[0]+"
  • ");var a=document.createTextNode(e[1]);$("#chatall li:last")[0].appendChild(a),document.getElementById("chatall").scrollTop=document.getElementById("chatall").scrollHeight})},setup_chat_listener:function(e){document.getElementsByClassName("chat-tab")[0].innerHTML=e,F.on("chat",function(e){0!=$("#chat-bar").position().left&&e[1].indexOf(":")>=0&&(E||($("#favicon").attr("href","static/images/highlogo.png"),E=!0,l=setInterval(t.chat_blink,2e3)));var n=o.intToARGB(o.hashCode(e[0])).substring(0,6);$("#chatchannel").append("
  • "+e[0]+"
  • ");var a=document.createTextNode(e[1]);$("#chatchannel li:last")[0].appendChild(a),document.getElementById("chatchannel").scrollTop=document.getElementById("chatchannel").scrollHeight})},chat_blink:function(){$("#chat-btn i").css("opacity",.5),setTimeout(function(){$("#chat-btn i").css("opacity",1)},1e3)}};window.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};var o={rnd:function(e){return e[Math.floor(Math.random()*e.length)]},predicate:function(){for(var e,t,o,n=[],a=arguments.length,s=function(e,t){return e===t?0:t>e?-1:1},i=function(e,t){var o=s,n=s;return e&&(n=function(t,n){return o(e(t),e(n))}),t?function(e,t){return-1*n(e,t)}:n},l=0;a>l;l++)e=arguments[l],"string"==typeof e?(t=e,o=s):(t=e.name,o=i(e.primer,e.reverse)),n.push({name:t,cmp:o});return function(t,o){for(var s,i,l=0;a>l&&(i=0,e=n[l],s=e.name,i=e.cmp(t[s],o[s]),0===i);l++);return i}},hashCode:function(e){for(var t=0,o=0;o>24&255).toString(16)+(e>>16&255).toString(16)+(e>>8&255).toString(16)+(255&e).toString(16)},pad:function(e){return 10>e?"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()-H>=2*Y&&(F.removeAllListeners(),F.disconnect(),F.connect(),K.setup_all_listeners()),H=Date.now(),setTimeout(o.sample,Y)},loadjsfile:function(e){if(-1==D.indexOf("["+e+"]")){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),D+="["+e+"]"}},msieversion:function(){var e=window.navigator.userAgent,t=e.indexOf("MSIE ");return t>0||navigator.userAgent.match(/Trident.*rv\:11\./)?!0:!1},getRandomInt:function(e,t){return Math.floor(Math.random()*(t-e))+e},rgbToHsl:function(e){r=e[0],g=e[1],b=e[2],r/=255,g/=255,b/=255;var t,o,n=Math.max(r,g,b),a=Math.min(r,g,b),s=(n+a)/2;if(n==a)t=o=0;else{var i=n-a;switch(o=s>.5?i/(2-n-a):i/(n+a),n){case r:t=(g-b)/i+(g.5&&(s=.5),"hsl("+Math.floor(360*t)+", "+Math.floor(100*o)+"%, "+Math.floor(100*s)+"%)"}};Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;t>e;e++)this[e]&&this[e].parentElement&&this[e].parentElement.removeChild(this[e])};var n,a,s,l,c,d,u,m,p,h,v,f,y,w={host_listener:function(){var e;F.on("id",function(t){void 0===e?e=t:(F.removeAllListeners(t),G=!1,e=t);var o="http://"+window.location.hostname+"/remote/"+t;$("#code-text").text(t),$("#code-qr").attr("src","https://chart.googleapis.com/chart?chs=221x221&cht=qr&choe=UTF-8&chld=L|1&chl="+o),$("#code-link").attr("href",o),G||(G=!0,F.on(t,function(e){"volume"==e[0]?($("#volume").slider("value",e[1]),u.setVolume(e[1]),localStorage.setItem("volume",e[1]),W.choose_button(e[1],!1)):"channel"==e[0]?(F.emit("change_channel"),C=e[1].toLowerCase(),$("#chan").html(C.substring(0,1).toUpperCase()+C.substring(1).toLowerCase()),I=!0,F.emit("list",C.toLowerCase()),localStorage[C.toLowerCase()]&&(64!=localStorage[C.toLowerCase()].length?localStorage.removeItem(C.toLowerCase()):F.emit("password",[localStorage[C.toLowerCase()],C.toLowerCase()])),window.history.pushState("object or string","Title","/"+C.toLowerCase())):"pause"==e[0]?u.pauseVideo():"play"==e[0]?u.playVideo():"skip"==e[0]&&k.skip()}))})}},k={channel_listener:function(){F.on("channel",function(e){k.channel_function(e)})},channel_function:function(e){if("list"==e[0])a=e[1],a.sort(o.predicate({name:"votes",reverse:!0},"added")),k.populate_list(a);else if("added"==e[0]){a.push(e[1]),a.sort(o.predicate({name:"votes",reverse:!0},"added"));var t=k.getIndexOfSong(e[1].id);k.insertAtIndex(t,e[1],!0);var n=$("#wrapper").children()[t];setTimeout(function(){$(n).css("height",66)},5)}else if("deleted"==e[0]){var s=$("#wrapper").children()[k.getIndexOfSong(e[1])];s.style.height=0,setTimeout(function(){$("#"+e[1]).remove(),a.splice(k.getIndexOfSong(e[1]),1)},305),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1}else if("vote"==e[0]){var i=k.getIndexOfSong(e[1]),l=a[i];a[i].votes+=1,a[i].added=e[2],a.sort(o.predicate({name:"votes",reverse:!0},"added")),$("#"+e[1]).remove(),k.insertAtIndex(k.getIndexOfSong(e[1]),l,!1)}else"song_change"==e[0]&&(a[0].now_playing=!0,a[0].votes=0,a[0].guids=[],a[0].added=e[1],a[a.length-1].now_playing=!1,a.push(a.shift()),$("#wrapper").children()[0].remove(),k.insertAtIndex($("#wrapper").children().length,a[a.length-2],!1),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1)},skipping_listener:function(){F.on("skipping",function(e){document.getElementById("pBar").innerHTML="Vote registrated! "+e[0]+" of "+e[1]+" has skipped. "+Math.ceil(e[1]/2)+" or more is needed!",$("#pBar").addClass("opacityFull"),setTimeout(function(){$("#pBar").removeClass("opacityFull")},1500)})},populate_list:function(e){$("#wrapper").empty(),$.each(e,function(e,t){if(!t.now_playing){var o=decodeURIComponent(t.title),n=t.id,a="//img.youtube.com/vi/"+n+"/mqdefault.jpg",s=t.votes;$("#wrapper").append(S);var i=$("#list-song");i.find(".list-title").text(o),i.find(".list-title").attr("title",o),i.find(".list-votes").text(s),i.find(".vote-container").attr("onclick","vote('"+n+"','pos')"),i.find(".list-image").attr("data-original",a),i.attr("id",n),i.find("#del").attr("onclick","vote('"+n+"', 'del')"),I||$(".card-action").removeClass("hide"),1==s&&i.find(".vote-text").text("vote")}}),window.mobilecheck()?$(".list-image").lazyload({}):$(".list-image").lazyload({container:$("#wrapper")}).removeClass("lazy"),$("#settings").css("visibility","visible"),$("#settings").css("opacity","1"),$("#wrapper").css("opacity","1")},vote:function(e,t){return F.emit("vote",[C,e,t,j]),!0},skip:function(){return F.emit("skip",[C,localStorage[C.toLowerCase()]]),!0},importOldList:function(e){playlist_url="lists/"+e+".json",n=$.ajax({type:"GET",url:playlist_url,async:!1}).responseText,n=$.parseJSON(n);var t="",o=0;$.each(n.songs,function(e,n){t+=n.id+",",o>45&&(J.addVideos(t),t="",o=0),o++}),J.addVideos(t),document.getElementById("search").value=""},show:function(){window.mobilecheck()||(T?(T=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.no/"+C.toLowerCase())):(T=!0,$("#toptitle").html("Zöff"),$("#chan").removeClass("bigChan"),$("#chan").html(C)))},insertAtIndex:function(e,t,o){return 0===e?void $("#wrapper").prepend(k.generateSong(t,o)):void $("#wrapper > div:nth-child("+e+")").after(k.generateSong(t,o))},generateSong:function(e,t){var o=e.id,n=e.title,a=e.votes,s="background-image:url('//img.youtube.com/vi/"+o+"/mqdefault.jpg');",i=$("
    "+S+"
    ");return t&&i.find("#list-song").css("height",0),i.find(".list-title").text(n),i.find(".list-title").attr("title",n),i.find(".list-votes").text(a),i.find(".vote-container").attr("onclick","vote('"+o+"','pos')"),i.find(".list-image").attr("style",s),i.find("#list-song").attr("id",o),i.find("#del").attr("onclick","vote('"+o+"', 'del')"),I||i.find(".card-action").removeClass("hide"),1==a&&i.find(".vote-text").text("vote"),i.html()},getIndexOfSong:function(e){return indexes=$.map(a,function(t,o){return t.id==e?o:void 0}),indexes[0]}},C=$("#chan").html(),I=!0,_=0,T=!0,S=$("#list-song-html").html(),E=!1,B=!1,x=0,L="***REMOVED***",M=$("#temp-results-container"),N=$("#empty-results-container").html(),A=!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)?)?/,s=[],P=0,V=1,j="",D="",O=!1,p=1,z=!1,q=!1,Y=6e3,H=Date.now(),G=!1,U={"sync disconnect on unload":!0},F=io.connect("//"+window.location.hostname+":3000",U);F.on("get_list",function(){F.emit("list",C.toLowerCase())}),$(document).ready(function(){window.vote=k.vote,window.submit=J.submit,window.submitAndClose=J.submitAndClose,localStorage.list_update&&"13.06.15"==localStorage.list_update||(localStorage.setItem("list_update","13.06.15"),window.location.reload(!0)),K.setup_youtube_listener(C),e.admin_listener(),k.channel_listener(),k.skipping_listener(),$("#settings").sideNav({menuWidth:300,edge:"right",closeOnClick:!1}),window.mobilecheck()||(t.setup_chat_listener(C),t.allchat_listener(),w.host_listener(),$("#chat-btn").sideNav({menuWidth:272,edge:"left",closeOnClick:!1}),$(".drag-target")[1].remove()),window.mobilecheck()||o.msieversion()||Notification.requestPermission(),localStorage[C.toLowerCase()]&&(64!=localStorage[C.toLowerCase()].length?localStorage.removeItem(C.toLowerCase()):F.emit("password",[localStorage[C.toLowerCase()],C.toLowerCase()])),window.mobilecheck()?(document.getElementById("search").blur(),K.readyLooks()):(K.loadPlayer(),window.onYouTubeIframeAPIReady=K.onYouTubeIframeAPIReady,navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&$(".main").height(window.innerHeight-64),git_info=$.ajax({type:"GET",url:"https://api.github.com/repos/zoff-music/zoff/commits",async:!1}).responseText,git_info=$.parseJSON(git_info),$("#latest-commit").html("Latest Commit:
    "+git_info[0].commit.author.date.substring(0,10)+": "+git_info[0].committer.login+"
    "+git_info[0].sha.substring(0,10)+": "+git_info[0].commit.message+"2)if(40==e.keyCode)i<$("div.result").length-2&&i++,$("div.result:nth-child("+(i-1)+")").removeClass("hoverResults"),$("div.result:nth-child("+i+")").addClass("hoverResults");else if(38==e.keyCode)$("div.result:nth-child("+i+")").removeClass("hoverResults"),$("div.result:nth-child("+(i-1)+")").addClass("hoverResults"),i>1&&i--;else if(13==e.keyCode){i=0;var t=document.getElementsByClassName("hoverResults")[0];"function"==typeof t.onclick&&t.onclick.apply(t),$("div.hoverResults").removeClass("hoverResults"),$("#results").html(""),document.getElementById("search").value="",$(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")}}),$("input[class=conf]").change(function(){e.save()}),$("#listImport").on("submit",function(){J.importPlaylist(document.getElementById("import").value)}),$(window).focus(function(){B&&($("#favicon").attr("href","static/images/favicon.png"),B=!1)}),document.getElementById("chat-btn").addEventListener("click",function(){$("#text-chat-input").focus(),$("#chat-btn i").css("opacity",1),clearInterval(l),E=!1,B=!1,$("#favicon").attr("href","static/images/favicon.png")}),$(".chat-tab").click(function(){$("#text-chat-input").focus()}),$("#skip").on("click",function(){k.skip()}),$("#chan").on("click",function(){k.show()}),$("#adminForm").on("submit",function(){e.pass_save()}),$("#chatForm").on("submit",function(){t.chat(document.getElementById("chatForm").input)}),$("#shuffle").on("click",function(){e.shuffle()}),$("#search-btn").on("click",function(){J.showSearch()}),$("#song-title").on("click",function(){J.showSearch()}),$("#admin-lock").on("click",function(){e.log_out()}),$("#closeSettings").on("click",function(){e.hide_settings()});var W={initYoutubeControls:function(e){setInterval(W.durationSetter,1e3),W.initControls()},initControls:function(){document.getElementById("volume-button").addEventListener("click",W.mute_video),document.getElementById("playpause").addEventListener("click",W.play_pause),document.getElementById("fullscreen").addEventListener("click",W.fullscreen)},initSlider:function(){localStorage.volume?vol=localStorage.getItem("volume"):(vol=100,localStorage.setItem("volume",vol)),$("#volume").slider({min:0,max:100,value:vol,range:"min",animate:!0,slide:function(e,t){W.setVolume(t.value),localStorage.setItem("volume",t.value)}}),W.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==u.getPlayerState()?u.pauseVideo():(2==u.getPlayerState()||0==u.getPlayerState())&&u.playVideo()},settings:function(){$("#qS").toggleClass("hide")},changeQuality:function(e){u.getPlaybackQuality!=e&&(u.setPlaybackQuality(e),u.getPlaybackQuality()),$("#qS").toggleClass("hide")},mute_video:function(){u.isMuted()?(u.unMute(),W.choose_button(u.getVolume(),!1)):(W.choose_button(0,!0),u.mute())},setVolume:function(e){u.setVolume(e),W.choose_button(e,!1),u.isMuted()&&u.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&&33>=e?(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&&66>=e?(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&&100>=e&&(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=u.getPlayerState(),button=document.getElementById("playpause"),1==state?u.pauseVideo():2==state&&u.playVideo()},durationSetter:function(){duration=u.getDuration(),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=u.getCurrentTime(),currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=o.pad(minutes)+":"+o.pad(seconds)+" / "+o.pad(dMinutes)+":"+o.pad(dSeconds),per=100/duration*currDurr,per>=100?per=100:0==duration&&(per=0),$("#bar").width(per+"%")},volumeOptions:function(){u.isMuted()?(u.unMute(),vol=u.getVolume(),$("#volume").slider("value",u.getVolume())):(u.mute(),$("#volume").slider("value",0))},hoverMute:function(e){vol=u.getVolume()}},J={showSearch:function(){$("#search-wrapper").toggleClass("hide"),window.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($(".search_results").html(""),""!==window.search_input){A=!0;var t=encodeURIComponent(window.search_input),n="https://www.googleapis.com/youtube/v3/search?key="+L+"&videoEmbeddable=true&part=id&fields=items(id)&type=video&order=viewCount&safeSearch=none&maxResults=25";n+="&q="+t,P&&(n+="&videoCategoryId=10");var a="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+L+"&id=";o.contains($("#search_loader").attr("class").split(" "),"hide")&&$("#search_loader").removeClass("hide"),o.contains($("#results").attr("class").split(" "),"hide")&&$("#results").removeClass("hide"),$.ajax({type:"GET",url:n,dataType:"jsonp",success:function(e){0==e.items.length?($("").appendTo($("#results")).show("blind",83.33),o.contains($("#search_loader").attr("class").split(" "),"hide")||$("#search_loader").addClass("hide")):e.items&&($.each(e.items,function(e,t){a+=t.id.videoId+","}),$.ajax({type:"GET",url:a,dataType:"jsonp",success:function(e){var t="",n=$(M);$.each(e.items,function(e,o){var a=o.contentDetails.duration;if(secs=J.durationToSeconds(a),!longsongs||secs<720){m=o.snippet.title,enc_title=encodeURIComponent(m).replace(/'/g,"\\'"),y=o.id,a=a.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s"),thumb=o.snippet.thumbnails.medium.url;var s=n;s.find(".search-title").text(m),s.find(".result_info").text(a),s.find(".thumb").attr("data-original",thumb),s.find(".add-many").attr("onclick","submit('"+y+"','"+enc_title+"',"+secs+");"),$($(s).find("div")[0]).attr("onclick","submitAndClose('"+y+"','"+enc_title+"',"+secs+");"),$($(s).find("div")[0]).attr("id",y),t+=s.html()}}),$("").appendTo($("#results")).show("blind",83.33*(e.items.length-1)),setTimeout(function(){$(".thumb").lazyload({container:$("#results")})},250),o.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")},submitAndClose:function(e,t,o){J.submit(e,t,o),$("#results").html(""),J.showSearch(),document.getElementById("search").value="",$("#results").html="",$(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},importPlaylist:function(e,t){token="",void 0!==t&&(token="&pageToken="+t),playlist_url="https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+L+"&playlistId="+e+token,$.ajax({type:"GET",url:playlist_url,dataType:"jsonp",success:function(t){var o="";J.addVideos(t.items[0].contentDetails.videoId),$.each(t.items,function(e,t){o+=t.contentDetails.videoId+","}),J.addVideos(o),t.nextPageToken&&J.importPlaylist(e,t.nextPageToken),document.getElementById("import").value=""}})},addVideos:function(e){var t="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id=";t+=e,$.ajax({type:"POST",url:t,dataType:"jsonp",success:function(e){$.each(e.items,function(e,t){var o=J.durationToSeconds(t.contentDetails.duration);(!longsongs||720>o)&&(enc_title=encodeURIComponent(t.snippet.title),J.submit(t.id,enc_title,o))})}})},submit:function(e,t,o){F.emit("add",[e,decodeURIComponent(t),j,o])},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}},K={setup_youtube_listener:function(e){F.on("np",function(e){if(0==e[0].length){document.getElementById("song-title").innerHTML="Empty channel. Add some songs!",$("#player_overlay").height($("#player").height()),window.mobilecheck()||$("#player_overlay").toggleClass("hide");try{u.stopVideo()}catch(t){}}else $("#player_overlay").addClass("hide"),h=e[0][0].id,s=e[1][0],time=e[2],v=time-s.startTime,f=e[0][0].title,K.getTitle(f,p),K.setBGimage(h),O&&!window.mobilecheck()?(u.getVideoUrl().split("v=")[1]!=h&&(u.loadVideoById(h),K.notifyUser(h,f),u.seekTo(v),z&&u.pauseVideo()),z||u.playVideo(),(u.getDuration()>v||0==u.getDuration())&&u.seekTo(v)):K.getTitle(f,p)}),F.on("viewers",function(e){p=e,void 0!==f&&K.getTitle(f,p)})},onPlayerStateChange:function(e){switch(e.data){case-1:break;case 0:F.emit("end",h),q=!1,z=!1;break;case 1:q=!0,1==document.getElementById("play").className.split(" ").length&&$("#play").toggleClass("hide"),2==document.getElementById("pause").className.split(" ").length&&$("#pause").toggleClass("hide"),z&&(F.emit("pos"),z=!1);break;case 2:z=!0,1==document.getElementById("pause").className.split(" ").length&&$("#pause").toggleClass("hide"),2==document.getElementById("play").className.split(" ").length&&$("#play").toggleClass("hide");break;case 3:}},getTitle:function(e,t){var o=t>1?"viewers":"viewer",n=decodeURIComponent(e),a=document.getElementById("song-title");document.title=n+" • Zöff / "+C,a.innerHTML=n,document.getElementById("viewers").innerHTML=t+" "+o,a.title=n+" • "+t+" "+o},errorHandler:function(e){5==e.data||100==e.data||101==e.data||150==e.data?F.emit("skip",e.data):void 0!==h&&u.loadVideoById(h)},onPlayerReady:function(e){O=!0,window.mobilecheck()||($("#player").css("opacity","1"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),u.loadVideoById(h),u.playVideo(),u.seekTo(v)),K.readyLooks(),W.initYoutubeControls(u),W.initSlider(),u.setVolume(localStorage.getItem("volume"))},readyLooks:function(){K.setBGimage(h)},setBGimage:function(e){if(void 0!==e){var t=new Image;t.onload=function(){var e=new ColorThief;document.getElementsByTagName("body")[0].style.backgroundColor=o.rgbToHsl(e.getColor(t))},t.crossOrigin="Anonymous",t.src="//zoff.no:8080/http://img.youtube.com/vi/"+e+"/mqdefault.jpg"}},notifyUser:function(e,t){if(t=t.replace(/\\\'/g,"'").replace(/"/g,"'").replace(/&/g,"&"),"granted"===Notification.permission&&document.hidden&&"30H2Z8Lr-4c"!=e&&!window.mobilecheck()){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(){F.on("get_list",function(){F.emit("list",C.toLowerCase())}),K.setup_youtube_listener(C),e.admin_listener(),t.setup_chat_listener(C),t.allchat_listener(),k.channel_listener(),k.skipping_listener()},onYouTubeIframeAPIReady:function(){u=new YT.Player("player",{videoId:"asd",playerVars:{rel:"0",wmode:"transparent",controls:"0",iv_load_policy:"3",theme:"light",color:"white"},events:{onReady:K.onPlayerReady,onStateChange:K.onPlayerStateChange,onError:K.errorHandler}})},loadPlayer:function(){c=document.createElement("script"),c.src="https://www.youtube.com/iframe_api",d=document.getElementsByTagName("script")[0],d.parentNode.insertBefore(c,d)}}}(); \ No newline at end of file +!function(){var e={admin_listener:function(){F.on("toast",function(t){switch(t){case"addedsong":t=o.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"savedsettings":t=o.rnd(["I've saved your settings","I stored all your settings","Your settings have been stored in a safe place"]);break;case"wrongpass":t=o.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."]),localStorage[k.toLowerCase()]&&localStorage.removeItem(k.toLowerCase()),e.display_logged_out(),C=!0;break;case"shuffled":t=o.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":t=o.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":t=o.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":t=o.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":t=o.rnd(["The song was skipped","I have skipped a song","Skipped to the beat","Skipmaster3000","They see me skippin', they hatin'"]);break;case"listhaspass":t=o.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"]);break;case"noskip":t=o.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":t=o.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":t="Skipping is disabled the first 10 seconds.";break;case"correctpass":t="Correct password. You now have access to the sacred realm of The Admin.";break;case"changedpass":t="Your password has been changed!"}Materialize.toast(t,4e3)}),F.on("pw",function(e){C=!1,P=e,names=["vote","addsongs","longsongs","frontpage","allvideos","removeplay","skip","shuffle"],localStorage.setItem(k.toLowerCase(),e);for(var t=0;t150||("#all_chat"==$(".tab a.active").attr("href")?F.emit("all,chat",e.value):F.emit("chat",e.value),e.value="")},allchat_listener:function(){F.on("chat.all",function(e){0!=$("#chat-bar").position().left?T||($("#favicon").attr("href","static/images/highlogo.png"),T=!0,E=!0,i=setInterval(t.chat_blink,2e3)):document.hidden&&($("#favicon").attr("href","static/images/highlogo.png"),E=!0);var n=o.intToARGB(o.hashCode(e[0])).substring(0,6);$("#chatall").append("
  • "+e[0]+"
  • ");var a=document.createTextNode(e[1]);$("#chatall li:last")[0].appendChild(a),document.getElementById("chatall").scrollTop=document.getElementById("chatall").scrollHeight})},setup_chat_listener:function(e){document.getElementsByClassName("chat-tab")[0].innerHTML=e,F.on("chat",function(e){0!=$("#chat-bar").position().left&&e[1].indexOf(":")>=0&&(T||($("#favicon").attr("href","static/images/highlogo.png"),T=!0,i=setInterval(t.chat_blink,2e3)));var n=o.intToARGB(o.hashCode(e[0])).substring(0,6);$("#chatchannel").append("
  • "+e[0]+"
  • ");var a=document.createTextNode(e[1]);$("#chatchannel li:last")[0].appendChild(a),document.getElementById("chatchannel").scrollTop=document.getElementById("chatchannel").scrollHeight})},chat_blink:function(){$("#chat-btn i").css("opacity",.5),setTimeout(function(){$("#chat-btn i").css("opacity",1)},1e3)}};window.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};var o={rnd:function(e){return e[Math.floor(Math.random()*e.length)]},predicate:function(){for(var e,t,o,n=[],a=arguments.length,s=function(e,t){return e===t?0:t>e?-1:1},i=function(e,t){var o=s,n=s;return e&&(n=function(t,n){return o(e(t),e(n))}),t?function(e,t){return-1*n(e,t)}:n},l=0;a>l;l++)e=arguments[l],"string"==typeof e?(t=e,o=s):(t=e.name,o=i(e.primer,e.reverse)),n.push({name:t,cmp:o});return function(t,o){for(var s,i,l=0;a>l&&(i=0,e=n[l],s=e.name,i=e.cmp(t[s],o[s]),0===i);l++);return i}},hashCode:function(e){for(var t=0,o=0;o>24&255).toString(16)+(e>>16&255).toString(16)+(e>>8&255).toString(16)+(255&e).toString(16)},pad:function(e){return 10>e?"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()-q>=2*Y&&(F.removeAllListeners(),F.disconnect(),F.connect(),Q.setup_all_listeners()),q=Date.now(),setTimeout(o.sample,Y)},loadjsfile:function(e){if(-1==j.indexOf("["+e+"]")){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\./)?!0:!1},getRandomInt:function(e,t){return Math.floor(Math.random()*(t-e))+e},rgbToHsl:function(e){r=e[0],g=e[1],b=e[2],r/=255,g/=255,b/=255;var t,o,n=Math.max(r,g,b),a=Math.min(r,g,b),s=(n+a)/2;if(n==a)t=o=0;else{var i=n-a;switch(o=s>.5?i/(2-n-a):i/(n+a),n){case r:t=(g-b)/i+(g.5&&(s=.5),"hsl("+Math.floor(360*t)+", "+Math.floor(100*o)+"%, "+Math.floor(100*s)+"%)"}};Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;t>e;e++)this[e]&&this[e].parentElement&&this[e].parentElement.removeChild(this[e])};var n,a,s,i,l,c,d,u,m,h,p,v,f,y={host_listener:function(){var e;F.on("id",function(t){void 0===e?e=t:(F.removeAllListeners(t),H=!1,e=t);var o="http://"+window.location.hostname+"/remote/"+t;$("#code-text").text(t),$("#code-qr").attr("src","https://chart.googleapis.com/chart?chs=221x221&cht=qr&choe=UTF-8&chld=L|1&chl="+o),$("#code-link").attr("href",o),H||(H=!0,F.on(t,function(e){"volume"==e[0]?($("#volume").slider("value",e[1]),d.setVolume(e[1]),localStorage.setItem("volume",e[1]),W.choose_button(e[1],!1)):"channel"==e[0]?(F.emit("change_channel"),k=e[1].toLowerCase(),$("#chan").html(k.substring(0,1).toUpperCase()+k.substring(1).toLowerCase()),C=!0,F.emit("list",k.toLowerCase()),localStorage[k.toLowerCase()]&&(64!=localStorage[k.toLowerCase()].length?localStorage.removeItem(k.toLowerCase()):F.emit("password",[localStorage[k.toLowerCase()],k.toLowerCase()])),window.history.pushState("object or string","Title","/"+k.toLowerCase())):"pause"==e[0]?d.pauseVideo():"play"==e[0]?d.playVideo():"skip"==e[0]&&w.skip()}))})}},w={channel_listener:function(){F.on("channel",function(e){w.channel_function(e)})},channel_function:function(e){switch(e[0]){case"list":w.populate_list(e[1]);break;case"added":w.added_song(e[1]);break;case"deleted":w.deleted_song(e[1]);break;case"vote":w.voted_song(e[1],e[2]);break;case"song_change":w.song_change(e[1])}},skipping_listener:function(){F.on("skipping",function(e){document.getElementById("pBar").innerHTML="Vote registrated! "+e[0]+" of "+e[1]+" has skipped. "+Math.ceil(e[1]/2)+" or more is needed!",$("#pBar").addClass("opacityFull"),setTimeout(function(){$("#pBar").removeClass("opacityFull")},1500)})},populate_list:function(e){a=e,w.sortList(),$("#wrapper").empty(),$.each(a,function(e,t){t.now_playing||$("#wrapper").append(w.generateSong(t,!1))}),window.mobilecheck()?$(".list-image").lazyload({}):$(".list-image").lazyload({container:$("#wrapper")}).removeClass("lazy"),$("#settings").css("visibility","visible"),$("#settings").css("opacity","1"),$("#wrapper").css("opacity","1")},added_song:function(e){a.push(e),w.sortList(),w.insertAtIndex(e,!0)},deleted_song:function(e){var t=w.getIndexOfSong(e),o=$("#wrapper").children()[t];o.style.height=0,setTimeout(function(){$("#"+e).remove(),a.splice(w.getIndexOfSong(e),1)},305),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1},voted_song:function(e,t){var o=w.getIndexOfSong(e),n=a[o];a[o].votes+=1,a[o].added=t,w.sortList(),$("#"+e).remove(),w.insertAtIndex(n,!1)},song_change:function(e){var t=a.length-1;a[0].now_playing=!0,a[0].votes=0,a[0].guids=[],a[0].added=e,a[t].now_playing=!1,a.push(a.shift()),$("#wrapper").children()[0].remove(),w.insertAtIndex(a[t-1],!1),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1},vote:function(e,t){return F.emit("vote",[k,e,t,P]),!0},skip:function(){return F.emit("skip",[k,localStorage[k.toLowerCase()]]),!0},importOldList:function(e){var t="",o=0;playlist_url="lists/"+e+".json",p=$.parseJSON($.ajax({type:"GET",url:playlist_url,async:!1}).responseText),$.each(p.songs,function(e,n){t+=n.id+",",o>45&&(K.addVideos(t),t="",o=0),o++}),K.addVideos(t),document.getElementById("search").value=""},sortList:function(){a.sort(o.predicate({name:"votes",reverse:!0},"added"))},show:function(){window.mobilecheck()||(_?(_=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.no/"+k.toLowerCase())):(_=!0,$("#toptitle").html("Zöff"),$("#chan").removeClass("bigChan"),$("#chan").html(k)))},insertAtIndex:function(e,t){G=w.getIndexOfSong(e.id),0===G?$("#wrapper").prepend(w.generateSong(e,t)):$("#wrapper > div:nth-child("+G+")").after(w.generateSong(e,t)),t&&setTimeout(function(){var e=$("#wrapper").children()[G];$(e).css("height",66)},5)},generateSong:function(e,t){var o=e.id,n=e.title,a=e.votes,s="background-image:url('//img.youtube.com/vi/"+o+"/mqdefault.jpg');",i=$("
    "+S+"
    ");return t&&i.find("#list-song").css("height",0),C||i.find(".card-action").removeClass("hide"),1==a&&i.find(".vote-text").text("vote"),i.find(".list-title").text(n),i.find(".list-title").attr("title",n),i.find(".list-votes").text(a),i.find(".vote-container").attr("onclick","vote('"+o+"','pos')"),i.find(".list-image").attr("style",s),i.find("#list-song").attr("id",o),i.find("#del").attr("onclick","vote('"+o+"', 'del')"),i.html()},getIndexOfSong:function(e){return indexes=$.map(a,function(t,o){return t.id==e?o:void 0}),indexes[0]}},k=$("#chan").html(),C=!0,I=0,_=!0,S=$("#list-song-html").html(),T=!1,E=!1,B=0,x="***REMOVED***",L=$("#temp-results-container"),M=$("#empty-results-container").html(),N=!1,A=/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)?)?/,s=[],R=0,V=1,P="",j="",D=!1,m=1,z=!1,O=!1,Y=6e3,q=Date.now(),H=!1,G=-1,U={"sync disconnect on unload":!0},F=io.connect("//"+window.location.hostname+":3000",U);F.on("get_list",function(){F.emit("list",k.toLowerCase())}),$(document).ready(function(){window.vote=w.vote,window.submit=K.submit,window.submitAndClose=K.submitAndClose,localStorage.list_update&&"13.06.15"==localStorage.list_update||(localStorage.setItem("list_update","13.06.15"),window.location.reload(!0)),Q.setup_youtube_listener(k),e.admin_listener(),w.channel_listener(),w.skipping_listener(),$("#settings").sideNav({menuWidth:300,edge:"right",closeOnClick:!1}),localStorage[k.toLowerCase()]&&(64!=localStorage[k.toLowerCase()].length?localStorage.removeItem(k.toLowerCase()):F.emit("password",[localStorage[k.toLowerCase()],k.toLowerCase()])),window.mobilecheck()?(document.getElementById("search").blur(),Q.readyLooks()):(t.setup_chat_listener(k),t.allchat_listener(),y.host_listener(),Q.loadPlayer(),window.onYouTubeIframeAPIReady=Q.onYouTubeIframeAPIReady,$("#chat-btn").sideNav({menuWidth:272,edge:"left",closeOnClick:!1}),$(".drag-target")[1].remove(),o.msieversion()||Notification.requestPermission(),navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&$(".main").height(window.innerHeight-64),git_info=$.ajax({type:"GET",url:"https://api.github.com/repos/zoff-music/zoff/commits",async:!1}).responseText,git_info=$.parseJSON(git_info),$("#latest-commit").html("Latest Commit:
    "+git_info[0].commit.author.date.substring(0,10)+": "+git_info[0].committer.login+"
    "+git_info[0].sha.substring(0,10)+": "+git_info[0].commit.message+"2)if(40==e.keyCode)$(children[G-1]).removeClass("hoverResults"),$(children[G]).addClass("hoverResults"),G1&&G--,$(children[G]).removeClass("hoverResults"),$(children[G-1]).addClass("hoverResults");else if(13==e.keyCode){G=0;var t=document.getElementsByClassName("hoverResults")[0];"function"==typeof t.onclick&&t.onclick.apply(t),$("div.hoverResults").removeClass("hoverResults"),$("#results").html(""),document.getElementById("search").value=""}}),$("input[class=conf]").change(function(){e.save()}),$("#listImport").on("submit",function(){K.importPlaylist(document.getElementById("import").value)}),$(window).focus(function(){E&&($("#favicon").attr("href","static/images/favicon.png"),E=!1)}),document.getElementById("chat-btn").addEventListener("click",function(){$("#text-chat-input").focus(),$("#chat-btn i").css("opacity",1),clearInterval(i),T=!1,E=!1,$("#favicon").attr("href","static/images/favicon.png")}),$(".chat-tab").click(function(){$("#text-chat-input").focus()}),$("#skip").on("click",function(){w.skip()}),$("#chan").on("click",function(){w.show()}),$("#adminForm").on("submit",function(){e.pass_save()}),$("#chatForm").on("submit",function(){t.chat(document.getElementById("chatForm").input)}),$("#shuffle").on("click",function(){e.shuffle()}),$("#search-btn").on("click",function(){K.showSearch()}),$("#song-title").on("click",function(){K.showSearch()}),$("#admin-lock").on("click",function(){e.log_out()}),$("#closeSettings").on("click",function(){e.hide_settings()});var W={initYoutubeControls:function(e){setInterval(W.durationSetter,1e3),W.initControls()},initControls:function(){document.getElementById("volume-button").addEventListener("click",W.mute_video),document.getElementById("playpause").addEventListener("click",W.play_pause),document.getElementById("fullscreen").addEventListener("click",W.fullscreen)},initSlider:function(){localStorage.volume?vol=localStorage.getItem("volume"):(vol=100,localStorage.setItem("volume",vol)),$("#volume").slider({min:0,max:100,value:vol,range:"min",animate:!0,slide:function(e,t){W.setVolume(t.value),localStorage.setItem("volume",t.value)}}),W.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==d.getPlayerState()?d.pauseVideo():(2==d.getPlayerState()||0==d.getPlayerState())&&d.playVideo()},settings:function(){$("#qS").toggleClass("hide")},changeQuality:function(e){d.getPlaybackQuality!=e&&(d.setPlaybackQuality(e),d.getPlaybackQuality()),$("#qS").toggleClass("hide")},mute_video:function(){d.isMuted()?(d.unMute(),W.choose_button(d.getVolume(),!1)):(W.choose_button(0,!0),d.mute())},setVolume:function(e){d.setVolume(e),W.choose_button(e,!1),d.isMuted()&&d.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&&33>=e?(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&&66>=e?(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&&100>=e&&(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=d.getPlayerState(),button=document.getElementById("playpause"),1==state?d.pauseVideo():2==state&&d.playVideo()},durationSetter:function(){duration=d.getDuration(),dMinutes=Math.floor(duration/60),dSeconds=duration-60*dMinutes,currDurr=d.getCurrentTime(),currDurr>duration&&(currDurr=duration),minutes=Math.floor(currDurr/60),seconds=currDurr-60*minutes,document.getElementById("duration").innerHTML=o.pad(minutes)+":"+o.pad(seconds)+" / "+o.pad(dMinutes)+":"+o.pad(dSeconds),per=100/duration*currDurr,per>=100?per=100:0==duration&&(per=0),$("#bar").width(per+"%")},volumeOptions:function(){d.isMuted()?(d.unMute(),vol=d.getVolume(),$("#volume").slider("value",d.getVolume())):(d.mute(),$("#volume").slider("value",0))},hoverMute:function(e){vol=d.getVolume()}},K={showSearch:function(){$("#search-wrapper").toggleClass("hide"),window.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($(".search_results").html(""),""!==window.search_input){N=!0;var t=encodeURIComponent(window.search_input),a="https://www.googleapis.com/youtube/v3/search?key="+x+"&videoEmbeddable=true&part=id&fields=items(id)&type=video&order=viewCount&safeSearch=none&maxResults=25";a+="&q="+t,R&&(a+="&videoCategoryId=10");var s="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+x+"&id=";o.contains($("#search_loader").attr("class").split(" "),"hide")&&$("#search_loader").removeClass("hide"),o.contains($("#results").attr("class").split(" "),"hide")&&$("#results").removeClass("hide"),$.ajax({type:"GET",url:a,dataType:"jsonp",success:function(e){0==e.items.length?($("").appendTo($("#results")).show("blind",83.33),o.contains($("#search_loader").attr("class").split(" "),"hide")||$("#search_loader").addClass("hide")):e.items&&($.each(e.items,function(e,t){s+=t.id.videoId+","}),$.ajax({type:"GET",url:s,dataType:"jsonp",success:function(e){var t="",a=$(L);$.each(e.items,function(e,o){var s=o.contentDetails.duration;if(secs=K.durationToSeconds(s),!longsongs||secs<720){u=o.snippet.title,enc_title=encodeURIComponent(u).replace(/'/g,"\\'"),n=o.id,s=s.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s"),thumb=o.snippet.thumbnails.medium.url;var i=a;i.find(".search-title").text(u),i.find(".result_info").text(s),i.find(".thumb").attr("data-original",thumb),i.find(".add-many").attr("onclick","submit('"+n+"','"+enc_title+"',"+secs+");"),$($(i).find("div")[0]).attr("onclick","submitAndClose('"+n+"','"+enc_title+"',"+secs+");"),$($(i).find("div")[0]).attr("id",n),t+=i.html()}}),$("").appendTo($("#results")).show("blind",83.33*(e.items.length-1)),setTimeout(function(){$(".thumb").lazyload({container:$("#results")})},250),o.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")},submitAndClose:function(e,t,o){K.submit(e,t,o),$("#results").html(""),K.showSearch(),document.getElementById("search").value="",$("#results").html="",$(".main").removeClass("blurT"),$("#controls").removeClass("blurT"),$(".main").removeClass("clickthrough")},importPlaylist:function(e,t){token="",void 0!==t&&(token="&pageToken="+t),playlist_url="https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+x+"&playlistId="+e+token,$.ajax({type:"GET",url:playlist_url,dataType:"jsonp",success:function(t){var o="";K.addVideos(t.items[0].contentDetails.videoId),$.each(t.items,function(e,t){o+=t.contentDetails.videoId+","}),K.addVideos(o),t.nextPageToken&&K.importPlaylist(e,t.nextPageToken),document.getElementById("import").value=""}})},addVideos:function(e){var t="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id=";t+=e,$.ajax({type:"POST",url:t,dataType:"jsonp",success:function(e){$.each(e.items,function(e,t){var o=K.durationToSeconds(t.contentDetails.duration);(!longsongs||720>o)&&(enc_title=encodeURIComponent(t.snippet.title),K.submit(t.id,enc_title,o))})}})},submit:function(e,t,o){F.emit("add",[e,decodeURIComponent(t),P,o])},durationToSeconds:function(e){var t=e.match(A);return hours=parseInt(t[12])||0,minutes=parseInt(t[14])||0,seconds=parseInt(t[16])||0,60*hours*60+60*minutes+seconds}},Q={setup_youtube_listener:function(e){F.on("np",function(e){if(0==e[0].length){document.getElementById("song-title").innerHTML="Empty channel. Add some songs!",$("#player_overlay").height($("#player").height()),window.mobilecheck()||$("#player_overlay").toggleClass("hide");try{d.stopVideo()}catch(t){}}else h=e[0][0].id,s=e[1][0],time=e[2],v=time-s.startTime,f=e[0][0].title,$("#player_overlay").addClass("hide"),Q.getTitle(f,m),Q.setBGimage(h),D&&!window.mobilecheck()?(d.getVideoUrl().split("v=")[1]!=h&&(d.loadVideoById(h),Q.notifyUser(h,f),d.seekTo(v),z&&d.pauseVideo()),z||d.playVideo(),(d.getDuration()>v||0==d.getDuration())&&d.seekTo(v)):Q.getTitle(f,m)}),F.on("viewers",function(e){m=e,void 0!==f&&Q.getTitle(f,m)})},onPlayerStateChange:function(e){switch(e.data){case-1:break;case 0:O=!1,z=!1,F.emit("end",h);break;case 1:O=!0,1==document.getElementById("play").className.split(" ").length&&$("#play").toggleClass("hide"),2==document.getElementById("pause").className.split(" ").length&&$("#pause").toggleClass("hide"),z&&(F.emit("pos"),z=!1);break;case 2:z=!0,1==document.getElementById("pause").className.split(" ").length&&$("#pause").toggleClass("hide"),2==document.getElementById("play").className.split(" ").length&&$("#play").toggleClass("hide");break;case 3:}},getTitle:function(e,t){var o=t>1?"viewers":"viewer",n=decodeURIComponent(e),a=document.getElementById("song-title"),s=document.getElementById("viewers");document.title=n+" • Zöff / "+k,a.innerHTML=n,s.innerHTML=t+" "+o,a.title=n+" • "+t+" "+o},errorHandler:function(e){5==e.data||100==e.data||101==e.data||150==e.data?F.emit("skip",e.data):void 0!==h&&d.loadVideoById(h)},onPlayerReady:function(e){D=!0,window.mobilecheck()||($("#player").css("opacity","1"),$("#controls").css("opacity","1"),$(".playlist").css("opacity","1"),d.loadVideoById(h),d.playVideo(),d.seekTo(v)),Q.readyLooks(),W.initYoutubeControls(d),W.initSlider(),d.setVolume(localStorage.getItem("volume"))},readyLooks:function(){Q.setBGimage(h)},setBGimage:function(e){if(void 0!==e){var t=new Image;t.onload=function(){var e=new ColorThief;document.getElementsByTagName("body")[0].style.backgroundColor=o.rgbToHsl(e.getColor(t))},t.crossOrigin="Anonymous",t.src="//zoff.no:8080/http://img.youtube.com/vi/"+e+"/mqdefault.jpg"}},notifyUser:function(e,t){if(t=t.replace(/\\\'/g,"'").replace(/"/g,"'").replace(/&/g,"&"),"granted"===Notification.permission&&document.hidden&&"30H2Z8Lr-4c"!=e&&!window.mobilecheck()){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(){F.on("get_list",function(){F.emit("list",k.toLowerCase())}),Q.setup_youtube_listener(k),e.admin_listener(),t.setup_chat_listener(k),t.allchat_listener(),w.channel_listener(),w.skipping_listener()},onYouTubeIframeAPIReady:function(){d=new YT.Player("player",{videoId:"asd",playerVars:{rel:"0",wmode:"transparent",controls:"0",iv_load_policy:"3",theme:"light",color:"white"},events:{onReady:Q.onPlayerReady,onStateChange:Q.onPlayerStateChange,onError:Q.errorHandler}})},loadPlayer:function(){l=document.createElement("script"),l.src="https://www.youtube.com/iframe_api",c=document.getElementsByTagName("script")[0],c.parentNode.insertBefore(l,c)}}}(); \ No newline at end of file diff --git a/static/js/admin.js b/static/js/admin.js index ae292a1a..09254874 100755 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -59,23 +59,25 @@ var Admin = { socket.on("pw", function(msg) { - console.log("fuck"); - w_p = false; + w_p = false; adminpass = msg; - names=["vote","addsongs","longsongs","frontpage", "allvideos", "removeplay", "skip", "shuffle"]; + names = ["vote","addsongs","longsongs","frontpage", "allvideos", + "removeplay", "skip", "shuffle"]; + + localStorage.setItem(chan.toLowerCase(), msg); + for (var i = 0; i < names.length; i++) { $("input[name="+names[i]+"]").attr("disabled", false); } - $(".card-action").removeClass("hide"); + $(".card-action").removeClass("hide"); $("#admin-lock").removeClass("mdi-action-lock"); - if(!Helper.contains($("#admin-lock").attr("class").split(" "), "mdi-action-lock-open")) - $("#admin-lock").addClass("mdi-action-lock-open clickable"); - localStorage.setItem(chan.toLowerCase(), msg); $("#password").val(""); $("#password").attr("placeholder", "Change channel password") - //Materialize.toast("Correct password. You now have access to the sacred realm of The Admin.", 4000); - }); + + if(!Helper.contains($("#admin-lock").attr("class").split(" "), "mdi-action-lock-open")) + $("#admin-lock").addClass("mdi-action-lock-open clickable"); + }); socket.on("conf", function(msg) { @@ -103,18 +105,27 @@ var Admin = { display_logged_out: function() { - w_p = true; - names=["vote","addsongs","longsongs","frontpage", "allvideos", "removeplay", "skip", "shuffle"]; - for (var i = 0; i < names.length; i++) { - $("input[name="+names[i]+"]").attr("disabled", true); + w_p = true; + adminpass = ""; + names = ["vote","addsongs","longsongs","frontpage", "allvideos", + "removeplay", "skip", "shuffle"]; + + document.getElementById("password").value = ""; + + for (i = 0; i < names.length; i++) { + $("input[name="+names[i]+"]").attr("disabled", true); } - if(!Helper.contains($("#admin-lock").attr("class").split(" "), "mdi-action-lock")) + + if(!Helper.contains($("#admin-lock").attr("class").split(" "), "mdi-action-lock")){ $("#admin-lock").addClass("mdi-action-lock"); - $("#admin-lock").removeClass("mdi-action-lock-open clickable"); - if($(".card-action").length != 0 && !Helper.contains($(".card-action").attr("class").split(" "), "hide")) + } + + if($(".card-action").length != 0 && + !Helper.contains($(".card-action").attr("class").split(" "), "hide")){ $(".card-action").addClass("hide"); - adminpass = ""; - document.getElementById("password").value = ""; + } + + $("#admin-lock").removeClass("mdi-action-lock-open clickable"); $("#password").attr("placeholder", "Enter channel password") }, @@ -125,29 +136,24 @@ var Admin = { set_conf: function(conf_array) { - if(conf_array['adminpass'] == "" || !w_p) hasadmin = false; - else hasadmin = true; - music = conf_array["allvideos"]; + music = conf_array["allvideos"]; longsongs = conf_array["longsongs"]; - names=["vote","addsongs","longsongs","frontpage", "allvideos", "removeplay", "skip", "shuffle"]; - for (var i = 0; i < names.length; i++) { + names = ["vote","addsongs","longsongs","frontpage", "allvideos", + "removeplay", "skip", "shuffle"]; + + if(conf_array['adminpass'] == "" || !w_p) + hasadmin = false; + else hasadmin = true; + + for (var i = 0; i < names.length; i++) + { document.getElementsByName(names[i])[0].checked = (conf_array[names[i]] === true); $("input[name="+names[i]+"]").attr("disabled", hasadmin); } - if(hasadmin && !localStorage[chan.toLowerCase()]) - { - $("#password").attr("placeholder", "Enter channel password"); - Admin.display_logged_out(); - if(!Helper.contains($("#admin-lock").attr("class").split(" "), "mdi-action-lock")) - $("#admin-lock").addClass("mdi-action-lock"); - $("#admin-lock").removeClass("mdi-action-lock-open clickable"); - }else if(!hasadmin && !localStorage[chan.toLowerCase()]) - { - $("#password").attr("placeholder", "Enter channel password"); - if(!Helper.contains($("#admin-lock").attr("class").split(" "), "mdi-action-lock")) - $("#admin-lock").addClass("mdi-action-lock"); - $("#admin-lock").removeClass("mdi-action-lock-open clickable"); + if((hasadmin && !localStorage[chan.toLowerCase()]) || + (!hasadmin && !localStorage[chan.toLowerCase()])){ + Admin.display_logged_out(); } /*if(conf_array.desc !== undefined) @@ -158,17 +164,17 @@ var Admin = { submitAdmin: function(form) { - voting = form.vote.checked; - addsongs = form.addsongs.checked; - longsongs = form.longsongs.checked; - frontpage = form.frontpage.checked; - allvideos = form.allvideos.checked; + voting = form.vote.checked; + addsongs = form.addsongs.checked; + longsongs = form.longsongs.checked; + frontpage = form.frontpage.checked; + allvideos = form.allvideos.checked; removeplay = form.removeplay.checked; - //adminpass = document.getElementById("password").value; - skipping = form.skip.checked; - shuffling = form.shuffle.checked; + skipping = form.skip.checked; + shuffling = form.shuffle.checked; + configs = [voting, addsongs, longsongs, frontpage, allvideos, + removeplay, adminpass, skipping, shuffling]; - configs = [voting, addsongs, longsongs, frontpage, allvideos, removeplay, adminpass, skipping, shuffling]; socket.emit("conf", configs); }, @@ -176,24 +182,9 @@ var Admin = { $('#settings').sideNav('hide'); }, - remove_bar: function() - { - setTimeout(function(){ - $("#adminPanel").removeClass("success"); - $("#adminPanel").removeClass("fadeerror"); - $("#eBar").removeClass("opacityFull"); - $("#sBar").removeClass("opacityFull"); - },1500); - }, - shuffle: function() { socket.emit('shuffle', adminpass !== undefined ? adminpass : ""); }, - get_wp: function() - { - return w_p; - } - } \ No newline at end of file diff --git a/static/js/list.js b/static/js/list.js index cdd0af58..0345758c 100755 --- a/static/js/list.js +++ b/static/js/list.js @@ -9,75 +9,24 @@ var List = { channel_function: function(msg) { - if(msg[0] == "list") - { - full_playlist = msg[1]; - full_playlist.sort(Helper.predicate({ - name: 'votes', - reverse: true - }, 'added')); - List.populate_list(full_playlist); - }else if(msg[0] == "added") - { - full_playlist.push(msg[1]); - full_playlist.sort(Helper.predicate({ - name: 'votes', - reverse: true - }, 'added')); - - var index = List.getIndexOfSong(msg[1].id); - - List.insertAtIndex(index, msg[1], true); - var test = $("#wrapper").children()[index]; - setTimeout(function(){ - $(test).css("height", 66); - },5); - - }else if(msg[0] == "deleted") - { - var to_delete = $("#wrapper").children()[List.getIndexOfSong(msg[1])]; - to_delete.style.height = 0; - setTimeout(function() - { - $("#"+msg[1]).remove(); - full_playlist.splice(List.getIndexOfSong(msg[1]), 1); - }, 305); - document.getElementById('wrapper').scrollTop += 1; - document.getElementById('wrapper').scrollTop += -1; - }else if(msg[0] == "vote") - { - var index_of_song = List.getIndexOfSong(msg[1]); - var song_voted_on = full_playlist[index_of_song]; - full_playlist[index_of_song].votes += 1; - full_playlist[index_of_song].added = msg[2]; - full_playlist.sort(Helper.predicate({ - name: 'votes', - reverse: true - }, 'added')); - $("#"+msg[1]).remove(); - List.insertAtIndex(List.getIndexOfSong(msg[1]), song_voted_on, false); - - //List.populate_list(full_playlist, false); - }else if(msg[0] == "song_change") - { - - full_playlist[0].now_playing = true; - full_playlist[0].votes = 0; - full_playlist[0].guids = []; - full_playlist[0].added = msg[1]; - full_playlist[full_playlist.length-1].now_playing = false; - /*full_playlist.sort(predicate({ - name: 'votes', - reverse: true - }, 'added')); - */ - full_playlist.push(full_playlist.shift()); - $("#wrapper").children()[0].remove(); - List.insertAtIndex($("#wrapper").children().length, full_playlist[full_playlist.length-2], false); - document.getElementById('wrapper').scrollTop += 1; - document.getElementById('wrapper').scrollTop += -1; - //populate_list(full_playlist); - } + switch(msg[0]) + { + case "list": + List.populate_list(msg[1]); + break; + case "added": + List.added_song(msg[1]); + break; + case "deleted": + List.deleted_song(msg[1]); + break; + case "vote": + List.voted_song(msg[1], msg[2]); + break; + case "song_change": + List.song_change(msg[1]); + break; + } }, skipping_listener: function(){ @@ -93,27 +42,14 @@ var List = { populate_list: function(msg) { + full_playlist = msg; + + List.sortList(); $("#wrapper").empty(); - $.each(msg, function(j, listeID){ - if(!listeID.now_playing){ //check that the song isnt playing - - var video_title=decodeURIComponent(listeID.title); - var video_id = listeID.id; - var video_thumb = "//img.youtube.com/vi/"+video_id+"/mqdefault.jpg"; - //var delsong = ""; if(pass_corr=="correct"); - var video_votes = listeID.votes; - $("#wrapper").append(list_html); - var song = $("#list-song"); - song.find(".list-title").text(video_title); - song.find(".list-title").attr("title", video_title); - song.find(".list-votes").text(video_votes); - song.find(".vote-container").attr("onclick", "vote('"+video_id+"','pos')"); - song.find(".list-image").attr("data-original",video_thumb); - song.attr("id",video_id); - song.find("#del").attr("onclick", "vote('"+video_id+"', 'del')"); - if(!w_p) $(".card-action").removeClass("hide"); - if(video_votes==1)song.find(".vote-text").text("vote"); + $.each(full_playlist, function(j, current_song){ + if(!current_song.now_playing){ //check that the song isnt playing + $("#wrapper").append(List.generateSong(current_song, false)); } }); @@ -125,6 +61,56 @@ var List = { }, + added_song: function(added){ + full_playlist.push(added); + List.sortList(); + List.insertAtIndex(added, true); + }, + + deleted_song: function(deleted){ + var index = List.getIndexOfSong(deleted); + var to_delete = $("#wrapper").children()[index]; + to_delete.style.height = 0; + + setTimeout(function() + { + $("#"+deleted).remove(); + full_playlist.splice(List.getIndexOfSong(deleted), 1); + }, 305); + + document.getElementById('wrapper').scrollTop += 1; + document.getElementById('wrapper').scrollTop += -1; + }, + + voted_song: function(voted, time){ + var index_of_song = List.getIndexOfSong(voted); + var song_voted_on = full_playlist[index_of_song]; + + full_playlist[index_of_song].votes += 1; + full_playlist[index_of_song].added = time; + + List.sortList(); + $("#"+voted).remove(); + List.insertAtIndex(song_voted_on, false); + }, + + song_change: function(time){ + var length = full_playlist.length-1; + + full_playlist[0].now_playing = true; + full_playlist[0].votes = 0; + full_playlist[0].guids = []; + full_playlist[0].added = time; + full_playlist[length].now_playing = false; + + full_playlist.push(full_playlist.shift()); + $("#wrapper").children()[0].remove(); + + List.insertAtIndex(full_playlist[length-1], false); + document.getElementById('wrapper').scrollTop += 1; + document.getElementById('wrapper').scrollTop += -1; + }, + vote: function(id, vote){ socket.emit('vote', [chan, id, vote, adminpass]); return true; @@ -136,23 +122,26 @@ var List = { }, importOldList: function(chan){ + var ids=""; + var num=0; + playlist_url = "lists/"+chan+".json"; - list = $.ajax({ - type: "GET", - url: playlist_url, - async: false - }).responseText; - list = $.parseJSON(list); - var ids=""; - var num=0; + list = $.parseJSON($.ajax({ + type: "GET", + url: playlist_url, + async: false + }).responseText); + $.each(list.songs, function(i,data) { ids+=data.id+","; + if(num>45){ Search.addVideos(ids); - ids=""; - num=0; + + ids = ""; + num = 0; } num++; }); @@ -161,6 +150,14 @@ var List = { document.getElementById("search").value = ""; }, + sortList: function() + { + full_playlist.sort(Helper.predicate({ + name: 'votes', + reverse: true + }, 'added')); + }, + show: function(){ if(!window.mobilecheck()) { @@ -179,23 +176,35 @@ var List = { } }, - insertAtIndex: function(i, song_info, transition) { - if(i === 0) { + insertAtIndex: function(song_info, transition) { + i = List.getIndexOfSong(song_info.id); + + if(i === 0) $("#wrapper").prepend(List.generateSong(song_info, transition)); - return; + else + $("#wrapper > div:nth-child(" + (i) + ")").after(List.generateSong(song_info, transition)); + + if(transition) + { + setTimeout(function(){ + var added = $("#wrapper").children()[i]; + $(added).css("height", 66); + },5); } - $("#wrapper > div:nth-child(" + (i) + ")").after(List.generateSong(song_info, transition)); }, generateSong: function(song_info, transition) { - var video_id = song_info.id; + var video_id = song_info.id; var video_title = song_info.title; var video_votes = song_info.votes; var video_thumb = "background-image:url('//img.youtube.com/vi/"+video_id+"/mqdefault.jpg');"; + var song = $("
    "+list_html+"
    "); + + if(transition) song.find("#list-song").css("height", 0); + if(!w_p) song.find(".card-action").removeClass("hide"); + if(video_votes == 1)song.find(".vote-text").text("vote"); - var song = $("
    "+list_html+"
    "); - if(transition) song.find("#list-song").css("height", 0); song.find(".list-title").text(video_title); song.find(".list-title").attr("title", video_title); song.find(".list-votes").text(video_votes); @@ -203,14 +212,6 @@ var List = { song.find(".list-image").attr("style",video_thumb); song.find("#list-song").attr("id", video_id); song.find("#del").attr("onclick", "vote('"+video_id+"', 'del')"); - if(!w_p) song.find(".card-action").removeClass("hide"); - if(video_votes == 1)song.find(".vote-text").text("vote"); - -/* - $(".lazy").lazyload({ - container: $("#wrapper") - }).removeClass("lazy"); -*/ return song.html(); }, diff --git a/static/js/listeners.js b/static/js/listeners.js index d3fbf1e0..c2dc3fd5 100755 --- a/static/js/listeners.js +++ b/static/js/listeners.js @@ -1,41 +1,43 @@ -var chan = $("#chan").html(); -var w_p = true; -var hasadmin=0; -var list; -var showToggle =true; -var list_html = $("#list-song-html").html(); +var chan = $("#chan").html(); +var w_p = true; +var hasadmin = 0; +var showToggle = true; +var list_html = $("#list-song-html").html(); +var blink_interval_exists = false; +var unseen = false; +var timer = 0; +var api_key = "***REMOVED***"; +var result_html = $("#temp-results-container"); +var empty_results_html = $("#empty-results-container").html(); +var searching = false +var time_regex = /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)?)?/ +var conf = []; +var music = 0; +var frontpage = 1; +var adminpass = ""; +var filesadded = ""; +var player_ready = false; +var viewers = 1; +var paused = false; +var playing = false; +var SAMPLE_RATE = 6000; // 6 seconds +var lastSample = Date.now(); +var began = false; +var i = -1; + +var id; var full_playlist; var conf; var blink_interval; -var blink_interval_exists = false; -var unseen = false; -var timer = 0; -var api_key = "***REMOVED***"; -var result_html = $("#temp-results-container"); -var empty_results_html = $("#empty-results-container").html(); -var searching = false -var time_regex = /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)?)?/ var tag; var firstScriptTag; var ytplayer; var title; var viewers; var video_id; -var conf = []; -var music = 0; -var frontpage = 1; -var adminpass = ""; -var filesadded=""; -var player_ready = false; +var list; var seekTo; var song_title; -var viewers = 1; -var paused = false; -var playing = false; -var SAMPLE_RATE = 6000; // 6 seconds -var lastSample = Date.now(); -var began = false; -var id; var connection_options = { 'sync disconnect on unload':true @@ -48,8 +50,8 @@ socket.on("get_list", function(){ $(document).ready(function() { - window.vote = List.vote; - window.submit = Search.submit; + window.vote = List.vote; + window.submit = Search.submit; window.submitAndClose = Search.submitAndClose; if(!localStorage["list_update"] || localStorage["list_update"] != "13.06.15") @@ -68,32 +70,8 @@ $(document).ready(function() closeOnClick: false // Closes side-nav on clicks, useful for Angular/Meteor }); - if(!window.mobilecheck()) - { - Chat.setup_chat_listener(chan); - Chat.allchat_listener(); - Hostcontroller.host_listener(); - $("#chat-btn").sideNav({ - menuWidth: 272, // Default is 240 - edge: 'left', // Choose the horizontal origin - closeOnClick: false // Closes side-nav on clicks, useful for Angular/Meteor - }); - - $(".drag-target")[1].remove(); - } - - //Materialize.toast("Passwords have been reset. If anything is not right, please send us a mail @ contact@zoff.no", 10000); - - //$('#settings-close').sideNav('hide'); - - if(!window.mobilecheck() && !Helper.msieversion()) - { - Notification.requestPermission(); - } - if(localStorage[chan.toLowerCase()]) { - //localStorage.removeItem(chan.toLowerCase()); if(localStorage[chan.toLowerCase()].length != 64) localStorage.removeItem(chan.toLowerCase()); else @@ -104,9 +82,22 @@ $(document).ready(function() document.getElementById("search").blur(); Youtube.readyLooks(); }else{ + + Chat.setup_chat_listener(chan); + Chat.allchat_listener(); + Hostcontroller.host_listener(); Youtube.loadPlayer(); window.onYouTubeIframeAPIReady = Youtube.onYouTubeIframeAPIReady; + $("#chat-btn").sideNav({ + menuWidth: 272, // Default is 240 + edge: 'left', // Choose the horizontal origin + closeOnClick: false // Closes side-nav on clicks, useful for Angular/Meteor + }); + + $(".drag-target")[1].remove(); + + if(!Helper.msieversion()) Notification.requestPermission(); if(navigator.userAgent.toLowerCase().indexOf("firefox") > -1) //quickdickfix for firefoxs weird percent handling $(".main").height(window.innerHeight-64); @@ -163,50 +154,41 @@ $(document).ready(function() }); $(document).keyup(function(e) { - if(event.keyCode == 27){ - $("#results").html(""); - $(".main").removeClass("blurT"); - $("#controls").removeClass("blurT"); - $(".main").removeClass("clickthrough"); - if(!Helper.contains($("#search-wrapper").attr("class").split(" "), "hide")) - $("#search-wrapper").toggleClass("hide"); - if(Helper.contains($("#song-title").attr("class").split(" "), "hide")) - $("#song-title").toggleClass("hide"); + if(event.keyCode == 27){ + $("#results").html(""); + if(!Helper.contains($("#search-wrapper").attr("class").split(" "), "hide")) + $("#search-wrapper").toggleClass("hide"); + if(Helper.contains($("#song-title").attr("class").split(" "), "hide")) + $("#song-title").toggleClass("hide"); - if($("#search-btn i").attr('class') == "mdi-navigation-close") - { - $("#search-btn i").toggleClass("mdi-navigation-close"); - $("#search-btn i").toggleClass("mdi-action-search"); - } - $("#results").toggleClass("hide"); - } - - else if ($("div.result").length > 2){ - - if (e.keyCode == 40) { - if(i < $("div.result").length -2) - i++; - $("div.result:nth-child("+(i-1)+")").removeClass("hoverResults"); - $("div.result:nth-child("+i+")").addClass("hoverResults"); - } else if (e.keyCode == 38) { - $("div.result:nth-child("+i+")").removeClass("hoverResults"); - $("div.result:nth-child("+(i-1)+")").addClass("hoverResults"); - if(i > 1) - i--; - } else if(e.keyCode == 13) { - i = 0; - var elem = document.getElementsByClassName("hoverResults")[0]; - if (typeof elem.onclick == "function") { - elem.onclick.apply(elem); - } - $("div.hoverResults").removeClass("hoverResults"); - $("#results").html(''); - document.getElementById("search").value = ""; - $(".main").removeClass("blurT"); - $("#controls").removeClass("blurT"); - $(".main").removeClass("clickthrough"); - } - } + if($("#search-btn i").attr('class') == "mdi-navigation-close") + { + $("#search-btn i").toggleClass("mdi-navigation-close"); + $("#search-btn i").toggleClass("mdi-action-search"); + } + $("#results").toggleClass("hide"); + }else if ($("div.result").length > 2){ + if (e.keyCode == 40) { + $(children[i-1]).removeClass("hoverResults"); + $(children[i]).addClass("hoverResults"); + if(i < children.length -2) + i++; + } else if (e.keyCode == 38) { + if(i > 1) + i--; + $(children[i]).removeClass("hoverResults"); + $(children[i-1]).addClass("hoverResults"); + } else if(e.keyCode == 13) { + i = 0; + var elem = document.getElementsByClassName("hoverResults")[0]; + if (typeof elem.onclick == "function") { + elem.onclick.apply(elem); + } + $("div.hoverResults").removeClass("hoverResults"); + $("#results").html(''); + document.getElementById("search").value = ""; + } + } }); $('input[class=conf]').change(function() diff --git a/static/js/youtube.js b/static/js/youtube.js index 000c605b..88c2811d 100755 --- a/static/js/youtube.js +++ b/static/js/youtube.js @@ -8,6 +8,7 @@ var Youtube = { document.getElementById('song-title').innerHTML = "Empty channel. Add some songs!"; $("#player_overlay").height($("#player").height()); + if(!window.mobilecheck()) $("#player_overlay").toggleClass("hide"); try{ ytplayer.stopVideo(); @@ -16,12 +17,13 @@ var Youtube = { } else{ //console.log("gotten new song"); + video_id = obj[0][0]["id"]; + conf = obj[1][0]; + time = obj[2]; + seekTo = time - conf["startTime"]; + song_title = obj[0][0]["title"]; + $("#player_overlay").addClass("hide"); - video_id = obj[0][0]["id"]; - conf = obj[1][0]; - time = obj[2]; - seekTo = time - conf["startTime"]; - song_title = obj[0][0]["title"]; Youtube.getTitle(song_title, viewers); Youtube.setBGimage(video_id); @@ -48,6 +50,7 @@ var Youtube = { socket.on("viewers", function(view) { viewers = view; + if(song_title !== undefined) Youtube.getTitle(song_title, viewers); }); @@ -59,12 +62,14 @@ var Youtube = { case -1: break; case 0: + playing = false; + paused = false; + socket.emit("end", video_id); - playing = false; - paused = false; break; case 1: playing = true; + if(document.getElementById("play").className.split(" ").length == 1) $("#play").toggleClass("hide"); if(document.getElementById("pause").className.split(" ").length == 2) @@ -77,6 +82,7 @@ var Youtube = { break; case 2: paused = true; + if(document.getElementById("pause").className.split(" ").length == 1) $("#pause").toggleClass("hide"); if(document.getElementById("play").className.split(" ").length == 2) @@ -89,21 +95,23 @@ var Youtube = { getTitle: function(titt, v) { - var outPutWord = v > 1 ? "viewers" : "viewer"; - var title= decodeURIComponent(titt); - var elem = document.getElementById('song-title'); + var outPutWord = v > 1 ? "viewers" : "viewer"; + var title = decodeURIComponent(titt); + var elem = document.getElementById('song-title'); + var viewers = document.getElementById('viewers'); - document.title = title + " • Zöff / "+chan; - elem.innerHTML = title; - document.getElementById('viewers').innerHTML = v + " " + outPutWord; - elem.title = title + " • " + v + " " + outPutWord; + document.title = title + " • Zöff / "+chan; + elem.innerHTML = title; + viewers.innerHTML = v + " " + outPutWord; + elem.title = title + " • " + v + " " + outPutWord; }, errorHandler: function(newState) { - if(newState.data == 5 || newState.data == 100 || newState.data == 101 || newState.data == 150) - socket.emit("skip", newState.data); + if(newState.data == 5 || newState.data == 100 + || newState.data == 101 || newState.data == 150) + socket.emit("skip", newState.data); else if(video_id !== undefined) ytplayer.loadVideoById(video_id); }, @@ -133,21 +141,20 @@ var Youtube = { setBGimage: function(id){ if(id !== undefined) { - var img = new Image(); - img.onload = function () { - var colorThief = new ColorThief(); - //console.log(rgbToHsl(colorThief.getColor(img))); - document.getElementsByTagName("body")[0].style.backgroundColor = Helper.rgbToHsl(colorThief.getColor(img)) - //$("body").css("background-color", rgbToHsl(colorThief.getColor(img))); - //$("body").css("background-color", colorThief.getColor(img)); + var img = new Image(); + img.onload = function () + { + var colorThief = new ColorThief(); + document.getElementsByTagName("body")[0].style.backgroundColor = Helper.rgbToHsl(colorThief.getColor(img)); }; + img.crossOrigin = 'Anonymous'; - img.src = '//zoff.no:8080/http://img.youtube.com/vi/'+id+'/mqdefault.jpg'; + img.src = '//zoff.no:8080/http://img.youtube.com/vi/'+id+'/mqdefault.jpg'; } }, notifyUser: function(id, title) { - title= title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&"); + title = title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&"); if (Notification.permission === "granted" && document.hidden && id != "30H2Z8Lr-4c" && !window.mobilecheck()) { var notification = new Notification("Now Playing", {body: title, icon: "http://i.ytimg.com/vi/"+id+"/mqdefault.jpg", iconUrl: "http://i.ytimg.com/vi/"+id+"/mqdefault.jpg"}); notification.onclick = function(x) { window.focus(); this.cancel(); }; @@ -183,8 +190,8 @@ var Youtube = { }, loadPlayer: function() { - tag = document.createElement('script'); - tag.src = "https://www.youtube.com/iframe_api"; + tag = document.createElement('script'); + tag.src = "https://www.youtube.com/iframe_api"; firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); }