var channel_list; var frontpage = true; var socket; var rotation_timeout; var Frontpage = { blob_list: [], winter: (new Date()).getMonth() >= 10 ? true : false, times_rotated: 0, all_channels: [], frontpage_function: function() { frontpage = true; Helper.log([ "Frontpage fetch", msg ]); Frontpage.all_channels = window.lists; var msg = window.lists; delete window.lists; window.lists = undefined; //document.querySelector("#lists-script").remove(); if(msg.length == 0) { //Helper.css("#preloader", "display", "none"); document.getElementById("channel-list-container").insertAdjacentHTML("beforeend", "
No channels yet
"); } else { Frontpage.populate_channels(msg, true, false); } //Frontpage.set_viewers(msg.viewers); }, populate_channels: function(lists, popular, set) { //document.getElementById("channels").innerHTML = ""; var num = 0; if(!set) Frontpage.add_backdrop(lists, 0); else if(set) { document.getElementById("channels").innerHTML = ""; if(popular) { lists = lists.sort(Helper.predicate({ name: 'pinned', reverse: true }, { name: 'viewers', reverse: true }, { name: 'accessed', reverse: true }, { name: 'count', reverse: true })); } else { lists = lists.sort(Helper.predicate({ name: 'viewers', reverse: true }, { name: 'count', reverse: true })); } if(!Helper.mobilecheck()) { clearTimeout(rotation_timeout); Frontpage.add_backdrop(lists, 0); } pre_card = channel_list; Helper.log([ "Pre_card: ", pre_card ]); for(var x in lists) { var chan = Helper.decodeChannelName(lists[x]._id); if(num<12 || !popular) { var id = lists[x].id; var viewers = lists[x].viewers; var description = lists[x].description; var img; img = "background-image:url('https://img.youtube.com/vi/"+id+"/hqdefault.jpg');"; if(lists[x].thumbnail && lists[x].thumbnail != "") { img = "background-image:url('" + lists[x].thumbnail + "');"; } var song_count = lists[x].count; var card = document.createElement("div"); card.innerHTML += pre_card; //card.innerHTML = card.children[0]; if(song_count > 3) { if(lists[x].pinned == 1) { card.querySelector(".pin").setAttribute("style", "display:block;"); //card.find(".card").attr("title", "Featured list"); } else { /*card.find(".pin").attr("style", "display:none;"); card.find(".card").attr("title", ""); card.querySelector(".pin").remove();*/ } card.querySelector(".chan-name").innerText = chan; card.querySelector(".chan-name").setAttribute("title", chan); card.querySelector(".chan-views").innerText = viewers; card.querySelector(".chan-songs").innerText = song_count; card.querySelector(".chan-bg").setAttribute("style", img); card.querySelector(".chan-link").setAttribute("href", chan + "/"); if(description != "" && description != undefined && !Helper.mobilecheck() && description != "This list has no description") { card.querySelector(".card-title").innerText = chan; card.querySelector(".description_text").innerText = description; description = ""; } else { card.querySelector(".card-reveal").remove(); Helper.removeClass(card.querySelector(".card"), "sticky-action") } document.getElementById("channels").insertAdjacentHTML("beforeend", card.children[0].innerHTML); } else { num--; } } num++; } } var options_list = lists.slice(); options_list = options_list.sort(Frontpage.sortFunction_active); var data = {}; for(var x in options_list) { data[Helper.decodeChannelName(options_list[x]._id)] = null; } if(document.querySelectorAll(".pin").length == 1 && !Helper.mobilecheck()) { Helper.tooltip(document.querySelectorAll(".pin")[0].parentElement.parentElement.parentElement, { delay: 5, position: "top", html: "Featured playlist" }); } var to_autocomplete = document.querySelectorAll("input.autocomplete")[0]; //if(Helper.mobilecheck()) to_autocomplete = "input.mobile-search"; M.Autocomplete.init(to_autocomplete, { data: data, limit: 5, // The max amount of results that can be shown at once. Default: Infinity. onAutocomplete: function(val) { Frontpage.to_channel(val, false); }, }); //document.getElementById("preloader").style.display = "none"; document.getElementById("channels").style.display = "block"; //Materialize.fadeInImage('#channels'); //$("#channels").fadeIn(800); //document.getElementById("autocomplete-input").focus(); num = 0; }, sortFunction: function(a, b) { var o1 = a.viewers; var o2 = b.viewers; var p1 = a.count; var p2 = b.count; if (o1 < o2) return 1; if (o1 > o2) return -1; if (p1 < p2) return 1; if (p1 > p2) return -1; return 0; }, sortFunction_active: function(a, b){ var o1 = a.accessed; var o2 = b.accessed; var p1 = a.count; var p2 = b.count; 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; iWe suck at pranks..Agreed
', 100000); } if(window.location.hostname != "localhost") { ga('send', 'pageview'); } window.onpopstate = function(e){ var url_split = window.location.href.split("/"); if(url_split[3] !== "" && url_split[3].substring(0,1) != "#"){ Frontpage.to_channel(url_split[3], true); } }; if(window.location.hostname == "fb.zoff.me") { Helper.addClass("footer", "hide"); } channel_list = document.querySelector(".hidden-channel-list").cloneNode(true).innerHTML; try { document.querySelector(".hidden-channel-list").remove(); }catch(e){} Frontpage.share_link_modifier(); if(window.location.hostname == "zoff.me" || window.location.hostname == "fb.zoff.me") add = "https://zoff.me"; else add = window.location.hostname; if(socket === undefined) { no_socket = false; socket = io.connect(''+add+':8080', connection_options); socket.on('update_required', function(msg) { if(window.location.hostname == "localhost") { console.log(msg); return; } window.location.reload(true); }); } if(document.querySelectorAll("#alreadyfp").length === 0 || Helper.mobilecheck() || !socket._callbacks.$playlists || user_auth_avoid){ setup_playlist_listener(); } /*M.Modal.init(document.getElementById("about")); M.Modal.init(document.getElementById("help")); M.Modal.init(document.getElementById("contact"));*/ var elem = document.querySelector('select'); document.querySelector(".no-jump-select").remove(); M.FormSelect.init(elem); Helper.log([ "Sending frontpage_lists", "Socket" ]); Crypt.init(); if(Crypt.get_offline()){ change_offline(true, offline); } else { if(!Helper.mobilecheck()) { Helper.tooltip("#offline-mode", { delay: 5, position: "bottom", html: "Enable local mode" }); } } if(!Helper.mobilecheck()) { Helper.tooltip("#frontpage-viewer-counter", { delay: 5, position: "bottom", html: "Total Viewers" }); Helper.tooltip("#client-mode-button", { delay: 5, position: "bottom", html: "Client mode" }); Helper.tooltip(".generate-channel-name", { delay: 5, position: "bottom", html: "Generate name" }); } Frontpage.get_frontpage_lists(); Helper.css("#channel-load", "display", "none"); //Materialize.toast("Try out our new feature, remote!", 8000) if(window.location.hash == "#donation") { window.location.hash = "#"; M.Modal.init(document.getElementById("donation"));; M.Modal.getInstance(document.getElementById("donation")).open(); } //var pad = 0; /*$(".zicon").on("click", function(e) { e.preventDefault(); pad += 10; Helper.css(".zicon", "padding-left", pad + "vh"); if(pad >= 80) window.location.href = 'http://etys.no'; });*/ if(!Helper.mobilecheck() && Frontpage.winter) { document.getElementsByClassName("mega")[0].insertAdjacentHTML("afterbegin", ''); } if(Helper.mobilecheck()){ //$('input#autocomplete-input').characterCounter(); } window['__onGCastApiAvailable'] = function(loaded, errorInfo) { if (loaded) { chromecastReady = true; } else { } } }, share_link_modifier: function() { document.getElementById("facebook-code-link").setAttribute("href", "https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/"); document.getElementById("facebook-code-link").setAttribute("onclick", "window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/', 'Share Zoff','width=600,height=300'); return false;"); document.getElementById("twitter-code-link").setAttribute("href", "https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic"); document.getElementById("twitter-code-link").setAttribute("onclick", "window.open('https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic','Share Playlist','width=600,height=300'); return false;"); //$("#qr-code-link").attr("href", "//chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https://zoff.me/&choe=UTF-8&chld=L%7C1"); //$("#qr-code-image-link").attr("src", "//chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https://zoff.me/&choe=UTF-8&chld=L%7C1"); } }; String.prototype.capitalizeFirstLetter = function() { return this.charAt(0).toUpperCase() + this.slice(1); };