//script for frontpage 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(msg) { frontpage = true; Helper.log([ "Frontpage fetch", msg ]); Frontpage.all_channels = msg.channels; if(msg.channels.length == 0) { $("#preloader").css("display", "none"); $("#channel-list-container").append("
No channels yet
"); } else { Frontpage.populate_channels(msg.channels, true); } Frontpage.set_viewers(msg.viewers); }, populate_channels: function(lists, popular) { $("#channels").empty(); var num = 0; 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 = lists[x]._id; if(num<12 || !popular) { var id = lists[x].id; var viewers = lists[x].viewers; var description = lists[x].description; var img = "background-image:url('https://img.youtube.com/vi/"+id+"/hqdefault.jpg');"; if(lists[x].thumbnail) { img = "background-image:url('" + lists[x].thumbnail + "');"; } var song_count = lists[x].count; var card = pre_card.clone(); if(song_count > 4) { if(lists[x].pinned == 1) { card.find(".pin").attr("style", "display:block;"); card.find(".card").attr("title", "Pinned!"); } else { card.find(".pin").attr("style", "display:none;"); card.find(".card").attr("title", ""); } card.find(".chan-name").text(chan); card.find(".chan-name").attr("title", chan); card.find(".chan-views").text(viewers); card.find(".chan-songs").text(song_count); card.find(".chan-bg").attr("style", img); card.find(".chan-link").attr("href", chan + "/"); if(description != "" && description != undefined && !Helper.mobilecheck()) { card.find(".card-title").text(chan); card.find(".description_text").text(description); description = ""; } else { card.find(".card-reveal").remove(); card.find(".card").removeClass("sticky-action") } $("#channels").append(card.html()); } 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[options_list[x]._id] = null; } var to_autocomplete = "input.autocomplete"; //if(Helper.mobilecheck()) to_autocomplete = "input.mobile-search"; $(to_autocomplete).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"; //Materialize.fadeInImage('#channels'); $("#channels").fadeIn(800); $("#searchFrontpage").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") { $("footer").addClass("hide"); } channel_list = $("#channel-list-container").clone().html(); if(window.location.hostname != "fb.zoff.me") 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 || Helper.mobilecheck() || user_auth_avoid) { socket = io.connect(''+add+':8080', connection_options); socket.on('update_required', function() { window.location.reload(true); }); } if($("#alreadyfp").length === 0 || Helper.mobilecheck() || !socket._callbacks.$playlists || user_auth_avoid){ setup_playlist_listener(); } $("#about").modal(); $("#help").modal(); $("#contact").modal(); $('select').material_select(); Helper.log([ "Sending frontpage_lists", "Socket" ]); Crypt.init(); if(Crypt.get_offline()){ change_offline(true, offline); } else { if(!Helper.mobilecheck()) { $("#offline-mode").tooltip({ delay: 5, position: "bottom", tooltip: "Enable local mode" }); } } if(!Helper.mobilecheck()) { $("#frontpage-viewer-counter").tooltip({ delay: 5, position: "bottom", tooltip: "Total Viewers" }); $(".generate-channel-name").tooltip({ delay: 5, position: "bottom", tooltip: "Generate name" }); } Frontpage.get_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').modal(); $('#donation').modal('open'); } if(!localStorage.ok_cookie){ before_toast(); Materialize.toast("We're using cookies to enhance your experience! ok", 10000); } var pad = 0; $(".zicon").on("click", function(e) { e.preventDefault(); pad += 10; $(".zicon").css("padding-left", pad + "vh"); if(pad >= 80) window.location.href = 'http://etys.no'; }); if(!Helper.mobilecheck() && Frontpage.winter) { $(".mega").prepend(''); } if(Helper.mobilecheck()){ $('input#autocomplete-input').characterCounter(); } window['__onGCastApiAvailable'] = function(loaded, errorInfo) { if (loaded) { chromecastReady = true; } else { } } }, share_link_modifier: function() { $("#facebook-code-link").attr("href", "https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/"); $("#facebook-code-link").attr("onclick", "window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/', 'Share Zoff','width=600,height=300'); return false;"); $("#twitter-code-link").attr("href", "https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic"); $("#twitter-code-link").attr("onclick", "window.open('https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic','Share Playlist','width=600,height=300'); return false;"); //$("#qr-code-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); };