From 5e2e267481aa5d162f714c8e63e251138926013d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Mon, 2 May 2016 14:37:43 +0200 Subject: [PATCH] Removed serviceworker and fixed gulp --- static/dist/main.min.js | 3034 +-------------------------------------- 1 file changed, 2 insertions(+), 3032 deletions(-) diff --git a/static/dist/main.min.js b/static/dist/main.min.js index 5e3d1ab1..2d98af05 100755 --- a/static/dist/main.min.js +++ b/static/dist/main.min.js @@ -1,3032 +1,2 @@ -var Admin = { - - beginning:true, - - admin_listener: function() - { - - socket.on("toast", function(msg) - { - switch(msg) { - case "addedsong": - msg=Helper.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": - msg=Helper.rnd(["I've saved your settings", "I stored all your settings", "Your settings have been stored in a safe place"]) - break; - case "wrongpass": - msg=Helper.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."]) - Crypt.remove_pass(chan.toLowerCase()); - Admin.display_logged_out(); - w_p = true; - break; - case "shuffled": - msg=Helper.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": - msg=Helper.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": - msg=Helper.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": - msg=Helper.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": - msg=Helper.rnd(["The song was skipped", "I have skipped a song", "Skipped to the beat", "Skipmaster3000", "They see me skippin', they hatin'"]) - break; - case "listhaspass": - msg=Helper.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": - msg=Helper.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": - msg=Helper.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": - msg="Skipping is disabled the first 10 seconds."; - break; - case "correctpass": - msg="Correct password. You now have access to the sacred realm of The Admin."; - break; - case "changedpass": - msg="Your password has been changed!"; - break; - case "suggested": - msg="Your song was suggested!"; - break; - case "alreadyplay": - msg="Seems the song you want is already playing. No fooling the system!"; - break; - } - Materialize.toast(msg, 4000); - }); - - - socket.on("pw", function(msg) - { - - w_p = false; - adminpass = msg; - names = ["vote","addsongs","longsongs","frontpage", "allvideos", - "removeplay", "skip", "shuffle"]; - - Crypt.set_pass(chan.toLowerCase(), Crypt.decrypt_pass(msg)) - - for (var i = 0; i < names.length; i++) { - $("input[name="+names[i]+"]").attr("disabled", false); - } - - $(".card-action").removeClass("hide"); - $("#admin-lock").removeClass("mdi-action-lock"); - $("#password").val(""); - $("#password").attr("placeholder", "Change channel password") - //if(!window.mobilecheck()){ - if(!Helper.contains($(".playlist-tabs").attr("class").split(" "), "hide")) { - $(".playlist-tabs-loggedIn").removeClass("hide"); - $(".playlist-tabs").addClass("hide"); - } - //$("#top-button").toggleClass("top-button-with-tabs"); - //$("#wrapper").toggleClass("tabs_height"); - //} - - if(!Helper.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)); - }); - - socket.on("conf", function(msg) - { - Crypt.init(); - Admin.set_conf(msg[0]); - if(Crypt.get_pass(chan.toLowerCase()) !== undefined && Admin.beginning && Crypt.get_pass(chan.toLowerCase()) != ""){ - socket.emit("password", [Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase())), chan.toLowerCase()]); - Admin.beginning = false; - } - }); - }, - - pass_save: function() - { - if(!w_p) - { - socket.emit('password', [Crypt.crypt_pass(CryptoJS.SHA256(document.getElementById("password").value).toString()), chan.toLowerCase(), Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase()))]); - } - else - { - socket.emit('password', [Crypt.crypt_pass(CryptoJS.SHA256(document.getElementById("password").value).toString()), chan.toLowerCase()]); - } - }, - - log_out: function(){ - if(Crypt.get_pass(chan.toLowerCase())){ - Crypt.remove_pass(chan.toLowerCase()); - Admin.display_logged_out(); - Materialize.toast("Logged out", 4000); - }else{ - Materialize.toast("Not logged in", 4000); - } - }, - - display_logged_out: function() - { - 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")){ - $("#admin-lock").addClass("mdi-action-lock"); - } - - if(!Helper.contains($(".playlist-tabs-loggedIn").attr("class").split(" "), "hide")){ - $(".playlist-tabs-loggedIn").addClass("hide"); - $(".playlist-tabs").removeClass("hide"); - } - - if($(".card-action").length != 0 && - !Helper.contains($(".card-action").attr("class").split(" "), "hide")){ - $(".card-action").addClass("hide"); - } - - if($(".playlist-tabs-li a.active").attr("href") == "#suggestions") - { - $('ul.playlist-tabs').tabs('select_tab', 'wrapper'); - $('ul.playlist-tabs-loggedIn').tabs('select_tab', 'wrapper'); - $("#wrapper").removeClass("tabs_height"); - } else { - $('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"); - //$("#top-button").removeClass("top-button-with-tabs"); - }, - - //function used in html onlick - save: function(){ - Admin.submitAdmin(document.getElementById("adminForm").elements); - }, - - set_conf: function(conf_array) - { - music = conf_array["allvideos"]; - longsongs = conf_array["longsongs"]; - names = ["vote","addsongs","longsongs","frontpage", "allvideos", - "removeplay", "skip", "shuffle"]; - - - if(conf_array['adminpass'] == "" || !w_p){ - hasadmin = false; - if(!window.mobilecheck()){ - //$(".playlist-tabs").removeClass("hide"); - //$("#wrapper").toggleClass("tabs_height"); - } - } - 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)){ - Admin.display_logged_out(); - }else if(!hasadmin && Crypt.get_pass(chan.toLowerCase()) === undefined){ - if(!Helper.contains($(".playlist-tabs").attr("class").split(" "), "hide")) { - $(".playlist-tabs-loggedIn").removeClass("hide"); - $(".playlist-tabs").addClass("hide"); - } - $("#password").attr("placeholder", "Create channel password"); - } - - /*if(conf_array.desc !== undefined) - { - document.getElementById("description").innerHTML = conf_array.desc; - }*/ - }, - - submitAdmin: function(form) - { - voting = form.vote.checked; - addsongs = form.addsongs.checked; - longsongs = form.longsongs.checked; - frontpage = form.frontpage.checked; - allvideos = form.allvideos.checked; - removeplay = form.removeplay.checked; - skipping = form.skip.checked; - shuffling = form.shuffle.checked; - configs = [voting, addsongs, longsongs, frontpage, allvideos, - removeplay, adminpass, skipping, shuffling]; - - socket.emit("conf", configs); - }, - - hide_settings: function(){ - $('#settings').sideNav('hide'); - }, - - shuffle: function() - { - socket.emit('shuffle', adminpass !== undefined ? adminpass : ""); - }, - - get_admin:function() - { - return [w_p, hasadmin]; - } - - } -var Chat = { - - namechange: function(newName) - { - socket.emit("namechange", newName); - Crypt.set_name(newName); - }, - - removename: function() - { - socket.emit("removename"); - Crypt.remove_name(); - }, - - chat: function(data) - { - if(data.value.length > 150) - return; - if(data.value.startsWith("/name ")){ - Chat.namechange(data.value.substring(6)); - }else if(data.value.startsWith("/removename")){ - Chat.removename(); - } - else if($(".chat-tab-li a.active").attr("href") == "#all_chat") - socket.emit("all,chat", data.value); - else - socket.emit("chat", data.value); - data.value = ""; - return; - }, - - allchat_listener: function() - { - socket.on("chat.all", function(inp) - { - - - //$("#chat-btn").css("color", "grey"); - - if(!blink_interval_exists && inp[1].substring(0,1) == ":" && !chat_active) - { - $("#favicon").attr("href", "static/images/highlogo.png"); - blink_interval_exists = true; - unseen = true; - chat_unseen = true; - if(!blinking) Chat.chat_blink(); - //blink_interval = setTimeout(Chat.chat_blink, 2000); - } - - if(document.hidden) - { - $("#favicon").attr("href", "static/images/highlogo.png"); - } - var color = Helper.intToARGB(Helper.hashCode(inp[0])); - if(color.length < 6) { - for(x = color.length; x < 6; x++){ - color = "0" + color; - } - } - color = Helper.hexToRgb(color.substring(0,6)); - var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); - $("#chatall").append("
  • "+inp[0]+"
  • "); - var in_text = document.createTextNode(inp[1]); - $("#chatall li:last")[0].appendChild(in_text); - document.getElementById("chatall").scrollTop = document.getElementById("chatall").scrollHeight; - }); - }, - - setup_chat_listener: function(channel) - { - socket.on("chat", function(data) - { - if(!blink_interval_exists && data[1].substring(0,1) == ":" && !chat_active) - { - $("#favicon").attr("href", "static/images/highlogo.png"); - unseen = true; - chat_unseen = true; - if(!blinking) Chat.chat_blink(); - //blink_interval = setTimeout(Chat.chat_blink, 1000); - } - - var color = Helper.intToARGB(Helper.hashCode(data[0])); - if(color.length < 6) { - for(x = color.length; x < 6; x++){ - color = "0" + color; - } - } - color = Helper.hexToRgb(color.substring(0,6)); - var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); - $("#chatchannel").append("
  • "+data[0]+"
  • "); - var in_text = document.createTextNode(data[1]); - $("#chatchannel li:last")[0].appendChild(in_text); - document.getElementById("chatchannel").scrollTop = document.getElementById("chatchannel").scrollHeight; - }); - }, - - chat_blink: function() { - blinking = true; - $(".chat-link").attr("style", "color: grey !important;"); - setTimeout(function () { - $(".chat-link").attr("style", "color: white !important;"); - setTimeout(function() { - if(blinking) Chat.chat_blink(); - }, 1000); - }, 1000); - } - -} -var Crypt = { - - conf_pass: undefined, - - init: function(){ - - document.cookie = chan.toLowerCase() + '=; path=/' + chan.toLowerCase() + '; expires=' + new Date(0).toUTCString(); - - try{ - conf_arr = Crypt.decrypt(Crypt.getCookie("_opt"), "_opt"); - }catch(err){ - conf_arr = Crypt.decrypt(Crypt.create_cookie("_opt"), "_opt"); - } - try{ - Crypt.conf_pass = Crypt.decrypt(Crypt.getCookie(chan.toLowerCase()), chan.toLowerCase()); - }catch(err){ - Crypt.conf_pass = Crypt.decrypt(Crypt.create_cookie(chan.toLowerCase()), chan.toLowerCase()); - } - Hostcontroller.change_enabled(conf_arr.remote); - if(conf_arr["width"] != 100) Player.set_width(conf_arr["width"]); - if(conf_arr["name"] != undefined && conf_arr["name"] != "") Chat.namechange(conf_arr["name"]); - }, - - decrypt: function(cookie, name){ - if(Crypt.getCookie(name) === undefined) { - cookie = Crypt.create_cookie(name); - } - - var decrypted = CryptoJS.AES.decrypt( - cookie,"0103060703080703080701", - { - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7 - } - ); - - return $.parseJSON(decrypted.toString(CryptoJS.enc.Utf8)); - }, - - decrypt_pass: function(pass){ - var decrypted = CryptoJS.AES.decrypt( - pass,socket.id, - { - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7 - } - ); - - return decrypted.toString(CryptoJS.enc.Utf8); - }, - - encrypt: function(json_formated, cookie){ - var to_encrypt = JSON.stringify(json_formated); - - var encrypted = CryptoJS.AES.encrypt( - to_encrypt, - "0103060703080703080701", - { - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7 - } - ); - - var CookieDate = new Date; - CookieDate.setFullYear(CookieDate.getFullYear( ) +1); - document.cookie = cookie+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;"; - }, - - encrypt_string: function(string){ - var encrypted = CryptoJS.AES.encrypt( - string, - socket.id, - { - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7 - } - ); - return encrypted.toString(); - }, - - get_volume: function(){ - return Crypt.decrypt(Crypt.getCookie("_opt"), "_opt").volume; - //return conf_arr.volume; - }, - - set_volume: function(val){ - conf_arr.volume = val; - Crypt.encrypt(conf_arr, "_opt"); - }, - - create_cookie: function(name){ - if(name == "_opt") cookie_object = {volume: 100, width: 100, remote: true, name: ""}; - else cookie_object = {passwords: {}}; - - var string_it = JSON.stringify(cookie_object); - - var encrypted = CryptoJS.AES.encrypt( - string_it, - "0103060703080703080701", - { - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7 - } - ); - - var CookieDate = new Date; - CookieDate.setFullYear(CookieDate.getFullYear( ) +1); - - document.cookie = name+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;"; - //document.cookie = name+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;" - //document.cookie = na"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;" - return Crypt.getCookie(name); - }, - - set_pass: function(chan, pass){ - Crypt.conf_pass.passwords[chan] = pass; - Crypt.encrypt(Crypt.conf_pass, chan); - }, - - remove_pass:function(chan){ - delete Crypt.conf_pass.passwords[chan]; - Crypt.encrypt(Crypt.conf_pass, chan.toLowerCase()); - }, - - set_name:function(name){ - conf_arr.name = name; - Crypt.encrypt(conf_arr, "_opt"); - }, - - remove_name:function(){ - conf_arr.name = ""; - Crypt.encrypt(conf_arr, "_opt"); - }, - - get_pass: function(chan){ - if(Crypt.conf_pass != undefined) return Crypt.conf_pass.passwords[chan]; - return undefined; - }, - - set_remote: function(val){ - conf_arr.remote = val; - Crypt.encrypt(conf_arr, "_opt"); - }, - - get_remote: function(val){ - return conf_arr.remote; - }, - - crypt_pass: function(pass){ - var encrypted = CryptoJS.AES.encrypt( - pass, - socket.id, - { - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7 - } - ); - return encrypted.toString(); - }, - - get_width: function(){ - return conf_arr["width"]; - }, - - set_width: function(val){ - conf_arr["width"] = val; - Crypt.encrypt(conf_arr, "_opt"); - }, - - getCookie: function(name) { - var value = "; " + document.cookie; - var parts = value.split("; " + name + "="); - if (parts.length == 2) return parts.pop().split(";").shift(); - } -} -window.mobilecheck = function() { - var check = false; - (function(a){if(/(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(a)||/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(a.substr(0,4)))check = true;})(navigator.userAgent||navigator.vendor||window.opera); - return check; -}; - -var Helper = { - rnd: function(arr) - { - return arr[Math.floor(Math.random() * arr.length)]; - }, - - predicate: function() { - var fields = [], - n_fields = arguments.length, - field, name, cmp; - - var default_cmp = function (a, b) { - if (a === b) return 0; - return a < b ? -1 : 1; - }, - getCmpFunc = function (primer, reverse) { - var dfc = default_cmp, - // closer in scope - cmp = default_cmp; - if (primer) { - cmp = function (a, b) { - return dfc(primer(a), primer(b)); - }; - } - if (reverse) { - return function (a, b) { - return -1 * cmp(a, b); - }; - } - return cmp; - }; - - // preprocess sorting options - for (var i = 0; i < n_fields; i++) { - field = arguments[i]; - if (typeof field === 'string') { - name = field; - cmp = default_cmp; - } else { - name = field.name; - cmp = getCmpFunc(field.primer, field.reverse); - } - fields.push({ - name: name, - cmp: cmp - }); - } - - // final comparison function - return function (A, B) { - var name, result; - for (var i = 0; i < n_fields; i++) { - result = 0; - field = fields[i]; - name = field.name; - - result = field.cmp(A[name], B[name]); - if (result !== 0) break; - } - return result; - }; - }, - - hashCode: function(str) { // java String#hashCode - var hash = 0; - for (var i = 0; i < str.length; i++) { - hash = str.charCodeAt(i) + ((hash << 5) - hash); - } - return hash; - }, - - intToARGB: function(i){ - return ((i>>24)&0xFF).toString(16) + - ((i>>16)&0xFF).toString(16) + - ((i>>8)&0xFF).toString(16) + - (i&0xFF).toString(16); - }, - - hexToRgb: function(hex) { - var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); - return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; - }, - - - pad: function(n) - { - return n < 10 ? "0"+Math.floor(n) : Math.floor(n); - }, - - - contains: function(a, obj) { - var i = a.length; - while (i--) { - if (a[i] === obj) { - return true; - } - } - return false; - }, - - sample: function() { - if (Date.now() - lastSample >= SAMPLE_RATE * 2) { - socket.removeAllListeners() - socket.disconnect(); - socket.connect(); - Player.setup_all_listeners(); - } - lastSample = Date.now(); - setTimeout(Helper.sample, SAMPLE_RATE); - }, - - loadjsfile: function(filename) - { - if (filesadded.indexOf("["+filename+"]")==-1){ - var fileref=document.createElement('script'); - fileref.setAttribute("type","text/javascript"); - fileref.setAttribute("src", filename); - document.getElementsByTagName("head")[0].appendChild(fileref); - filesadded+="["+filename+"]"; - } - }, - - msieversion: function() { - - var ua = window.navigator.userAgent; - var msie = ua.indexOf("MSIE "); - - if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number - return true; - else // If another browser, return 0 - return false; - }, - - getRandomInt: function(min, max) { - return Math.floor(Math.random() * (max - min)) + min; - }, - - rgbToHsl: function(arr, light){ - r = arr[0], g = arr[1], b = arr[2]; - r /= 255, g /= 255, b /= 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h, s, l = (max + min) / 2; - - if(max == min){ - h = s = 0; // achromatic - }else{ - var d = max - min; - s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - if(l>0.5 && light)l=0.5; //make sure it isnt too light - else if(l<0.65 && !light)l=0.65; - - return "hsl("+Math.floor(h*360)+", "+Math.floor(s*100)+"%, "+Math.floor(l*100)+"%)"; - }, - - componentToHex: function(c) { - var hex = c.toString(16); - return hex.length == 1 ? "0" + hex : hex; - }, - - rgbToHex: function(r, g, b) { - return "#" + Helper.componentToHex(r) + Helper.componentToHex(g) + Helper.componentToHex(b); - }, - - upperFirst: function(string){ - return string.substring(0,1).toUpperCase()+string.substring(1).toLowerCase(); - }, - - addClass: function(object, toAdd){ - if(!Helper.contains($(object).attr("class").split(" "), toAdd)){ - $(object).addClass(toAdd); - } - }, - - send_mail: function(from, message){ - - - if(from != "" && message != ""){ - - $("#submit-contact-form").addClass("hide"); - $("#send-loader").removeClass("hide"); - $("#contact-form-from").attr("disabled", "true"); - $("#contact-form-message").attr("disabled", "true"); - - /* - $.ajax({ - type: "POST", - data: {from: from, message: message}, - url: "/php/mail.php", - success: function(data){ - if(data == "success"){ - $("#contact-container").empty(); - $("#contact-container").html("Mail has been sent, we'll be back with you shortly.") - }else{ - $("#contact-container").empty(); - $("#contact-container").html("Something went wrong, sorry about that. You could instead try with your own mail-client: contact@zoff.no") - } - } - });*/ - var from = $("#contact-form-from").val(); - var message = $("#contact-form-message").val(); - $("#contact-container").empty(); - newWindow = window.open("mailto:contact@zoff.no?Subject=Contact%20Zoff&Body=" + message, "_blank"); - $("#contact-container").html("Something went wrong, sorry about that. You could instead try with your own mail-client: contact@zoff.no"); - setTimeout(function(){newWindow.close()},500); - } - } - -} - -$(document).on('submit', '#contact-form', function(e){ - e.preventDefault(); - - var message = $("#contact-form-message").val(); - var from = $("#contact-form-from").val(); - - Helper.send_mail(from, message); -}); - - -Element.prototype.remove = function() { - this.parentElement.removeChild(this); -} - -NodeList.prototype.remove = HTMLCollection.prototype.remove = function() { - for(var i = 0, len = this.length; i < len; i++) { - if(this[i] && this[i].parentElement) { - this[i].parentElement.removeChild(this[i]); - } - } -} - - -String.prototype.startsWith = function(searchString, position) { - position = position || 0; - return this.indexOf(searchString, position) === position; -} -var Hostcontroller = { - - enabled: true, - - host_listener: function() { - - var old_id; - - socket.on("id", function(id) - { - if(old_id === undefined) old_id = id; - else - { - socket.removeAllListeners(id); - began = false; - old_id = id; - } - var codeURL = "https://remote."+window.location.hostname+"/"+id; - $("#code-text").text(id) - $("#code-qr").attr("src", "https://chart.googleapis.com/chart?chs=221x221&cht=qr&choe=UTF-8&chld=L|1&chl="+codeURL); - $("#code-link").attr("href", codeURL); - if(!began) - { - began = true; - socket.on(id, function(arr) - { - - if(enabled){ - if(arr[0] == "volume"){ - $("#volume").slider("value", arr[1]); - Player.ytplayer.setVolume(arr[1]); - localStorage.setItem("volume", arr[1]); - Playercontrols.choose_button(arr[1], false); - }else if(arr[0] == "channel"){ - console.log("changing channel"); - socket.emit("change_channel"); - Admin.beginning = true; - - chan = arr[1].toLowerCase(); - $("#chan").html(Helper.upperFirst(chan)); - - w_p = true; - socket.emit("list", chan.toLowerCase()); - - /*if(Crypt.get_pass(chan.toLowerCase()) !== undefined && Crypt.get_pass(chan.toLowerCase()) != ""){ - socket.emit("password", [Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase())), chan.toLowerCase()]); - }*/ - - window.history.pushState("object or string", "Title", "/"+chan.toLowerCase()); - }else if(arr[0] == "pause") - Player.ytplayer.pauseVideo() - else if(arr[0] == "play") - Player.ytplayer.playVideo(); - else if(arr[0] == "skip") - List.skip(); - } - }); - } - }); - - - $('input[class=remote_switch_class]').change(function() - { - enabled = document.getElementsByName("remote_switch")[0].checked; - Crypt.set_remote(enabled); - }); - }, - - change_enabled:function(val){ - enabled = val; - document.getElementsByName("remote_switch")[0].checked = enabled; - } -} -var List = { - - empty: false, - - channel_listener: function() - { - socket.on("channel", function(msg){ - List.channel_function(msg); - }); - }, - - channel_function: function(msg) - { - 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; - } - }, - - insertAtBeginning: function(song_info, transition) { - var add = List.generateSong(song_info, transition, false, true, false); - $("#wrapper").append(add); - }, - - insertAtIndex: function(song_info, transition) { - var i = List.getIndexOfSong(song_info.id); - - if(!song_info.now_playing){ - - var add = List.generateSong(song_info, transition, false, true, false); - if(i == 0) { - $("#wrapper").prepend(add); - } else { - $("#wrapper > div:nth-child(" + (i) + ")").after(add); - } - } - var added = $("#wrapper").children()[i]; - - if(transition) - { - setTimeout(function(){ - $(added).css("height", 66); - },5); - } - }, - - populate_list: function(msg) - { - if(list_html == undefined) list_html = $("#list-song-html").html(); - full_playlist = msg; - - List.sortList(); - $("#wrapper").empty(); - - if(full_playlist.length > 1){ - $.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, lazy_load, true)); - } - }); - - - if(lazy_load){ - if(window.mobilecheck()) $(".list-image").lazyload({}); - else{ - $(".list-image").lazyload({container: $("#wrapper")}).removeClass("lazy"); - - document.getElementById('wrapper').scrollTop += 1; - document.getElementById('wrapper').scrollTop += -1; - } - } - }else{ - List.empty = true; - $("#wrapper").append("The playlist is empty."); - } - $("#settings").css("visibility", "visible"); - $("#settings").css("opacity", "1"); - $("#wrapper").css("opacity", "1"); - }, - - added_song: function(added){ - now_playing = full_playlist.pop(); - full_playlist.push(added); - List.sortList(); - full_playlist.push(now_playing); - $("#suggested-"+added.id).remove(); - if(List.empty){ - List.empty = false; - } - $("#empty-channel-message").remove(); - List.insertAtIndex(added, true); - - }, - - deleted_song: function(deleted){ - - var index = List.getIndexOfSong(deleted); - var to_delete = $("#wrapper").children()[index]; - try{ - 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; - }catch(err){ - full_playlist.splice(List.getIndexOfSong(deleted), 1); - if(!List.empty) - $("#wrapper").children()[$("#wrapper").children().length-1].remove(); - } - if(full_playlist.length <= 2){ - List.empty = true; - $("#wrapper").append("The playlist is empty."); - } - $("#suggested-"+deleted).remove(); - Suggestions.checkUserEmpty(); - }, - - 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; - - try{ - full_playlist.push(full_playlist.shift()); - if(!List.empty) - $("#wrapper").children()[0].remove(); - if($("#wrapper").children().length == 0) { - List.empty = true; - $("#wrapper").append("The playlist is empty."); - } - List.insertAtIndex(full_playlist[length-1], false); - document.getElementById('wrapper').scrollTop += 1; - document.getElementById('wrapper').scrollTop += -1; - }catch(e){} - }, - - vote: function(id, vote){ - socket.emit('vote', [chan, id, vote, adminpass]); - return true; - }, - - skip: function(){ - socket.emit('skip', {pass: adminpass, id:video_id}); - return true; - }, - - importOldList: function(chan){ - var ids=""; - var num=0; - - playlist_url = "lists/"+chan+".json"; - - 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; - } - num++; - }); - - Search.addVideos(ids); - document.getElementById("search").value = ""; - }, - - sortList: function() - { - full_playlist.sort(Helper.predicate({ - name: 'votes', - reverse: true - }, 'added')); - }, - - show: function(){ - if(!window.mobilecheck()) - { - if(showToggle){ - showToggle=false; - $("#toptitle").empty(); - $("#chan").addClass("bigChan"); - //$("#chan").html("zoff.no/"+encodeURI(chan)); - $("#chan").html("zoff.no/"+chan.toLowerCase()); - }else{ - showToggle=true; - $("#toptitle").html("Zöff"); - $("#chan").removeClass("bigChan"); - $("#chan").html(chan); - } - } - }, - - generateSong: function(song_info, transition, lazy, list, user) - { - 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+"
    "); - var image_attr = "style"; - - var attr; - var del_attr; - - 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"); - if(lazy){ - video_thumb = "//img.youtube.com/vi/"+video_id+"/mqdefault.jpg"; - image_attr = "data-original"; - } - - if(list){ - song.find(".list-votes").text(video_votes); - song.find("#list-song").attr("id", video_id); - song.find(".vote-container").attr("title", video_title); - - attr = ".vote-container"; - del_attr = "del"; - }else if(!list){ - - song.find(".vote-text").text(song_info.duration); - - attr = ".add-suggested"; - if(user) - del_attr = "del_user_suggested"; - else - del_attr = "del_suggested"; - - song.find(".vote-container").attr("class", "clickable add-suggested"); - song.find(".add-suggested").attr("title", video_title); - song.find("#del").attr("id", del_attr); - song.find(attr).attr("data-video-title", video_title); - song.find(attr).attr("data-video-length", song_info.length); - song.find("#list-song").attr("id", "suggested-" + video_id); - song.find(".list-image").attr("class", song.find(".list-image").attr("class").replace("list-image", "list-suggested-image")); - - } - - song.find(".list-title").text(video_title); - song.find(".list-title").attr("title", video_title); - //song.find(".vote-container").attr("onclick", "vote('"+video_id+"','pos')"); - song.find(attr).attr("data-video-id", video_id); - song.find(".list-image").attr(image_attr,video_thumb); - song.find(".list-suggested-image").attr(image_attr,video_thumb); - song.find("#"+del_attr).attr("data-video-id", video_id); - //song.find("#del").attr("onclick", "vote('"+video_id+"', 'del')"); - - return song.html(); - }, - - getIndexOfSong: function(id) - { - indexes = $.map(full_playlist, function(obj, index) { - if(obj.id == id) { - return index; - } - }); - return indexes[0]; - }, - - scrollTop: function(){ - $("#wrapper").scrollTop(0); - }, - - scrollBottom: function(){ - $("#wrapper").scrollTop($("#wrapper")[0].scrollHeight); - } -} -var chan = window.chan == undefined ? $("#chan").html() : window.chan; -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 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 lazy_load = true; -var embed = false; -var autoplay = true; -var durationBegun = false; -var chat_active = false; -var chat_unseen = false; -var blinking = false; - -var result_html; -var empty_results_html; -var mobile_beginning; -var timeout_search; -var id; -var full_playlist; -var conf; -var blink_interval; -var tag; -var firstScriptTag; -var title; -var viewers; -var video_id; -var list; -var seekTo; -var song_title; -var previous_video_id; -var socket; -var connection_options = { - 'sync disconnect on unload':true, - 'secure': true, - 'force new connection': true -}; - - -if (navigator.serviceWorker) { - navigator.serviceWorker.register('/service-worker.js', {scope: '/'}) - .then(function (registration) { - console.log(registration); - }) - .catch(function (e) { - console.error(e); - }) -} else { - console.log('Service Worker is not supported in this browser.'); -} - -$().ready(function(){ - if(!window.fromFront && window.location.pathname != "/") init(); -}); - - -function init(){ - - chan = $("#chan").html(); - mobile_beginning = window.mobilecheck(); - var side = window.mobilecheck() ? "left" : "right"; - - window.onpopstate = function(e){ - onepage_load(); - } - - share_link_modifier_channel(); - - if(window.location.hostname == "zoff.no") add = "https://zoff.no"; - else add = window.location.hostname; - - - //setTimeout(function(){ - if(Player != undefined) Player.stopInterval= false; - //window.vote = List.vote; - //window.submit = Search.submit; - //window.submitAndClose = Search.submitAndClose; - - - - $('ul.playlist-tabs').tabs(); - $('ul.playlist-tabs-loggedIn').tabs(); - $('.chatTabs').tabs(); - $("#settings").sideNav({ - menuWidth: 300, // Default is 240 - edge: side, // Choose the horizontal origin - closeOnClick: false // Closes side-nav on clicks, useful for Angular/Meteor - }); - $('.collapsible').collapsible({ - accordion : true // A setting that changes the collapsible behavior to expandable instead of the default accordion style - }); - result_html = $("#temp-results-container"); - empty_results_html = $("#empty-results-container").html(); - - //awdwad - $(".video-container").resizable({ - start: function(event, ui) { - $('iframe').css('pointer-events','none'); - }, - stop: function(event, ui) { - $('iframe').css('pointer-events','auto'); - Crypt.set_width($(this).width()); - }, - handles: "e", - minWidth: 350 - }); - - /* - if(localStorage[chan.toLowerCase()]) - { - if(localStorage[chan.toLowerCase()].length != 64) - localStorage.removeItem(chan.toLowerCase()); - else - socket.emit("password", [localStorage[chan.toLowerCase()], chan.toLowerCase()]); - }*/ - - - socket = io.connect(''+add+':8880', connection_options); - Player.setup_youtube_listener(chan); - - Admin.admin_listener(); - List.channel_listener(); - - socket.on("get_list", function(){ - //setTimeout(function(){ - socket.emit('list', chan.toLowerCase()); - /*if(Crypt.get_pass(chan.toLowerCase()) != undefined){ - socket.emit("password", [Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase())), chan.toLowerCase()]); - }*/ - }); - - socket.on("suggested", function(params){ - var single = true; - if(params.id == undefined) - single = false; - //setTimeout(function(){ - Suggestions.catchUserSuggests(params, single); - //}, 1000); - }); - - socket.on("viewers", function(view) - { - viewers = view; - - if(song_title !== undefined) - Player.getTitle(song_title, viewers); - }); - - - if(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream){ - document.getElementById("search").blur(); - $("#channel-load").css("display", "none"); - } else { - window.onYouTubeIframeAPIReady = Player.onYouTubeIframeAPIReady; - Player.loadPlayer(); - } - - if(window.mobilecheck()) Mobile_remote.initiate_volume(); - - Chat.setup_chat_listener(chan); - Chat.allchat_listener(); - if(!window.mobilecheck()) Hostcontroller.host_listener(); - - if(!Helper.msieversion()) Notification.requestPermission(); - - $(".search_input").focus(); - - - git_info = $.ajax({ type: "GET", - url: "https://api.github.com/repos/zoff-music/zoff/commits", - async: false - }).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+"'); - $("#search").attr("placeholder", "Find song on YouTube..."); - -} - -window.init = init; - -$(document).keyup(function(e) { - 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"); - } -}); - -$('input[class=conf]').change(function() -{ - Admin.save(); -}); - -$("#clickme").click(function(){ - Player.ytplayer.playVideo(); -}); - -$(document).on("submit", "#listImport", function(){ - Search.importPlaylist(document.getElementById("import").value); -}); - -$(window).focus(function(){ - $("#favicon").attr("href", "static/images/favicon.png"); - unseen = false; -}); - -$(document).on("change", "#autoplay", function() { - if(this.checked) { - $("#embed-area").val(''); - } else { - $("#embed-area").val(''); - } -}); - -$(document).on("click", "#playbutton_remote", function(e) { - e.preventDefault(); - Mobile_remote.play_remote(); -}); - -$(document).on("click", "#pausebutton_remote", function(e) { - e.preventDefault(); - Mobile_remote.pause_remote(); -}); - -$(document).on("click", "#skipbutton_remote", function(e) { - e.preventDefault(); - Mobile_remote.skip_remote(); -}); - -$(document).on("submit", "#remoteform", function(e) { - e.preventDefault(); - Mobile_remote.get_input($("#remote_channel").val()); -}); - -$(document).on("click", "#chat-btn", function(){ - $("#text-chat-input").focus(); - //$("#chat-btn").css("color", "white"); - $("#chat-btn i").css("opacity", 1); - clearInterval(blink_interval); - blink_interval_exists = false; - unseen = false; - $("#favicon").attr("href", "static/images/favicon.png"); -}); - -function searchTimeout(event) { - search_input = $(".search_input").val(); - - code = event.keyCode || event.which; - - if (code != 40 && code != 38 && code != 13 && code != 39 && code != 37 && - code != 17 && code != 16 && code != 225 && code != 18) { - clearTimeout(timeout_search); - if(search_input.length < 3){$("#results").html("");} - if(code == 13){ - Search.search(search_input); - }else{ - timeout_search = setTimeout(function(){ - Search.search(search_input); - }, 1000); - /*i = 0; - timer=100;*/ - } - } -} - -if(/iPad|iPhone|iPod/.test(navigator.userAgent)){ - $(document).on('keydown', '.search_input', function(event) { - searchTimeout(event); - }); -} else { - $(document).on('keyup', ".search_input", function(event) { - searchTimeout(event); - }); -} - -$(document).on("click", ".chat-tab", function(){ - $("#text-chat-input").focus(); -}); - - -$(document).on("click", "#skip", function(e){ - e.preventDefault(); - List.skip(); -}); - -$(document).on("click", "#chan", function(e){ - e.preventDefault(); - List.show(); -}); - -$(document).on("submit", "#adminForm", function(e){ - e.preventDefault(); - Admin.pass_save(); -}); - -$(document).on("click", ".chat-link", function(e){ - chat_active = true; - unseen = false; - chat_unseen = false; - $(".chat-link").attr("style", "color: white !important;"); - blinking = false; - $("#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){ - chat_active = false; - $("#chatPlaylist").css("display", "none"); - $("#wrapper").css("display", "block"); - $("#suggestions").css("display", "none"); -}); - -$(document).on("click", ".suggested-link", function(e){ - chat_active = false; - $("#chatPlaylist").css("display", "none"); - $("#wrapper").css("display", "none"); - $("#suggestions").css("display", "block"); -}); - -$(document).on("submit", "#chatForm", function(e){ - e.preventDefault(); - Chat.chat(document.getElementById("chatForm").input); -}); - -$(document).on("click", "#shuffle", function(e) -{ - e.preventDefault(); - Admin.shuffle(); -}); - -$(document).on("click", "#search-btn", function(e) -{ - e.preventDefault(); - Search.showSearch(); -}); - -$(document).on("click", "#song-title", function(e) -{ - e.preventDefault(); - Search.showSearch(); -}); - -$(document).on("click", "#admin-lock", function(e) -{ - e.preventDefault(); - Admin.log_out(); -}); - -$(document).on("click", "#closeSettings", function(e) -{ - e.preventDefault(); - Admin.hide_settings(); -}); - -$(document).on( "click", ".result-object", function(e){ - var $html = $(e.target); - var substr = $html.prop('outerHTML').substring(0,4); - if(substr != "= 48 && adminpass != "")) && $("#wrapper").scrollTop() > 0){ - $("#top-button").removeClass("hide"); - Helper.addClass("#bottom-button", "hide"); - }else if(y >= $("#playlist").height() - 18 && $("#wrapper").scrollTop() < $("#wrapper")[0].scrollHeight - $("#wrapper").height() - 1){ - $("#bottom-button").removeClass("hide"); - Helper.addClass("#top-button", "hide"); - }else{ - Helper.addClass("#bottom-button", "hide"); - Helper.addClass("#top-button", "hide"); - } -}); - -$(document).on("mouseleave", "#playlist", function(){ - Helper.addClass("#bottom-button", "hide"); - Helper.addClass("#top-button", "hide"); -}); - -$(document).on("click", "#top-button", function(){ - List.scrollTop(); -}); - -$(document).on("click", "#bottom-button", function(){ - List.scrollBottom(); -}); - -function share_link_modifier_channel(){ - $("#facebook-code-link").attr("href", "https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/" + chan.toLowerCase()); - $("#facebook-code-link").attr("onclick", "window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/" + chan.toLowerCase() + "', 'Share Playlist','width=600,height=300'); return false;"); - $("#twitter-code-link").attr("href", "http://twitter.com/intent/tweet?url=https://zoff.no/" + chan.toLowerCase() + "&text=Check%20out%20this%20playlist%20" + chan.toLowerCase() + "%20on%20Zöff!&via=zoffmusic") - $("#twitter-code-link").attr("onclick", "window.open('http://twitter.com/intent/tweet?url=https://zoff.no/" + chan.toLowerCase() + "/&text=Check%20out%20this%20playlist%20" + chan.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/" + chan.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/" + chan.toLowerCase() + "&choe=UTF-8&chld=L%7C1"); -} - -function onepage_load(){ - - var url_split = window.location.href.split("/"); - - if(url_split[3].substr(0,1) != "#!" && url_split[3] != "" && !(url_split.length == 5 && url_split[4].substr(0,1) == "#")){ - socket.emit("change_channel"); - Admin.beginning = true; - - chan = url_split[3].replace("#", ""); - $("#chan").html(Helper.upperFirst(chan)); - - w_p = true; - socket.emit("list", chan.toLowerCase()); - }else if(url_split[3] == ""){ - $("#channel-load").css("display", "block"); - window.scrollTo(0, 0); - - Player.stopInterval = true; - Admin.display_logged_out(); - Admin.beginning = true; - chan = ""; - began = false; - durationBegun = false; - $("#embed-button").css("display", "none"); - - - socket.removeAllListeners(); - - $.ajax({ - url: "php/nochan.php", - success: function(e){ - - socket.disconnect(); - - document.getElementById("volume-button").removeEventListener("click", Playercontrols.mute_video); - document.getElementById("playpause").removeEventListener("click", Playercontrols.play_pause); - document.getElementById("fullscreen").removeEventListener("click", Playercontrols.fullscreen); - - video_id = ""; - song_title = ""; - - $("meta[name=theme-color]").attr("content", "#2D2D2D"); - - if(!/iPad|iPhone|iPod/.test(navigator.userAgent)) Player.ytplayer.destroy(); - - $(".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"); - $("main").html($($(e)[67]).html()); - $(".page-footer").removeClass("padding-bottom-extra"); - $(".page-footer").removeClass("padding-bottom-novideo"); - $("#favicon").attr("href", "static/images/favicon.png"); - - if($("#alreadyfp").length == 1){ - window.initfp(); - }else { - window.fromChannel = true; - window.initfp(); - } - - if($("#alreadychannel").length == 0){ - $("head").append("
    "; - num++; - //if(num>19)break; - } - document.getElementById("preloader").style.display = "none"; - document.getElementById("searches").innerHTML = output; - //Materialize.fadeInImage('#channels'); - $("#channels").fadeIn(800); - $("#searchFrontpage").focus(); - }, - - sortFunction: function(a, b) { - var o1 = a[0]; - var o2 = b[0]; - - var p1 = a[4]; - var p2 = b[4]; - - if (o1 < o2) return 1; - if (o1 > o2) return -1; - if (p1 < p2) return 1; - if (p1 > p2) return -1; - return 0; - }, - - getCookie: function(cname) { - var name = cname + "="; - var ca = document.cookie.split(';'); - for(var i=0; i= list.length || i >= 8) i = 0; - - var id = list[i][1]; - - if(Nochan.blob_list[i] !== undefined){ - //$(".room-namer").css("opacity", 0); - setTimeout(function(){ - if(frontpage){ - $("#mega-background").css("background", "url(data:image/png;base64,"+Nochan.blob_list[i]+")"); - $("#mega-background").css("background-size" , "200%"); - $("#mega-background").css("opacity", 1); - $("#searchFrontpage").attr("placeholder", list[i][3]); - //$(".room-namer").css("opacity", 1); - } - },500); - }else{ - - var img = new Image(); - img.src = "/static/images/thumbnails/"+id+".jpg"; - - img.onerror = function(){ // Failed to load - $.ajax({ - type: "POST", - data: {id:id}, - url: "/php/imageblob.php", - success: function(data){ - Nochan.blob_list.push(data); - //data will contain the vote count echoed by the controller i.e. - //$(".room-namer").css("opacity", 0); - setTimeout(function(){ - $("#mega-background").css("background", "url(data:image/png;base64,"+data+")"); - $("#mega-background").css("background-size" , "200%"); - $("#mega-background").css("opacity", 1); - $("#searchFrontpage").attr("placeholder", list[i][3]); - //$(".room-namer").css("opacity", 1); - },500); - //then append the result where ever you want like - //$("span#votes_number").html(data); //data will be containing the vote count which you have echoed from the controller - - } - }); - }; - img.onload = function(){ // Loaded successfully - $("#mega-background").css("background", "url("+img.src+")"); - $("#mega-background").css("background-size" , "200%"); - $("#mega-background").css("opacity", 1); - $("#searchFrontpage").attr("placeholder", list[i][3]); - }; - - } - setTimeout(function(){ - if(Nochan.times_rotated == 50 && frontpage){ - Nochan.times_rotated = 0; - i = 0; - socket.emit("frontpage_lists"); - }else if(frontpage){ - Nochan.times_rotated += 1; - Nochan.add_backdrop(list, i+1); - } - },6000); - - }, - - start_snowfall: function(){ - setTimeout(function(){ - var x = Math.floor((Math.random() * window.innerWidth) + 1); - var snow = document.createElement("div"); - var parent = document.getElementsByClassName("mega")[0]; - - snow.className = "snow"; - //snow.attr("left", x); - snow.style.left = x+"px"; - snow.style.top = "0px"; - parent.appendChild(snow); - Nochan.fall_snow(snow); - Nochan.start_snowfall(); - }, 800); - }, - - fall_snow: function(corn){ - corn.style.top = (parseInt(corn.style.top.replace("px", ""))+2)+"px"; - if(parseInt(corn.style.top.replace("px", "")) < document.getElementById("mega-background").offsetHeight-2.5){ - setTimeout(function(){ - Nochan.fall_snow(corn); - },50); - }else{ - corn.remove(); - } - }, - - set_viewers: function(viewers){ - if(viewers > 0){ - var to_add = viewers > 1 ? "listeners" : "listener"; - $("#frontpage-viewer-counter").html(viewers + " " + to_add); - } - }, - - to_channel: function(chan, popstate){ - - $("#channel-load").css("display", "block"); - window.scrollTo(0, 0); - frontpage = false; - - socket.removeAllListeners(); - - $.ajax({ - url: chan + "/php/index.php", - - success: function(e){ - - $("body").css("background-color", "#2d2d2d"); - socket.disconnect(); - - if(!popstate){ - window.history.pushState("to the channel!", "Title", "/" + chan); - window.chan = chan; - } - - $(".mega").remove(); - $(".mobile-search").remove(); - $("main").attr("class", "container center-align main"); - $("body").attr("id", "channelpage"); - $("header").html($($(e)[59]).html()); - $("main").html($($(e)[63]).html()); - $("#search").attr("placeholder", "Find song on YouTube..."); - $(".page-footer").addClass("padding-bottom-novideo"); - if($("#alreadychannel").length == 1){ - window.init(); - }else{ - window.fromFront = true; - window.init(); - } - if($("#alreadyfp").length == 0) $("head").append("
    "); - - } - }); - } - -} - -String.prototype.capitalizeFirstLetter = function() { - return this.charAt(0).toUpperCase() + this.slice(1); -} - -$().ready(function(){ - if(!window.fromChannel && window.location.pathname == "/") initfp(); -}); - -function share_link_modifier_frontpage(){ - $("#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 initfp(){ - - var date = new Date(); - - if(date.getMonth() == 3 && date.getDate() == 1){ - $(".mega").css("-webkit-transform", "rotate(180deg)"); - $(".mega").css("-moz-transform", "rotate(180deg)"); - //Materialize.toast('

    We suck at pranks..Agreed

    ', 100000); - } - - - window.onpopstate = function(e){ - var url_split = window.location.href.split("/"); - - if(url_split[3] != "" && url_split[3].substring(0,1) != "#"){ - Nochan.to_channel(url_split[3], true); - } - } - - channel_list = $("#channel-list-container").html(); - - share_link_modifier_frontpage(); - - var connection_options = { - 'secure': true, - 'force new connection': true - }; - - if(window.location.hostname == "zoff.no") add = "https://zoff.no"; - else add = window.location.hostname; - socket = io.connect(''+add+':8880', connection_options); - socket.on('playlists', function(msg){ - $("#channels").empty(); - - - Nochan.populate_channels(msg.channels); - - Nochan.set_viewers(msg.viewers); - }); - - - socket.emit('frontpage_lists'); - - $("#channel-load").css("display", "none"); - //Materialize.toast("Try out our new feature, remote!", 8000) - if(window.location.hash == "#donation") - { - window.location.hash = "#"; - $('#donation').openModal() - } - //window.channel_list = channel_list; - - - if(!localStorage["ok_cookie"]) - Materialize.toast("We're using cookies to enhance your experience! ok", 10000); - - var pad = 0; - document.getElementById("zicon").addEventListener("click", function(){ - pad+=10; - document.getElementById("zicon").style.paddingLeft = pad+"%"; - if(pad >= 100) - window.location.href = 'http://etys.no'; - }); - - if(!window.mobilecheck() && Nochan.winter) Nochan.start_snowfall(); - - /*if(navigator.userAgent.toLowerCase().indexOf("android") > -1){ - //console.log("android"); - if(Nochan.getCookie("show_prompt") == ""){ - var r = confirm("Do you want to download the native app for this webpage?"); - if(r) - window.location.href = 'https://play.google.com/store/apps/details?id=no.lqasse.zoff'; - else - { - var d = new Date(); - d.setTime(d.getTime() + (10*24*60*60*1000)); - var expires = "expires="+d.toUTCString(); - document.cookie = "show_prompt=false;"+expires; - } - } - }*/ - - git_info = $.ajax({ type: "GET", - url: "https://api.github.com/repos/zoff-music/zoff/commits", - async: false - }).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+" 1 ? "viewers" : "viewer"; - var title = decodeURIComponent(titt); - var elem = document.getElementById('song-title'); - var getTitleViews = document.getElementById('viewers'); - - document.title = title + " • Zöff / "+chan; - elem.innerHTML = title; - getTitleViews.innerHTML = v + " " + outPutWord; - elem.title = title + " • " + v + " " + outPutWord; - - }, - - errorHandler: function(newState) - { - if(newState.data == 5 || newState.data == 100 - || newState.data == 101 || newState.data == 150) - { - /*if(Player.count == 2){ - Player.count = 0;*/ - /*console.log("Before: " + Player.before_load); - console.log("Now: " + video_id); - console.log("After: " + Player.after_load); - console.log(Player.before_load == Player.ytplayer.getVideoUrl);*/ - curr_playing = Player.ytplayer.getVideoUrl().replace("https://www.youtube.com/watch?v=", ""); - - - socket.emit("skip", {error: newState.data, id: video_id, pass: adminpass}); - //console.log(video_id, Player.ytplayer.getVideoUrl(), Player.ytplayer.getPlayerState()); - - /*}else{ - setTimeout(function(){ - Player.ytplayer.loadVideoById(video_id); - Player.count ++; - }, Math.floor((Math.random() * 100) + 1)); - }*/ - }else if(video_id !== undefined) - Player.ytplayer.loadVideoById(video_id); - }, - - onPlayerReady: function(event) { - $("#channel-load").css("display", "none"); - try{ - beginning = true; - player_ready = true; - if(!window.MSStream) - { - $("#player").css("opacity", "1"); - $("#controls").css("opacity", "1"); - $(".playlist").css("opacity", "1"); - Player.ytplayer.loadVideoById(video_id); - if(autoplay && !window.mobilecheck()) Player.ytplayer.playVideo(); - if(!durationBegun) - Player.durationSetter(); - if(embed){ - setTimeout(function(){ - Player.ytplayer.seekTo(seekTo); - if(!autoplay){ - Player.ytplayer.pauseVideo(); - Playercontrols.play_pause_show(); - } - }, 1000); - }else - Player.ytplayer.seekTo(seekTo); - } - Player.readyLooks(); - Playercontrols.initYoutubeControls(Player.ytplayer); - Playercontrols.initSlider(); - Player.ytplayer.setVolume(Crypt.get_volume()); - $(".video-container").removeClass("no-opacity"); - }catch(e){} - }, - - readyLooks: function() - { - Player.setBGimage(video_id); - }, - - setBGimage: function(id){ - - if(id !== undefined && !embed) - { - var img = new Image(); - img.onload = function () - { - - var colorThief = new ColorThief(); - var color = colorThief.getColor(img); - - document.getElementsByTagName("body")[0].style.backgroundColor = Helper.rgbToHsl(color,true); - /*document.getElementById("top-button").style.backgroundColor = Helper.rgbToHsl(color); - document.getElementById("bottom-button").style.backgroundColor = Helper.rgbToHsl(color);*/ - - $("meta[name=theme-color]").attr("content", Helper.rgbToHex(color[0], color[1], color[2])); - }; - - img.crossOrigin = 'Anonymous'; - img.src = 'https://zoff.no:8080/https://img.youtube.com/vi/'+id+'/mqdefault.jpg'; - } - }, - - set_width: function(val){ - $(".video-container").width(val); - }, - - notifyUser: function(id, title) { - title = title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&"); - if (Notification.permission === "granted" && document.hidden) { - 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(); }; - setTimeout(function(){ - notification.close(); - },5000); - } - }, - - setup_all_listeners: function() - { - socket.on("get_list", function(){ - socket.emit('list', chan.toLowerCase()); - }); - Player.setup_youtube_listener(chan); - Admin.admin_listener(); - Chat.setup_chat_listener(chan); - Chat.allchat_listener(); - List.channel_listener(); - }, - - onYouTubeIframeAPIReady: function() { - Player.ytplayer = new YT.Player('player', { - videoId: video_id, - playerVars: { rel:"0", wmode:"transparent", controls: "0" , iv_load_policy: "3", theme:"light", color:"white", showinfo: 0}, - events: { - 'onReady': Player.onPlayerReady, - 'onStateChange': Player.onPlayerStateChange, - 'onError': Player.errorHandler - } - }); - //Youtube.durationSetter(); - }, - - durationSetter: function() - { - /*try{ - //duration = Player.ytplayer.getDuration(); - }catch(e){};*/ - if(duration != undefined){ - try{ - if(!Player.stopInterval) durationBegun = true; - dMinutes = Math.floor(duration / 60); - dSeconds = duration - dMinutes * 60; - currDurr = Player.ytplayer.getCurrentTime() != undefined ? Math.floor(Player.ytplayer.getCurrentTime()) : seekTo; - if(currDurr > duration) - currDurr = duration; - minutes = Math.floor(currDurr / 60); - seconds = currDurr - (minutes * 60); - document.getElementById("duration").innerHTML = Helper.pad(minutes)+":"+Helper.pad(seconds)+" / "+Helper.pad(dMinutes)+":"+Helper.pad(dSeconds); - per = (100 / duration) * currDurr; - if(per >= 100) - per = 100; - else if(duration == 0) - per = 0; - $("#bar").width(per+"%"); - }catch(e){ - - } - } - if(!Player.stopInterval) setTimeout(Player.durationSetter, 1000); - }, - - loadPlayer: function() { - if($("script[src='https://www.youtube.com/iframe_api']")["length"] == 1){ - Player.onYouTubeIframeAPIReady(); - }else{ - tag = document.createElement('script'); - tag.src = "https://www.youtube.com/iframe_api"; - firstScriptTag = document.getElementsByTagName('script')[0]; - firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); - } - } - -} -var Playercontrols = { - - stopInterval: false, - - initYoutubeControls: function() - { - if(window.mobilecheck() && !/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream){ - $("#controls").appendTo("#playbar"); - } - Playercontrols.initControls(); - }, - - initControls: function() - { - document.getElementById("volume-button").addEventListener("click", Playercontrols.mute_video); - document.getElementById("playpause").addEventListener("click", Playercontrols.play_pause); - document.getElementById("fullscreen").addEventListener("click", Playercontrols.fullscreen); - - }, - - initSlider: function() - { - try{ - vol = (Crypt.get_volume()); - }catch(e){} - $("#volume").slider({ - min: 0, - max: 100, - value: vol, - range: "min", - animate: true, - slide: function(event, ui) { - - Playercontrols.setVolume(ui.value); - //localStorage.setItem("volume", ui.value); - try{Crypt.set_volume(ui.value);}catch(e){} - } - }); - Playercontrols.choose_button(vol, false); - //$("#volume").slider("value", ytplayer.getVolume()); - }, - - fullscreen: function() - { - var playerElement = document.getElementById("player"); - var requestFullScreen = playerElement.requestFullScreen || playerElement.mozRequestFullScreen || playerElement.webkitRequestFullScreen; - if (requestFullScreen) { - requestFullScreen.bind(playerElement)(); - } - }, - - play_pause: function() - { - - if(Player.ytplayer.getPlayerState() == 1) - { - Player.ytplayer.pauseVideo(); - if(window.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"); - } - }else if(Player.ytplayer.getPlayerState() == 2 || Player.ytplayer.getPlayerState() == 0) - { - Player.ytplayer.playVideo(); - if(window.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() - { - if(document.getElementById("pause").className.split(" ").length == 1) - $("#pause").toggleClass("hide"); - if(document.getElementById("play").className.split(" ").length == 2) - $("#play").toggleClass("hide"); - }, - - settings: function() - { - $("#qS").toggleClass("hide"); - }, - - changeQuality: function(wantedQ) - { - if(Player.ytplayer.getPlaybackQuality != wantedQ) - { - Player.ytplayer.setPlaybackQuality(wantedQ); - Player.ytplayer.getPlaybackQuality(); - } - $("#qS").toggleClass("hide"); - }, - - mute_video: function() - { - if(!Player.ytplayer.isMuted()) - { - Playercontrols.choose_button(0, true); - Player.ytplayer.mute(); - }else - { - Player.ytplayer.unMute(); - Playercontrols.choose_button(Player.ytplayer.getVolume(), false); - } - }, - - setVolume: function(vol) - { - Player.ytplayer.setVolume(vol); - Playercontrols.choose_button(vol, false); - if(Player.ytplayer.isMuted()) - Player.ytplayer.unMute(); - }, - - choose_button: function(vol, mute) - { - if(!mute){ - if(vol >= 0 && vol <= 33){ - if(document.getElementById("v-full").className.split(" ").length == 1) - $("#v-full").toggleClass("hide"); - if(document.getElementById("v-medium").className.split(" ").length == 1) - $("#v-medium").toggleClass("hide"); - if(document.getElementById("v-low").className.split(" ").length == 2) - $("#v-low").toggleClass("hide"); - if(document.getElementById("v-mute").className.split(" ").length == 1) - $("#v-mute").toggleClass("hide"); - }else if(vol >= 34 && vol <= 66){ - if(document.getElementById("v-full").className.split(" ").length == 1) - $("#v-full").toggleClass("hide"); - if(document.getElementById("v-medium").className.split(" ").length == 2) - $("#v-medium").toggleClass("hide"); - if(document.getElementById("v-low").className.split(" ").length == 1) - $("#v-low").toggleClass("hide"); - if(document.getElementById("v-mute").className.split(" ").length == 1) - $("#v-mute").toggleClass("hide"); - }else if(vol >= 67 && vol <= 100){ - if(document.getElementById("v-full").className.split(" ").length == 2) - $("#v-full").toggleClass("hide"); - if(document.getElementById("v-medium").className.split(" ").length == 1) - $("#v-medium").toggleClass("hide"); - if(document.getElementById("v-low").className.split(" ").length == 1) - $("#v-low").toggleClass("hide"); - if(document.getElementById("v-mute").className.split(" ").length == 1) - $("#v-mute").toggleClass("hide"); - } - }else - { - if(document.getElementById("v-full").className.split(" ").length == 1) - $("#v-full").toggleClass("hide"); - if(document.getElementById("v-medium").className.split(" ").length == 1) - $("#v-medium").toggleClass("hide"); - if(document.getElementById("v-low").className.split(" ").length == 1) - $("#v-low").toggleClass("hide"); - if(document.getElementById("v-mute").className.split(" ").length == 2) - $("#v-mute").toggleClass("hide"); - } - }, - - playPause: function() - { - state = Player.ytplayer.getPlayerState(); - button = document.getElementById("playpause"); - if(state == 1) - { - Player.ytplayer.pauseVideo(); - }else if(state == 2) - { - Player.ytplayer.playVideo(); - } - }, - - volumeOptions: function() - { - if(Player.ytplayer.isMuted()) - { - Player.ytplayer.unMute(); - vol = Player.ytplayer.getVolume(); - $("#volume").slider("value", Player.ytplayer.getVolume()); - } - else - { - Player.ytplayer.mute(); - $("#volume").slider("value", 0); - } - }, - - hoverMute: function(foo) - { - vol = Player.ytplayer.getVolume(); - - } - -} -var Search = { - - showSearch: function(){ - $("#search-wrapper").toggleClass("hide"); - if(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(search_input){ - if(result_html == undefined || empty_results_html == undefined) { - result_html = $("#temp-results-container"); - empty_results_html = $("#empty-results-container").html(); - } - $(".search_results").html(''); - if(window.search_input !== ""){ - searching = true; - var keyword= encodeURIComponent(window.search_input); - //response= x - var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key+"&videoEmbeddable=true&part=id&fields=items(id)&type=video&order=viewCount&safeSearch=none&maxResults=25"; - yt_url+="&q="+keyword; - if(music)yt_url+="&videoCategoryId=10"; - - var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id="; - - if(Helper.contains($("#search_loader").attr("class").split(" "), "hide")) - $("#search_loader").removeClass("hide"); - - if(Helper.contains($("#results").attr("class").split(" "), "hide")) - $("#results").removeClass("hide"); - - $.ajax({ - type: "GET", - url: yt_url, - dataType:"jsonp", - success: function(response){ - if(response.items.length == 0) - { - - $("").appendTo($("#results")).show("blind", 83.33); - if(!Helper.contains($("#search_loader").attr("class").split(" "), "hide")) - $("#search_loader").addClass("hide"); - - }else if(response.items){ - //get list of IDs and make new request for video info - $.each(response.items, function(i,data) - { - vid_url += data.id.videoId+","; - }); - - $.ajax({ - type: "GET", - url: vid_url, - dataType:"jsonp", - success: function(response){ - - var output = ""; - var pre_result = $(result_html); - - //$("#results").append(result_html); - - $.each(response.items, function(i,song) - { - var duration=song.contentDetails.duration; - secs=Search.durationToSeconds(duration) - if(!longsongs || secs<720){ - title=song.snippet.title; - enc_title=title;//encodeURIComponent(title).replace(/'/g, "\\\'"); - id=song.id; - duration = duration.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s") - thumb=song.snippet.thumbnails.medium.url; - - //$("#results").append(result_html); - var songs = pre_result; - - songs.find(".search-title").text(title); - songs.find(".result_info").text(duration); - songs.find(".thumb").attr("data-original", thumb); - //songs.find(".add-many").attr("onclick", "submit('"+id+"','"+enc_title+"',"+secs+");"); - songs.find("#add-many").attr("data-video-id", id); - songs.find("#add-many").attr("data-video-title", enc_title); - songs.find("#add-many").attr("data-video-length", secs); - //$($(songs).find("div")[0]).attr("onclick", "submitAndClose('"+id+"','"+enc_title+"',"+secs+");"); - songs.find("#temp-results").attr("data-video-id", id); - songs.find("#temp-results").attr("data-video-title", enc_title); - songs.find("#temp-results").attr("data-video-length", secs); - //$($(songs).find("div")[0]).attr("id", id) - output += songs.html(); - - } - }); - - $("").appendTo($("#results")).show("blind", (response.items.length-1) * 83.33); - - setTimeout(function(){$(".thumb").lazyload({container: $("#results")})}, 250); - - if(!Helper.contains($("#search_loader").attr("class").split(" "), "hide")) - $("#search_loader").addClass("hide"); - - $(".add-many").click(function(e) { - e.preventDefault(); - e.stopPropagation(); - return false; - }); - } - }); - } - } - }); - - }else{ - $(".main").removeClass("blurT"); - $("#controls").removeClass("blurT"); - $(".main").removeClass("clickthrough"); - } - }, - - submitAndClose: function(id,title,duration){ - Search.submit(id,title, duration); - $("#results").html(''); - Search.showSearch(); - document.getElementById("search").value = ""; - $("#results").html = ""; - $(".main").removeClass("blurT"); - $("#controls").removeClass("blurT"); - $(".main").removeClass("clickthrough"); - }, - - importPlaylist: function(pId,pageToken){ - token = ""; - if(pageToken !== undefined) - token = "&pageToken="+pageToken; - playlist_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+api_key+"&playlistId="+pId+token; - $.ajax({ - type: "GET", - url: playlist_url, - dataType:"jsonp", - success: function(response) - { - var ids=""; - //Search.addVideos(response.items[0].contentDetails.videoId); - //response.items.shift(); - $.each(response.items, function(i,data) - { - ids+=data.contentDetails.videoId+","; - }); - Search.addVideos(ids, true); - if(response.nextPageToken) Search.importPlaylist(pId, response.nextPageToken); - document.getElementById("import").value = ""; - } - }); - }, - - addVideos: function(ids, playlist){ - var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=***REMOVED***&id="; - request_url += ids; - - $.ajax({ - type: "POST", - url: request_url, - dataType:"jsonp", - success: function(response){ - $.each(response.items, function(i,song) - { - var duration=Search.durationToSeconds(song.contentDetails.duration); - if(!longsongs || duration<720){ - enc_title= song.snippet.title;//encodeURIComponent(song.snippet.title); - Search.submit(song.id, enc_title, duration, playlist); - } - }); - - } - }); - }, - - submit: function(id,title,duration, playlist){ - socket.emit("add", {id: id, title: decodeURIComponent(title), adminpass: adminpass, list: chan.toLowerCase(), duration: duration, playlist: playlist}); - //[id, decodeURIComponent(title), adminpass, duration, playlist]); - }, - - durationToSeconds: function(duration) { - var matches = duration.match(time_regex); - hours= parseInt(matches[12])||0, - minutes= parseInt(matches[14])||0, - seconds= parseInt(matches[16])||0 - return hours*60*60+minutes*60+seconds; - } - -} -var Suggestions = { - - catchUserSuggests: function(params, single){ - if(single){ - Suggestions.createSuggested(params); - }else{ - for(x in params){ - Suggestions.createSuggested(params[x]); - } - } - Suggestions.checkUserEmpty(); - }, - - createSuggested: function(params){ - var secs = params.duration; - var video_id = params.id; - var video_title = params.title; - var minutes = Math.floor(secs / 60); - var seconds = secs - minutes * 60; - - duration = minutes+"m " + seconds + "s"; - - var song = List.generateSong({id: video_id, title: video_title, length: secs, duration: duration}, false, false, false, true); - $("#user-suggest-html").append(song); - }, - - fetchYoutubeSuggests: function(id){ - - var get_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&relatedToVideoId="+id+"&type=video&key="+api_key; - var video_urls = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id="; - - $.ajax({ - type: "GET", - url: get_url, - dataType:"jsonp", - success: function(response) - { - $.each(response.items.slice(0,5), function(i,data){ - video_urls += data.id.videoId+","; - }); - - $.ajax({ - type: "GET", - url: video_urls, - dataType: "jsonp", - success: function(response) - { - $("#suggest-song-html").empty(); - - $.each(response.items, function(i,song) - { - var duration = song.contentDetails.duration; - var secs = Search.durationToSeconds(duration); - var video_id = song.id; - var video_title = song.snippet.title; - - duration = duration.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s") - - $("#suggest-song-html").append(List.generateSong({id: video_id, title: video_title, length: secs, duration: duration}, false, false, false)); - }); - } - }); - } - }); - }, - - checkUserEmpty: function(){ - var length = $("#user-suggest-html").children().length - if(length == 0){ - if(!Helper.contains($("#user_suggests").attr("class").split(" "), "hide")) - $("#user_suggests").addClass("hide"); - }else{ - $("#user_suggests").removeClass("hide"); - } - }, - -} \ No newline at end of file +!function(){function e(){A=$("#chan").html(),m=window.mobilecheck();var e=window.mobilecheck()?"left":"right";window.onpopstate=function(e){n()},o(),"zoff.no"==window.location.hostname?add="https://zoff.no":add=window.location.hostname,void 0!=ge&&(ge.stopInterval=!1),$("ul.playlist-tabs").tabs(),$("ul.playlist-tabs-loggedIn").tabs(),$(".chatTabs").tabs(),$("#settings").sideNav({menuWidth:300,edge:e,closeOnClick:!1}),$(".collapsible").collapsible({accordion:!0}),u=$("#temp-results-container"),p=$("#empty-results-container").html(),$(".video-container").resizable({start:function(e,t){$("iframe").css("pointer-events","none")},stop:function(e,t){$("iframe").css("pointer-events","auto"),c.set_width($(this).width())},handles:"e",minWidth:350}),M=io.connect(""+add+":8880",ce),ge.setup_youtube_listener(A),s.admin_listener(),P.channel_listener(),M.on("get_list",function(){M.emit("list",A.toLowerCase())}),M.on("suggested",function(e){var t=!0;void 0==e.id&&(t=!1),ye.catchUserSuggests(e,t)}),M.on("viewers",function(e){I=e,void 0!==B&&ge.getTitle(B,I)}),/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream?(document.getElementById("search").blur(),$("#channel-load").css("display","none")):(window.onYouTubeIframeAPIReady=ge.onYouTubeIframeAPIReady,ge.loadPlayer()),window.mobilecheck()&&pe.initiate_volume(),l.setup_chat_listener(A),l.allchat_listener(),window.mobilecheck()||z.host_listener(),d.msieversion()||Notification.requestPermission(),$(".search_input").focus(),ue=$.ajax({type:"GET",url:"https://api.github.com/repos/zoff-music/zoff/commits",async:!1}).responseText,ue=$.parseJSON(ue),$("#latest-commit").html("Latest Commit:
    "+ue[0].commit.author.date.substring(0,10)+": "+ue[0].committer.login+"
    "+ue[0].sha.substring(0,10)+": "+ue[0].commit.message+"'),$("#search").attr("placeholder","Find song on YouTube...")}function t(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(h),search_input.length<3&&$("#results").html(""),13==code?fe.search(search_input):h=setTimeout(function(){fe.search(search_input)},1e3))}function o(){$("#facebook-code-link").attr("href","https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/"+A.toLowerCase()),$("#facebook-code-link").attr("onclick","window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.no/"+A.toLowerCase()+"', 'Share Playlist','width=600,height=300'); return false;"),$("#twitter-code-link").attr("href","http://twitter.com/intent/tweet?url=https://zoff.no/"+A.toLowerCase()+"&text=Check%20out%20this%20playlist%20"+A.toLowerCase()+"%20on%20Zöff!&via=zoffmusic"),$("#twitter-code-link").attr("onclick","window.open('http://twitter.com/intent/tweet?url=https://zoff.no/"+A.toLowerCase()+"/&text=Check%20out%20this%20playlist%20"+A.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/"+A.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/"+A.toLowerCase()+"&choe=UTF-8&chld=L%7C1")}function n(){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),ge.stopInterval=!0,s.display_logged_out(),s.beginning=!0,A="",ee=!1,ie=!1,$("#embed-button").css("display","none"),M.removeAllListeners(),$.ajax({url:"php/nochan.php",success:function(e){M.disconnect(),document.getElementById("volume-button").removeEventListener("click",he.mute_video),document.getElementById("playpause").removeEventListener("click",he.play_pause),document.getElementById("fullscreen").removeEventListener("click",he.fullscreen),T="",B="",$("meta[name=theme-color]").attr("content","#2D2D2D"),/iPad|iPhone|iPod/.test(navigator.userAgent)||ge.ytplayer.destroy(),$(".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"),$("main").html($($(e)[67]).html()),$(".page-footer").removeClass("padding-bottom-extra"),$(".page-footer").removeClass("padding-bottom-novideo"),$("#favicon").attr("href","static/images/favicon.png"),1==$("#alreadyfp").length?window.initfp():(window.fromChannel=!0,window.initfp()),0==$("#alreadychannel").length&&$("head").append("
    ok",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")}),!window.mobilecheck()&&me.winter&&me.start_snowfall(),ue=$.ajax({type:"GET",url:"https://api.github.com/repos/zoff-music/zoff/commits",async:!1}).responseText,ue=$.parseJSON(ue),$("#latest-commit").html("Latest Commit:
    "+ue[0].commit.author.date.substring(0,10)+": "+ue[0].committer.login+"
    "+ue[0].sha.substring(0,10)+": "+ue[0].commit.message+"150||(e.value.startsWith("/name ")?l.namechange(e.value.substring(6)):e.value.startsWith("/removename")?l.removename():"#all_chat"==$(".chat-tab-li a.active").attr("href")?M.emit("all,chat",e.value):M.emit("chat",e.value),e.value="")},allchat_listener:function(){M.on("chat.all",function(e){q||":"!=e[1].substring(0,1)||se||($("#favicon").attr("href","static/images/highlogo.png"),q=!0,O=!0,le=!0,re||l.chat_blink()),document.hidden&&$("#favicon").attr("href","static/images/highlogo.png");var t=d.intToARGB(d.hashCode(e[0]));if(t.length<6)for(x=t.length;x<6;x++)t="0"+t;t=d.hexToRgb(t.substring(0,6));var o=d.rgbToHsl([t.r,t.g,t.b],!1);$("#chatall").append("
  • "+e[0]+"
  • ");var n=document.createTextNode(e[1]);$("#chatall li:last")[0].appendChild(n),document.getElementById("chatall").scrollTop=document.getElementById("chatall").scrollHeight})},setup_chat_listener:function(e){M.on("chat",function(e){q||":"!=e[1].substring(0,1)||se||($("#favicon").attr("href","static/images/highlogo.png"),O=!0,le=!0,re||l.chat_blink());var t=d.intToARGB(d.hashCode(e[0]));if(t.length<6)for(x=t.length;x<6;x++)t="0"+t;t=d.hexToRgb(t.substring(0,6));var o=d.rgbToHsl([t.r,t.g,t.b],!1);$("#chatchannel").append("
  • "+e[0]+"
  • ");var n=document.createTextNode(e[1]);$("#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&&l.chat_blink()},1e3)},1e3)}},c={conf_pass:void 0,init:function(){document.cookie=A.toLowerCase()+"=; path=/"+A.toLowerCase()+"; expires="+new Date(0).toUTCString();try{conf_arr=c.decrypt(c.getCookie("_opt"),"_opt")}catch(e){conf_arr=c.decrypt(c.create_cookie("_opt"),"_opt")}try{c.conf_pass=c.decrypt(c.getCookie(A.toLowerCase()),A.toLowerCase())}catch(e){c.conf_pass=c.decrypt(c.create_cookie(A.toLowerCase()),A.toLowerCase())}z.change_enabled(conf_arr.remote),100!=conf_arr.width&&ge.set_width(conf_arr.width),void 0!=conf_arr.name&&""!=conf_arr.name&&l.namechange(conf_arr.name)},decrypt:function(e,t){void 0===c.getCookie(t)&&(e=c.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,M.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,M.id,{mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});return t.toString()},get_volume:function(){return c.decrypt(c.getCookie("_opt"),"_opt").volume},set_volume:function(e){conf_arr.volume=e,c.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=/;",c.getCookie(e)},set_pass:function(e,t){c.conf_pass.passwords[e]=t,c.encrypt(c.conf_pass,e)},remove_pass:function(e){delete c.conf_pass.passwords[e],c.encrypt(c.conf_pass,e.toLowerCase())},set_name:function(e){conf_arr.name=e,c.encrypt(conf_arr,"_opt")},remove_name:function(){conf_arr.name="",c.encrypt(conf_arr,"_opt")},get_pass:function(e){return void 0!=c.conf_pass?c.conf_pass.passwords[e]:void 0},set_remote:function(e){conf_arr.remote=e,c.encrypt(conf_arr,"_opt")},get_remote:function(e){return conf_arr.remote},crypt_pass:function(e){var t=CryptoJS.AES.encrypt(e,M.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,c.encrypt(conf_arr,"_opt")},getCookie:function(e){var t="; "+document.cookie,o=t.split("; "+e+"=");return 2==o.length?o.pop().split(";").shift():void 0}};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 d={rnd:function(e){return e[Math.floor(Math.random()*e.length)]},predicate:function(){for(var e,t,o,n=[],a=arguments.length,i=function(e,t){return e===t?0:t>e?-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;a>l;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;a>l&&(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>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 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()-X>=2*K&&(M.removeAllListeners(),M.disconnect(),M.connect(),ge.setup_all_listeners()),X=Date.now(),setTimeout(d.sample,K)},loadjsfile:function(e){if(-1==G.indexOf("["+e+"]")){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),G+="["+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,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.5&&t?s=.5:.65>s&&!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"#"+d.componentToHex(e)+d.componentToHex(t)+d.componentToHex(o)},upperFirst:function(e){return e.substring(0,1).toUpperCase()+e.substring(1).toLowerCase()},addClass:function(e,t){d.contains($(e).attr("class").split(" "),t)||$(e).addClass(t)},send_mail:function(e,t){if(""!=e&&""!=t){$("#submit-contact-form").addClass("hide"),$("#send-loader").removeClass("hide"),$("#contact-form-from").attr("disabled","true"),$("#contact-form-message").attr("disabled","true");var 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: contact@zoff.no"),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();d.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;t>e;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 u,p,m,h,f,y,v,w,k,_,C,I,T,S,E,B,L,M,z={enabled:!0,host_listener:function(){var e;M.on("id",function(t){void 0===e?e=t:(M.removeAllListeners(t),ee=!1,e=t);var o="https://remote."+window.location.hostname+"/"+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),ee||(ee=!0,M.on(t,function(e){enabled&&("volume"==e[0]?($("#volume").slider("value",e[1]),ge.ytplayer.setVolume(e[1]),localStorage.setItem("volume",e[1]),he.choose_button(e[1],!1)):"channel"==e[0]?(console.log("changing channel"),M.emit("change_channel"),s.beginning=!0,A=e[1].toLowerCase(),$("#chan").html(d.upperFirst(A)),N=!0,M.emit("list",A.toLowerCase()),window.history.pushState("object or string","Title","/"+A.toLowerCase())):"pause"==e[0]?ge.ytplayer.pauseVideo():"play"==e[0]?ge.ytplayer.playVideo():"skip"==e[0]&&P.skip())}))}),$("input[class=remote_switch_class]").change(function(){enabled=document.getElementsByName("remote_switch")[0].checked,c.set_remote(enabled)})},change_enabled:function(e){enabled=e,document.getElementsByName("remote_switch")[0].checked=enabled}},P={empty:!1,channel_listener:function(){M.on("channel",function(e){P.channel_function(e)})},channel_function:function(e){switch(e[0]){case"list":P.populate_list(e[1]);break;case"added":P.added_song(e[1]);break;case"deleted":P.deleted_song(e[1]);break;case"vote":P.voted_song(e[1],e[2]);break;case"song_change":P.song_change(e[1])}},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==D&&(D=$("#list-song-html").html()),y=e,P.sortList(),$("#wrapper").empty(),y.length>1?($.each(y,function(e,t){t.now_playing||$("#wrapper").append(P.generateSong(t,!1,oe,!0))}),oe&&(window.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("The playlist is empty.")),$("#settings").css("visibility","visible"),$("#settings").css("opacity","1"),$("#wrapper").css("opacity","1")},added_song:function(e){now_playing=y.pop(),y.push(e),P.sortList(),y.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(),y.splice(P.getIndexOfSong(e),1)},305),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1}catch(n){y.splice(P.getIndexOfSong(e),1),P.empty||$("#wrapper").children()[$("#wrapper").children().length-1].remove()}y.length<=2&&(P.empty=!0,$("#wrapper").append("The playlist is empty.")),$("#suggested-"+e).remove(),ye.checkUserEmpty()},voted_song:function(e,t){var o=P.getIndexOfSong(e),n=y[o];y[o].votes+=1,y[o].added=t,P.sortList(),$("#"+e).remove(),P.insertAtIndex(n,!1)},song_change:function(e){var t=y.length-1;y[0].now_playing=!0,y[0].votes=0,y[0].guids=[],y[0].added=e,y[t].now_playing=!1;try{y.push(y.shift()),P.empty||$("#wrapper").children()[0].remove(),0==$("#wrapper").children().length&&(P.empty=!0,$("#wrapper").append("The playlist is empty.")),P.insertAtIndex(y[t-1],!1),document.getElementById("wrapper").scrollTop+=1,document.getElementById("wrapper").scrollTop+=-1}catch(o){}},vote:function(e,t){return M.emit("vote",[A,e,t,J]),!0},skip:function(){return M.emit("skip",{pass:J,id:T}),!0},importOldList:function(e){var t="",o=0;playlist_url="lists/"+e+".json",S=$.parseJSON($.ajax({type:"GET",url:playlist_url,async:!1}).responseText),$.each(S.songs,function(e,n){t+=n.id+",",o>45&&(fe.addVideos(t),t="",o=0),o++}),fe.addVideos(t),document.getElementById("search").value=""},sortList:function(){y.sort(d.predicate({name:"votes",reverse:!0},"added"))},show:function(){window.mobilecheck()||(V?(V=!1,$("#toptitle").empty(),$("#chan").addClass("bigChan"),$("#chan").html("zoff.no/"+A.toLowerCase())):(V=!0,$("#toptitle").html("Zöff"),$("#chan").removeClass("bigChan"),$("#chan").html(A)))},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');",u=$("
    "+D+"
    "),p="style";return t&&u.find("#list-song").css("height",0),N||u.find(".card-action").removeClass("hide"),1==c&&u.find(".vote-text").text("vote"),o&&(d="//img.youtube.com/vi/"+l+"/mqdefault.jpg",p="data-original"),n?(u.find(".list-votes").text(c),u.find("#list-song").attr("id",l),u.find(".vote-container").attr("title",r),i=".vote-container",s="del"):n||(u.find(".vote-text").text(e.duration),i=".add-suggested",s=a?"del_user_suggested":"del_suggested",u.find(".vote-container").attr("class","clickable add-suggested"),u.find(".add-suggested").attr("title",r),u.find("#del").attr("id",s),u.find(i).attr("data-video-title",r),u.find(i).attr("data-video-length",e.length),u.find("#list-song").attr("id","suggested-"+l),u.find(".list-image").attr("class",u.find(".list-image").attr("class").replace("list-image","list-suggested-image"))),u.find(".list-title").text(r),u.find(".list-title").attr("title",r),u.find(i).attr("data-video-id",l),u.find(".list-image").attr(p,d),u.find(".list-suggested-image").attr(p,d),u.find("#"+s).attr("data-video-id",l),u.html()},getIndexOfSong:function(e){return indexes=$.map(y,function(t,o){return t.id==e?o:void 0}),indexes[0]},scrollTop:function(){$("#wrapper").scrollTop(0)},scrollBottom:function(){$("#wrapper").scrollTop($("#wrapper")[0].scrollHeight)}},A=void 0==window.chan?$("#chan").html():window.chan,N=!0,j=0,V=!0,D=$("#list-song-html").html(),q=!1,O=!1,H="***REMOVED***",R=!1,Y=/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)?)?/,v=[],F=0,U=1,J="",G="",Z=!1,I=1,W=!1,Q=!1,K=6e3,X=Date.now(),ee=!1,te=-1,oe=!0,ne=!1,ae=!0,ie=!1,se=!1,le=!1,re=!1,ce={"sync disconnect on unload":!0,secure:!0,"force new connection":!0};$().ready(function(){window.fromFront||"/"==window.location.pathname||e()}),window.init=e,$(document).keyup(function(e){27==event.keyCode&&($("#results").html(""),d.contains($("#search-wrapper").attr("class").split(" "),"hide")||$("#search-wrapper").toggleClass("hide"),d.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"))}),$("input[class=conf]").change(function(){s.save()}),$("#clickme").click(function(){ge.ytplayer.playVideo()}), +$(document).on("submit","#listImport",function(){fe.importPlaylist(document.getElementById("import").value)}),$(window).focus(function(){$("#favicon").attr("href","static/images/favicon.png"),O=!1}),$(document).on("change","#autoplay",function(){this.checked?$("#embed-area").val(''):$("#embed-area").val('')}),$(document).on("click","#playbutton_remote",function(e){e.preventDefault(),pe.play_remote()}),$(document).on("click","#pausebutton_remote",function(e){e.preventDefault(),pe.pause_remote()}),$(document).on("click","#skipbutton_remote",function(e){e.preventDefault(),pe.skip_remote()}),$(document).on("submit","#remoteform",function(e){e.preventDefault(),pe.get_input($("#remote_channel").val())}),$(document).on("click","#chat-btn",function(){$("#text-chat-input").focus(),$("#chat-btn i").css("opacity",1),clearInterval(w),q=!1,O=!1,$("#favicon").attr("href","static/images/favicon.png")}),/iPad|iPhone|iPod/.test(navigator.userAgent)?$(document).on("keydown",".search_input",function(e){t(e)}):$(document).on("keyup",".search_input",function(e){t(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(),s.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("submit","#chatForm",function(e){e.preventDefault(),l.chat(document.getElementById("chatForm").input)}),$(document).on("click","#shuffle",function(e){e.preventDefault(),s.shuffle()}),$(document).on("click","#search-btn",function(e){e.preventDefault(),fe.showSearch()}),$(document).on("click","#song-title",function(e){e.preventDefault(),fe.showSearch()}),$(document).on("click","#admin-lock",function(e){e.preventDefault(),s.log_out()}),$(document).on("click","#closeSettings",function(e){e.preventDefault(),s.hide_settings()}),$(document).on("click",".result-object",function(e){var t=$(e.target),o=t.prop("outerHTML").substring(0,4);if("=t&&""==J||80>=t&&t>=48&&""!=J)&&$("#wrapper").scrollTop()>0?($("#top-button").removeClass("hide"),d.addClass("#bottom-button","hide")):t>=$("#playlist").height()-18&&$("#wrapper").scrollTop()<$("#wrapper")[0].scrollHeight-$("#wrapper").height()-1?($("#bottom-button").removeClass("hide"),d.addClass("#top-button","hide")):(d.addClass("#bottom-button","hide"),d.addClass("#top-button","hide"))}),$(document).on("mouseleave","#playlist",function(){d.addClass("#bottom-button","hide"),d.addClass("#top-button","hide")}),$(document).on("click","#top-button",function(){P.scrollTop()}),$(document).on("click","#bottom-button",function(){P.scrollBottom()});var de,ue,M,pe={id:"",get_input:function(e){""==pe.id?pe.set_id(e.toLowerCase()):pe.set_channel(e.toLowerCase())},set_id:function(e){pe.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){M.emit("id",[pe.id,"channel",e])},play_remote:function(){M.emit("id",[pe.id,"play","mock"])},pause_remote:function(){M.emit("id",[pe.id,"pause","mock"])},skip_remote:function(){M.emit("id",[pe.id,"skip","mock"])},initiate_volume:function(){$("#volume-control-remote").slider({min:0,max:100,value:100,range:"min",animate:!0,stop:function(e,t){M.emit("id",[pe.id,"volume",t.value]),console.log("volume")}})}},U=!0;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 me={blob_list:[],winter:!1,times_rotated:0,populate_channels:function(e){var t,o="",n=0;1==e[0][5]&&(t=e.shift()),e.sort(me.sortFunction),void 0!==t&&e.unshift(t),pre_card=$(de),window.mobilecheck()||me.add_backdrop(e,0);for(x in e){var a=e[x][3];if(12>n){var i=e[x][1],s=e[x][0],l="background-image:url('https://img.youtube.com/vi/"+i+"/hqdefault.jpg');",r=e[x][4],c=pre_card;1==e[x][5]?(c.find(".pin").attr("style","display:block;"),c.find(".card").attr("title","Pinned!")):(c.find(".pin").attr("style","display:none;"),c.find(".card").attr("title","")),c.find(".chan-name").text(a),c.find(".chan-name").attr("title",a),c.find(".chan-views").text(s),c.find(".chan-songs").text(r),c.find(".chan-bg").attr("style",l),c.find(".chan-link").attr("href",a),$("#channels").append(c.html())}o+="