mirror of
https://github.com/KevinMidboe/zoff.git
synced 2026-04-25 16:34:09 +00:00
Started on node.js+socket.io+mongoDB on the backend for more responsivnes
This commit is contained in:
0
js/jazzscript.js
Normal file → Executable file
0
js/jazzscript.js
Normal file → Executable file
111
js/list.js
111
js/list.js
@@ -7,53 +7,64 @@ var showToggle =true;
|
||||
var chan = $("#chan").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);
|
||||
});
|
||||
|
||||
function populate_list(msg)
|
||||
{
|
||||
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();*/
|
||||
|
||||
setTimeout(function()
|
||||
console.log(msg);
|
||||
for(obj in msg)
|
||||
{
|
||||
console.log(msg[obj]);
|
||||
}
|
||||
/*list = msg[0];
|
||||
conf = list.conf;*/
|
||||
|
||||
$("#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;
|
||||
if(find && $.inArray(video_id, bright) == -1) brightness = "brightness";
|
||||
else if(find && $.inArray(video_id, bright) != -1) brightness = "brightness fullbrightness";
|
||||
else brightness = "";
|
||||
var video_thumb = "http://i.ytimg.com/vi/"+video_id+"/mqdefault.jpg";
|
||||
var odd = ""; if(j%2===0)odd=" oddlist";
|
||||
var delsong = ""; if(pass_corr=="correct")delsong="<input id='del' title='Remove' type='button' class='button' value='X' onclick=\"vote('"+video_id+"','del')\">";
|
||||
var finalhtml="<div id='result' class='"+video_id+" result "+brightness+" lresult"+odd+"'>"+
|
||||
"<img class='thumb lthumb' src='"+video_thumb+"'>"+
|
||||
"<div class='ltitle'>"+video_title+"</div>"+
|
||||
"<div class='votes'>"+listeID.votes+
|
||||
"<a onclick=\"vote('"+video_id+"','pos');\" id='plus'>+</a>"+
|
||||
"<a onclick=\"vote('"+video_id+"','neg');\" id='minus'>-</a>"+
|
||||
delsong+
|
||||
"</div>"+
|
||||
"</div>";
|
||||
$("#wrapper").append(finalhtml);
|
||||
$.each(msg, function(j, listeID){
|
||||
if(listeID.hasOwnProperty('startTime'))
|
||||
{
|
||||
console.log("startTime");
|
||||
if(listeID.hasOwnProperty("addsongs") && listeID.addsongs == "true") adminadd = 1;
|
||||
else adminadd = 0;
|
||||
if(listeID.hasOwnProperty("allvideos") && listeID.allvideos == "true") music = 1;
|
||||
else music = 0;
|
||||
if(listeID.hasOwnProperty("longsongs") && listeID.longsongs == "true") longS = 1;
|
||||
else longS = 0;
|
||||
if(listeID.hasOwnProperty("vote") && listeID.vote == "true") adminvote = 1;
|
||||
else adminvote = 0;
|
||||
if(listeID.hasOwnProperty("adminpass") && listeID.adminpass !== '') hasadmin = 1;
|
||||
else hasadmin = 0;
|
||||
}else if(!listeID.now_playing){
|
||||
var video_title=listeID.title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&");
|
||||
var video_id = listeID.id;
|
||||
if(find && $.inArray(video_id, bright) == -1) brightness = "brightness";
|
||||
else if(find && $.inArray(video_id, bright) != -1) brightness = "brightness fullbrightness";
|
||||
else brightness = "";
|
||||
var video_thumb = "http://i.ytimg.com/vi/"+video_id+"/mqdefault.jpg";
|
||||
var odd = ""; if(j%2===0)odd=" oddlist";
|
||||
var delsong = ""; if(pass_corr=="correct")delsong="<input id='del' title='Remove' type='button' class='button' value='X' onclick=\"vote('"+video_id+"','del')\">";
|
||||
var finalhtml="<div id='result' class='"+video_id+" result "+brightness+" lresult"+odd+"'>"+
|
||||
"<img class='thumb lthumb' src='"+video_thumb+"'>"+
|
||||
"<div class='ltitle'>"+video_title+"</div>"+
|
||||
"<div class='votes'>"+listeID.votes+
|
||||
"<a onclick=\"vote('"+video_id+"','pos');\" id='plus'>+</a>"+
|
||||
"<a onclick=\"vote('"+video_id+"','neg');\" id='minus'>-</a>"+
|
||||
delsong+
|
||||
"</div>"+
|
||||
"</div>";
|
||||
$("#wrapper").append(finalhtml);
|
||||
}
|
||||
});
|
||||
if($("#playlist").height() != $("#player").height() || (peis && $("#playlist").height() != $("#jplayer").height()))
|
||||
{
|
||||
@@ -104,17 +115,23 @@ function updateList()
|
||||
$("#settings").css("visibility", "visible");
|
||||
$("#settings").css("opacity", "0.7");
|
||||
$("#wrapper").css("opacity", "1");
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
function updateList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function vote(id, vote){
|
||||
socket.emit('vote', [chan, id, vote, guid]);
|
||||
|
||||
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);
|
||||
//console.log("voted "+vote+" on "+id);
|
||||
/*if(vote=="pos"){ $("#playlist").addClass("success");}
|
||||
else{ $("#playlist").addClass("fadeerror");}
|
||||
updateList();*/
|
||||
@@ -139,13 +156,15 @@ function vote(id, vote){
|
||||
}
|
||||
|
||||
function skip(){
|
||||
socket.emit('skip', [chan, guid]);
|
||||
|
||||
voteRes = ($.ajax({
|
||||
type: "GET",
|
||||
url: "php/change.php",
|
||||
async: false,
|
||||
data: "skip",
|
||||
success: function() {
|
||||
console.log("voted to skip song");
|
||||
//console.log("voted to skip song");
|
||||
//$("#search").addClass("success");
|
||||
updateList();
|
||||
},
|
||||
|
||||
@@ -101,6 +101,7 @@ function initSlider()
|
||||
setVolume(ui.value);
|
||||
}
|
||||
});
|
||||
ytplayer.mute();
|
||||
$("#volume").slider("value", ytplayer.getVolume());
|
||||
}
|
||||
|
||||
|
||||
@@ -60,12 +60,12 @@ $(document).ready(function()
|
||||
}).responseText;
|
||||
//console.log(response);
|
||||
response = $.parseJSON(response);
|
||||
console.log(response.nowPlaying.length);
|
||||
//console.log(response.nowPlaying.length);
|
||||
conf = response.conf;
|
||||
console.log(conf);
|
||||
//console.log(conf);
|
||||
try{
|
||||
for(var first in response.nowPlaying) break;
|
||||
console.log(first);
|
||||
//console.log(first);
|
||||
response = first;
|
||||
}catch(err){
|
||||
response = "1";
|
||||
@@ -131,18 +131,18 @@ function onYouTubeIframeAPIReady() {
|
||||
}
|
||||
|
||||
function onPlayerStateChange(newState) {
|
||||
console.log("new state: "+newState.data);
|
||||
console.log("beginning: "+beginning);
|
||||
//console.log("new state: "+newState.data);
|
||||
//console.log("beginning: "+beginning);
|
||||
//ytplayer.seekTo(15);
|
||||
if((newState.data === 0 && checkEnd()) || (newState.data == 1 && checkEnd()))
|
||||
{
|
||||
console.log("nummer 1");
|
||||
//console.log("nummer 1");
|
||||
startNextSong();
|
||||
ytplayer.pauseVideo();
|
||||
wasPaused = false;
|
||||
}else if(newState.data == 1 && (wasPaused && !beginning))
|
||||
{
|
||||
console.log("unpaused");
|
||||
//console.log("unpaused");
|
||||
beginning = false;
|
||||
wasPaused = false;
|
||||
if(!syncInterval)
|
||||
@@ -158,7 +158,7 @@ function onPlayerStateChange(newState) {
|
||||
if(newState.data == 1 || newState.data == 2)
|
||||
{
|
||||
activeButton = document.getElementById("playpause").className;
|
||||
console.log(activeButton);
|
||||
//console.log(activeButton);
|
||||
if((newState.data == 2 && activeButton == "pause") || (newState.data == 1 && activeButton == "play"))
|
||||
{
|
||||
$("#playpause").toggleClass("play");
|
||||
@@ -168,9 +168,9 @@ function onPlayerStateChange(newState) {
|
||||
if(newState.data === 0)
|
||||
{
|
||||
quickFixCountdown = setTimeout(function(){
|
||||
console.log("trying quickfix");
|
||||
//console.log("trying quickfix");
|
||||
if(ytplayer.getPlayerState() === 0){
|
||||
console.log("quickfixPlay");
|
||||
//console.log("quickfixPlay");
|
||||
startNextSong();
|
||||
wasPaused = false;
|
||||
}
|
||||
@@ -180,7 +180,7 @@ function onPlayerStateChange(newState) {
|
||||
|
||||
function checkEnd()
|
||||
{
|
||||
console.log("sjekker om brukeren spolte");
|
||||
//console.log("sjekker om brukeren spolte");
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: 'php/timedifference.php',
|
||||
@@ -211,12 +211,12 @@ function startNextSong()
|
||||
data: "thisUrl="+response+"&act=save",
|
||||
|
||||
success: function() {
|
||||
console.log("saved song-switch - "+response);
|
||||
//console.log("saved song-switch - "+response);
|
||||
}
|
||||
}).responseText;
|
||||
arr = $.parseJSON(arr);
|
||||
response = arr.id;
|
||||
console.log("next video: "+response);
|
||||
//console.log("next video: "+response);
|
||||
getTitle(response);
|
||||
if(!window.mobilecheck())
|
||||
{
|
||||
@@ -235,7 +235,7 @@ function startNextSong()
|
||||
if(!syncInterval)
|
||||
syncInterval = setInterval(getTime, 5000);
|
||||
interval = true;
|
||||
console.log("starter intervallen. Interval: " + interval);
|
||||
//console.log("starter intervallen. Interval: " + interval);
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
@@ -243,11 +243,11 @@ function startNextSong()
|
||||
|
||||
function getTime()
|
||||
{
|
||||
console.log("utenfor if test" + wasPaused);
|
||||
//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");
|
||||
//console.log("sjekker om brukeren spolte");
|
||||
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
@@ -258,8 +258,8 @@ function getTime()
|
||||
timeDifference = $.parseJSON(data);
|
||||
}
|
||||
});
|
||||
console.log("current song: "+response);
|
||||
console.log("song in database: "+timeDifference[1]);
|
||||
//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)
|
||||
{
|
||||
@@ -268,7 +268,7 @@ function getTime()
|
||||
{
|
||||
if(parseInt(timeDifference[0]) > ytplayer.getDuration())
|
||||
{
|
||||
console.log("burde ikke søke, men hoppe til neste sang");
|
||||
//console.log("burde ikke søke, men hoppe til neste sang");
|
||||
}
|
||||
ytplayer.seekTo(timeDifference[0]);
|
||||
ytplayer.pauseVideo();
|
||||
@@ -283,7 +283,7 @@ function getTime()
|
||||
{
|
||||
//clearInterval(syncInterval);
|
||||
wasPaused = true;
|
||||
console.log("forskjellige videoer!!");
|
||||
//console.log("forskjellige videoer!!");
|
||||
if(!window.mobilecheck())
|
||||
{
|
||||
ytplayer.pauseVideo();
|
||||
@@ -354,7 +354,7 @@ function errorHandler(newState)
|
||||
data: "thisUrl="+response+"&act=empty",
|
||||
|
||||
success: function() {
|
||||
console.log("error! deleted video");
|
||||
//console.log("error! deleted video");
|
||||
}
|
||||
}).responseText;
|
||||
arr = $.parseJSON(arr);
|
||||
@@ -410,7 +410,7 @@ function setBGimage(id){
|
||||
var bg = new Image();
|
||||
bg.src = "http://img.youtube.com/vi/"+id+"/0.jpg";
|
||||
$("#bgimage").addClass("noopacity");
|
||||
console.log(bg);
|
||||
//console.log(bg);
|
||||
bg.addEventListener("load", function(){
|
||||
setTimeout(function(){
|
||||
$("#bgimage").css("background-image", "url("+bg.src+")");
|
||||
|
||||
Reference in New Issue
Block a user