merge backed and material

This commit is contained in:
Nicolas A. Tonne
2015-04-12 18:37:04 +02:00
1890 changed files with 322399 additions and 631 deletions

View File

@@ -1,6 +1,23 @@
var adminTogg = false;
var pass_corr = "";
socket.on("success_settings", function(msg)
{
pass_corr = "correct";
document.getElementById("sBar").innerHTML = msg;
$("#sBar").addClass("opacityFull");
document.getElementById("passbox").value = "";
remove_bar();
});
socket.on("error_settings", function(msg){
pass_corr = "wrong";
document.getElementById("eBar").innerHTML = "Error: " + msg;
$("#eBar").addClass("opacityFull");
document.getElementById("passbox").value = "";
remove_bar();
});
function admin()
{
adminTogg = !adminTogg;
@@ -37,33 +54,13 @@ function submitAdmin(form)
skipping = form.skip.value;
shuffling = form.shuffle.value;
confRes = $.ajax({
type: "POST",
url: "php/change.php",
async: false,
data: "conf=start&vote="+voting+"&addsongs="+addsongs+"&longsongs="+longsongs+"&frontpage="+frontpage+
"&allvideos="+allvideos+"&removeplay="+removeplay+"&pass="+adminpass+"&skip="+skipping+"&shuffling="+shuffling,
configs = [voting, addsongs, longsongs, frontpage, allvideos, removeplay, adminpass, skipping, shuffling];
success: function() {
console.log("configurations response: "+response);
}
}).responseText;
pass_corr = confRes;
socket.emit("conf", configs);
}
if(pass_corr=="correct"){
//$("#adminPanel").addClass("success");
document.getElementById("sBar").innerHTML = "Successfully applied settings.";
$("#sBar").addClass("opacityFull");
document.getElementById("passbox").value = "";
}else{
document.getElementById("eBar").innerHTML = "Error: Wrong Admin Password!";
$("#eBar").addClass("opacityFull");
document.getElementById("passbox").value = "";/*$("#adminPanel").addClass("fadeerror");*/
}
console.log(pass_corr);
updateList();
function remove_bar()
{
setTimeout(function(){
$("#adminPanel").removeClass("success");
$("#adminPanel").removeClass("fadeerror");
@@ -75,32 +72,5 @@ function submitAdmin(form)
function shuffle(form)
{
console.log(adminpass);
confRes = $.ajax({
type: "GET",
url: "php/change.php",
async: false,
data: "shuffle=true&pass="+adminpass,
success: function() {
console.log("configurations response: "+response);
}
}).responseText;
if(confRes == "shuffled")
{
document.getElementById("sBar").innerHTML = "Successfully shuffled playlist.";
$("#sBar").addClass("opacityFull");
updateList();
}else if(confRes = "wrong!"){
document.getElementById("eBar").innerHTML = "Error: Wrong Admin Password!";
$("#eBar").addClass("opacityFull");
}else if(confRes = "size"){
document.getElementById("eBar").innerHTML = "Error: Empty Playlist!";
$("#eBar").addClass("opacityFull");
}
setTimeout(function(){
$("#adminPanel").removeClass("success");
$("#adminPanel").removeClass("fadeerror");
$("#eBar").removeClass("opacityFull");
$("#sBar").removeClass("opacityFull");
},1500);
socket.emit('shuffle', adminpass);
}

View File

@@ -8,47 +8,70 @@ var chan = $("#chan").html();
var list_html = $("#list-song-html").html();
var hasadmin=0;
function updateList()
socket.on(guid, function(msg){
populate_list(msg);
});
socket.on("abc", function(){
alert("alert");
});
socket.on(chan.toLowerCase(), function(msg){
populate_list(msg);
});
socket.on("skipping", function(obj)
{
console.log("updating list");
list = $.ajax({ type: "GET",
url: "php/change.php",
async: false
}).responseText;
list = $.parseJSON(list);
conf = list.conf;
if(conf.hasOwnProperty("addsongs") && conf.addsongs == "true") adminadd = 1;
else adminadd = 0;
if(conf.hasOwnProperty("allvideos") && conf.allvideos == "true") music = 1;
else music = 0;
if(conf.hasOwnProperty("longsongs") && conf.longsongs == "true") longS = 1;
else longS = 0;
if(conf.hasOwnProperty("vote") && conf.vote == "true") adminvote = 1;
else adminvote = 0;
if(conf.hasOwnProperty("adminpass") && conf.adminpass !== '') hasadmin = 1;
else hasadmin = 0;
/*list[0].shift();
list[3].shift();
list[2].shift();*/
document.getElementById("pBar").innerHTML = "Vote registrated! "+obj[0]+" of "+obj[1]+" has skipped. "+(Math.ceil(obj[1]/2))+" or more is needed!";
$("#pBar").addClass("opacityFull");
setTimeout(function(){
$("#pBar").removeClass("opacityFull");
},1500);
});
setTimeout(function()
function populate_list(msg)
{
console.log(msg);
for(obj in msg)
{
console.log(msg[obj]);
}
$("#wrapper").empty();
$("#wrapper").empty();
$.each(list.songs, function(j, listeID){
var video_title=listeID.title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&");
var video_id = listeID.id;
var video_thumb = "background-image:url('http://img.youtube.com/vi/"+video_id+"/mqdefault.jpg');";
//var delsong = ""; if(pass_corr=="correct");
var video_votes = listeID.votes;
$("#wrapper").append(list_html);
var song = $("#list-song");
song.find(".list-title").text(video_title);
song.find(".list-votes").text(video_votes);
song.find(".votebg").attr("onclick", "vote('"+video_id+"','pos')");
song.find(".list-image").attr("style",video_thumb);
song.attr("id",video_id);
$.each(msg, function(j, listeID){
if(listeID.hasOwnProperty('startTime')) //check if its config part of list
{
console.log("startTime");
console.log(listeID.addsongs);
if(!adminTogg)
{
names=["vote","addsongs","longsongs","frontpage", "allvideos", "removeplay", "skip", "shuffle"];
for (var i = 0; i < names.length; i++) {
document.getElementsByName(names[i])[0].checked = (listeID[names[i]] === 'true');
document.getElementsByName(names[i])[1].checked = (listeID[names[i]] === 'false');
}
if(hasadmin)
$("#setpass").text("Channel has admin");
else
$("#setpass").text("Channel has no admin");
}
}else if(!listeID.now_playing){ //check that the song isnt playing
var video_title=listeID.title.replace(/\\\'/g, "'").replace(/&quot;/g,"'").replace(/&amp;/g,"&");
var video_id = listeID.id;
var video_thumb = "background-image:url('http://img.youtube.com/vi/"+video_id+"/mqdefault.jpg');";
//var delsong = ""; if(pass_corr=="correct");
var video_votes = listeID.votes;
$("#wrapper").append(list_html);
var song = $("#list-song");
song.find(".list-title").text(video_title);
song.find(".list-votes").text(video_votes);
song.find(".votebg").attr("onclick", "vote('"+video_id+"','pos')");
song.find(".list-image").attr("style",video_thumb);
song.attr("id",video_id);
}
});
if($("#playlist").height() != $("#player").height() || (peis && $("#playlist").height() != $("#jplayer").height()))
@@ -84,89 +107,19 @@ function updateList()
}else{
myScroll.refresh();
}
if(!adminTogg)
{
names=["vote","addsongs","longsongs","frontpage", "allvideos", "removeplay", "skip", "shuffle"];
for (var i = 0; i < names.length; i++) {
document.getElementsByName(names[i])[0].checked = (conf[names[i]] === "true");
document.getElementsByName(names[i])[1].checked = (conf[names[i]] === "false");
}
if(hasadmin)
$("#setpass").text("Channel has admin");
else
$("#setpass").text("Channel has no admin");
}
}, 2500);
$("#settings").css("visibility", "visible");
$("#settings").css("opacity", "0.7");
$("#wrapper").css("opacity", "1");
}
function vote(id, vote){
serverAns = ($.ajax({
type: "GET",
url: "php/change.php",
async: false,
data: "vote="+vote+"&id="+id+"&pass="+adminpass,
success: function() {
console.log("voted "+vote+" on "+id);
/*if(vote=="pos"){ $("#playlist").addClass("success");}
else{ $("#playlist").addClass("fadeerror");}
updateList();*/
},
}).responseText);
if(serverAns == "wrong")
{
//alert("Wrong adminpassword!");
$("#eBar").addClass("opacityFull");
}else{
if(vote=="pos" && serverAns != "many"){ $("."+id).addClass("success");}
else{ $("."+id).addClass("fadeerror");}
updateList();
}
setTimeout(function(){
$("."+id).removeClass("success");
$("."+id).removeClass("fadeerror");
$("#eBar").removeClass("opacityFull");
},1500);
socket.emit('vote', [chan, id, vote, guid, adminpass]);
}
function skip(){
voteRes = ($.ajax({
type: "GET",
url: "php/change.php",
async: false,
data: "skip",
success: function() {
console.log("voted to skip song");
//$("#search").addClass("success");
updateList();
},
}).responseText);
if(voteRes == "wrong!")
{
document.getElementById("eBar").innerHTML = "Error: Skipping disabled.";
$("#eBar").addClass("opacityFull");
}else{
skipVotes = voteRes.split("/");
if(skipVotes[0]>= skipVotes[1]/2)
{
document.getElementById("sBar").innerHTML = "Successfully skipped!";
$("#sBar").addClass("opacityFull");
}else
{
document.getElementById("pBar").innerHTML = "Vote registrated! "+skipVotes[0]+" of "+skipVotes[1]+" has skipped. "+(Math.ceil(skipVotes[1]/2))+" or more is needed!";
$("#pBar").addClass("opacityFull");
}
}
setTimeout(function(){
$("#search").removeClass("success");
$("#sBar").removeClass("opacityFull");
$("#pBar").removeClass("opacityFull");
$("#eBar").removeClass("opacityFull");
},1500);
socket.emit('skip', [chan, guid]);
}
function show(){
@@ -187,24 +140,3 @@ function show(){
fitToScreen();
}
}
function ks()
{
list = $.ajax({ type: "GET",
url: "php/change.php",
async: false
}).responseText;
list = $.parseJSON(list);
myScroll.destroy();
myScroll = null;
$("#playlist").css({height: $("#player").height()});
$("#playlist").css({overflow: "hidden"});
myScroll = new IScroll('#playlist', {
mouseWheel: true,
scrollbars: false,
scrollY: true,
interactiveScrollbars: false
});
scroller = true;
}

View File

@@ -1,3 +1,5 @@
var list_html;
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
@@ -9,7 +11,61 @@ function getCookie(cname) {
return "";
}
function populate_channels(lists)
{
var output = "";
lists.sort(sortFunction);
for(x in lists)
{
var id = lists[x][1];
var nowplaying = lists[x][2];
var chan = lists[x][3];
var viewers = lists[x][0];
var img = "background-image:url('http://img.youtube.com/vi/"+id+"/hqdefault.jpg');";
$("#channel").append(list_html);
var card = $("#chan-card");
card.find(".chan-name").text(chan);
card.find(".chan-views").text(viewers);
card.find(".chan-songs").text("666");
card.find(".chan-bg").attr("style", img);
card.find(".chan-link").attr("href", chan);
output+="<option value='"+chan+"'> ";
}
document.getElementById("searches").innerHTML = output;
}
String.prototype.capitalizeFirstLetter = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function sortFunction(a, b) {
if (a[0] === b[0]) {
return 0;
}
else {
return (a[0] < b[0]) ? 1 : -1;
}
}
$(document).ready(function (){
list_html = $("#chan-html").html();
$("#channels").empty();
var socket = io.connect('http://localhost:3000');
var playlists = [];
socket.emit('frontpage_lists');
socket.on('playlists', function(msg){
populate_channels(msg);
})
Materialize.showStaggeredList('#channels');
var pad = 0;
document.getElementById("zicon").addEventListener("click", function(){

View File

@@ -101,6 +101,7 @@ function initSlider()
setVolume(ui.value);
}
});
ytplayer.mute();
$("#volume").slider("value", ytplayer.getVolume());
}

View File

@@ -5,29 +5,28 @@ var timer = 0;
$(document).ready(function()
{
$( "#results" ).hover( function() { $("div.result").removeClass("hoverResults"); i = 0; }, function() { });
$("#search").focus();
$('#base').bind("keyup keypress", function(e) {
var code = e.keyCode || e.which;
if (code == 13) {
var code = e.keyCode || e.which;
if (code == 13) {
e.preventDefault();
return false;
}
});
$(".search_input").focus();
$(".search_input").keyup(function(event) {
var search_input = $(this).val();
console.log(event.keyCode);
if(event.keyCode == 13 && search_input == "fireplace")
{
if(!peis)
{
peis = true;
loadjsfile("js/jazzscript.js");
}else
{
peis = false;
@@ -74,7 +73,7 @@ $(document).ready(function()
}
}
});
setInterval(function(){
@@ -85,7 +84,7 @@ $(document).ready(function()
}, 1);
});
$(document).keyup(function(e) {
$(document).keyup(function(e) {
if ($("div.result").length > 2){
if (e.keyCode == 40) {
if(i < $("div.result").length -2)
@@ -115,13 +114,13 @@ $(document).keyup(function(e) {
function search(search_input){
$("#results").html('');
if(search_input !== ""){
var keyword= encodeURIComponent(search_input);
var yt_url='http://gdata.youtube.com/feeds/api/videos?q='+keyword+'&format=5&orderby=relevance&max-results=6&v=2&alt=jsonc';
var yt_url='http://gdata.youtube.com/feeds/api/videos?q='+keyword+'&format=5&orderby=relevance&max-results=6&v=2&alt=jsonc';
$.ajax({
type: "GET",
@@ -163,7 +162,7 @@ function search(search_input){
}
$("<div id='r' style='display:none;'>"+wrapper+"</div>").appendTo('#results').slideDown('slow');
}
else{ $("#video").html("<div id='no'>No Video</div>");}
}
@@ -186,58 +185,12 @@ function submitAndClose(id,title){
function submit(id,title,type){
serverAns = $.ajax({
type: "GET",
url: "php/change.php",
async: false,
data: "v="+id+"&n="+title+"&pass="+adminpass,
success: function() {
if(type){
document.getElementById("search").value = "";
$("#results").html = "";
$(".main").removeClass("blurT");
$("#controls").removeClass("blurT");
$(".main").removeClass("clickthrough");
}
//$("#search").addClass("success");
},
error: function(){
console.log("error in adding");
if(type)
{
document.getElementById("search").value = "";
$("#results").html = "";
$(".main").removeClass("blurT");
$("#controls").removeClass("blurT");
$(".main").removeClass("clickthrough");
$("#search").addClass("error");
}
}
}).responseText;
if(serverAns == "wrong")
{
//alert("Wrong adminpassword");
$("#search").addClass("error");
document.getElementById("eBar").innerHTML = "Error: Wrong Admin Password!";
$("#eBar").addClass("opacityFull");
}else{
//$("#search").addClass("success");
document.getElementById("sBar").innerHTML = "Successfully added song!";
$("#sBar").addClass("opacityFull");
socket.emit("add", [id, decodeURI(title), adminpass]);
if(type){
document.getElementById("search").value = "";
$("#results").html = "";
$(".main").removeClass("blurT");
$("#controls").removeClass("blurT");
$(".main").removeClass("clickthrough");
}
$("#search").focus();
setTimeout(function(){
$("#search").removeClass("success");
$("#search").removeClass("error");
$("#eBar").removeClass("opacityFull");
$("#sBar").removeClass("opacityFull");
},1500);
updateList();
event.stopPropagation();
}
// if(reply=="added"){$("#search").removeClass('success'); $("#search").addClass('success');}

View File

@@ -34,6 +34,38 @@ var notified = false;
var peis = false;
var filesadded="";
var colorThief;
var chan = $("#chan").html();
var player_ready = false;
var seekTo;
var arr = []
var song_title;
var viewers = 1;
var paused = false;
var playing = false;
socket.on(chan.toLowerCase()+",np", function(obj)
{
video_id = obj[0][0]["id"];
conf = obj[1][0];
time = obj[2];
seekTo = time - conf["startTime"];
song_title = obj[0][0]["title"];
getTitle(song_title, viewers);
if(player_ready)
{
if(ytplayer.getVideoUrl().split('v=')[1] != video_id)
ytplayer.loadVideoById(video_id);
ytplayer.playVideo();
ytplayer.seekTo(seekTo);
}
});
socket.on(chan.toLowerCase()+",viewers", function(view)
{
viewers = view;
if(song_title !== undefined)
getTitle(song_title, viewers);
});
$(document).ready(function()
{
@@ -42,7 +74,6 @@ $(document).ready(function()
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);
//(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|phone)|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; };
if(!window.mobilecheck())
@@ -50,33 +81,7 @@ $(document).ready(function()
Notification.requestPermission();
}
updateList();
wasPaused = false;
beginning = true;
diffVideo = false;
interval = false;
response = $.ajax({ type: "GET",
url: "php/change.php",
async: false
}).responseText;
//console.log(response);
response = $.parseJSON(response);
console.log(response.nowPlaying.length);
conf = response.conf;
console.log(conf);
try{
for(var first in response.nowPlaying) break;
console.log(first);
response = first;
}catch(err){
response = "1";
}
if(window.mobilecheck()){
//syncInterval = setInterval(getTime, 50000);
//listInterval = setInterval(updateList, 50000);
mobileSync = setInterval(function(){getTime();updateList();}, 10000);
//listKillInterval = setInterval(ks, 50000);
document.getElementById("search").blur();
readyLooks();
}else{
@@ -84,10 +89,6 @@ $(document).ready(function()
tag.src = "https://www.youtube.com/iframe_api";
firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
if(!syncInterval)
syncInterval = setInterval(getTime, 5000);
listInterval = setInterval(updateList, 10000);
//listKillInterval = setInterval(ks, 50000);
if($("#chan").html().toLowerCase() == "jazz")
{
@@ -114,7 +115,7 @@ function onYouTubeIframeAPIReady() {
ytplayer = new YT.Player('player', {
height: window.height*0.75,
width: window.width*0.6,
videoId: response,
videoId: video_id,
playerVars: { rel:"0", wmode:"transparent", controls: "0" , iv_load_policy: "3", theme:"light", color:"white"},
events: {
'onReady': onPlayerReady,
@@ -131,276 +132,78 @@ function onYouTubeIframeAPIReady() {
}
function onPlayerStateChange(newState) {
console.log("new state: "+newState.data);
console.log("beginning: "+beginning);
//ytplayer.seekTo(15);
if((newState.data === 0 && checkEnd()) || (newState.data == 1 && checkEnd()))
switch(newState.data)
{
console.log("nummer 1");
startNextSong();
ytplayer.pauseVideo();
wasPaused = false;
}else if(newState.data == 1 && (wasPaused && !beginning))
{
console.log("unpaused");
beginning = false;
wasPaused = false;
if(!syncInterval)
syncInterval = setInterval(getTime, 5000);
getTime();
}else if(newState.data == 2)
{
//clearInterval(syncInterval);
interval = true;
wasPaused = true;
beginning = false;
}
if(newState.data == 1 || newState.data == 2)
{
activeButton = document.getElementById("playpause").className;
console.log(activeButton);
if((newState.data == 2 && activeButton == "pause") || (newState.data == 1 && activeButton == "play"))
{
$("#playpause").toggleClass("play");
$("#playpause").toggleClass("pause");
}
}
if(newState.data === 0)
{
quickFixCountdown = setTimeout(function(){
console.log("trying quickfix");
if(ytplayer.getPlayerState() === 0){
console.log("quickfixPlay");
startNextSong();
wasPaused = false;
case -1:
break;
case 0:
socket.emit("end", video_id);
playing = false;
break;
case 1:
playing = true;
if(document.getElementById("playpause").className == "play")
{
$("#playpause").toggleClass("play");
$("#playpause").toggleClass("pause");
}
},5000);
if(paused)
{
socket.emit('pos');
paused = false;
}
break;
case 2:
paused = true;
if(document.getElementById("playpause").className == "pause")
{
$("#playpause").toggleClass("play");
$("#playpause").toggleClass("pause");
}
break;
case 3:
break;
}
}
function checkEnd()
function getTitle(titt, v)
{
console.log("sjekker om brukeren spolte");
$.ajax({
type: 'get',
url: 'php/timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
if(parseInt(timeDifference[0]) > ytplayer.getDuration())
var outPutWord = v > 1 ? "viewers" : "viewer";
var title= titt.replace(/\\\'/g, "'").replace(/&quot;/g,"'").replace(/&amp;/g,"&");
document.title = title + " • Zöff";
if(!window.mobilecheck()){
document.getElementsByName('v')[0].placeholder = title + " • " + v + " " + outPutWord;
}else
{
return true;
document.getElementById("mobileTitle").innerHTML = title;
document.getElementsByName('v')[0].placeholder = "Search • 1 " + v + " " + outPutWord;
//document.getElementById("viewers").innerHTML = viewers[5].length + " " + outPutWord;
}
return false;
}
function startNextSong()
{
//console.log(getTime());
if(checkEnd() && !changed)
{
setTimeout(function(){
arr = $.ajax({
type: "POST",
url: "php/change.php",
async: false,
data: "thisUrl="+response+"&act=save",
success: function() {
console.log("saved song-switch - "+response);
}
}).responseText;
arr = $.parseJSON(arr);
response = arr.id;
console.log("next video: "+response);
getTitle(response);
if(!window.mobilecheck())
{
ytplayer.loadVideoById(response);
notifyUser(response, arr.title);
}
beginning = true;
setBGimage(response);
},2500);
updateList();
changed = true;
setTimeout(function() {
changed = false;
if(!syncInterval)
syncInterval = setInterval(getTime, 5000);
interval = true;
console.log("starter intervallen. Interval: " + interval);
}, 2500);
}
}
function getTime()
{
console.log("utenfor if test" + wasPaused);
if(!window.mobilecheck() && ytplayer.getCurrentTime() > 2 && ytplayer.getPlayerState() == 1) wasPaused = false;
if(!wasPaused)
{
console.log("sjekker om brukeren spolte");
$.ajax({
type: 'get',
url: 'php/timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
console.log("current song: "+response);
console.log("song in database: "+timeDifference[1]);
if(!window.mobilecheck()){ //Added so the mobileversion will change banner
if(parseInt(timeDifference[2]) + 1> ytplayer.getCurrentTime() + parseInt(timeDifference[3]) && ytplayer.getPlayerState() === 0)
{
return true;
}else if(ytplayer.getCurrentTime() + parseInt(timeDifference[3]) > parseInt(timeDifference[2]) + 5 || (ytplayer.getCurrentTime() + parseInt(timeDifference[3]) < parseInt(timeDifference[2]) - 5 && ytplayer.getPlayerState() !== 0 && ytplayer.getPlayerState() != 3))
{
if(parseInt(timeDifference[0]) > ytplayer.getDuration())
{
console.log("burde ikke søke, men hoppe til neste sang");
}
ytplayer.seekTo(timeDifference[0]);
ytplayer.pauseVideo();
ytplayer.playVideo();
getTitle();
return false;
}
}
//if(interval){syncInterval = setInterval(getTime, 5000);interval = false;}
if(response != timeDifference[1])
{
//clearInterval(syncInterval);
wasPaused = true;
console.log("forskjellige videoer!!");
if(!window.mobilecheck())
{
ytplayer.pauseVideo();
ytplayer.loadVideoById(timeDifference[1]);
notifyUser(timeDifference[1], timeDifference[4]);
wasPaused = false;
if(!syncInterval)
syncInterval = setInterval(getTime, 5000);
}
response = timeDifference[1];
getTitle();
setBGimage(timeDifference[1]);
updateList();
/*setTimeout(function(){
//console.log(response);
diffVideo = true;
beginning = true;
$.ajax({
type: "POST",
url: "php/change.php",
async: false,
data: "thisUrl=123abcprompeprompe&act=save",
success: function(data)
{
response = timeDifference[1];
getTitle();
}
});
wasPaused = false;
if(!syncInterval)
syncInterval = setInterval(getTime, 5000);
},2500);*/
}
}
}
function getTitle()
{
$.ajax({ type: "GET",
url: "php/timedifference.php",
async: false,
success: function(data) {
viewers = $.parseJSON(data);
var outPutWord = viewers[5].length > 1 ? "viewers" : "viewer";
var title= viewers[4].replace(/\\\'/g, "'").replace(/&quot;/g,"'").replace(/&amp;/g,"&");
document.title = title + " • Zöff";
if(!window.mobilecheck())
document.getElementsByName('v')[0].placeholder = title + " • " + viewers[5].length + " " + outPutWord;
else
{
document.getElementById("mobileTitle").innerHTML = title;
document.getElementsByName('v')[0].placeholder = "Search • " + viewers[5].length + " " + outPutWord;
//document.getElementById("viewers").innerHTML = viewers[5].length + " " + outPutWord;
}
}
});
}
function errorHandler(newState)
{
setTimeout(function(){
arr = $.ajax({
type: "POST",
url: "php/change.php",
async: false,
data: "thisUrl="+response+"&act=empty",
success: function() {
console.log("error! deleted video");
}
}).responseText;
arr = $.parseJSON(arr);
response = arr.id;
if(!window.mobilecheck())
{
ytplayer.loadVideoById(response);
notifyUser(response);
}
setBGimage(response);
},2500);
/*
setTimeout(function(){
response = $.ajax({ type: "GET",
url: "change.php",
async: false
}).responseText;
var url = $.parseJSON(response);
response = url[0][0];
ytplayer.loadVideoById(response);
},2500);*/
socket.emit("end", video_id);
}
function onPlayerReady(event) {
//ytplayer = document.getElementById("myytplayer");
// ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
//ytplayer.addEventListener("onError", "errorHandler");
getTime();
player_ready = true;
if(!window.mobilecheck())
{
$("#player").css("opacity", "1");
$("#controls").css("opacity", "1");
$(".playlist").css("opacity", "1");
//$("#player").fadeIn();
ytplayer.loadVideoById(video_id);
ytplayer.playVideo();
initYoutubeControls(ytplayer);
ytplayer.seekTo(seekTo);
}
readyLooks();
initSlider();
//durationFixer = setInterval(durationSetter, 1000);
}
function readyLooks()
{
getTitle();
setBGimage(response);
setBGimage(video_id);
}
function setBGimage(id){