mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 20:48:48 +00:00
Added desktop notifications and removed doubleloading the same video
This commit is contained in:
@@ -30,6 +30,7 @@ var music = 0;
|
|||||||
var longS = 0;
|
var longS = 0;
|
||||||
var frontpage = 1;
|
var frontpage = 1;
|
||||||
var adminpass = "";
|
var adminpass = "";
|
||||||
|
var notified = false;
|
||||||
|
|
||||||
$(document).ready(function()
|
$(document).ready(function()
|
||||||
{
|
{
|
||||||
@@ -44,6 +45,7 @@ $(document).ready(function()
|
|||||||
{
|
{
|
||||||
$("#change").css("opacity", "0");
|
$("#change").css("opacity", "0");
|
||||||
$("#wrapper").css("opacity", "0");
|
$("#wrapper").css("opacity", "0");
|
||||||
|
Notification.requestPermission();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateList();
|
updateList();
|
||||||
@@ -68,19 +70,6 @@ $(document).ready(function()
|
|||||||
response = "1";
|
response = "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
$.ajax({
|
|
||||||
type: 'get',
|
|
||||||
url: 'php/timedifference.php',
|
|
||||||
data: "abcde",
|
|
||||||
async: false,
|
|
||||||
success: function(data) {
|
|
||||||
timeDifference = $.parseJSON(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log("timediff:"+timeDifference[0]);
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(window.mobilecheck()){
|
if(window.mobilecheck()){
|
||||||
//syncInterval = setInterval(getTime, 50000);
|
//syncInterval = setInterval(getTime, 50000);
|
||||||
//listInterval = setInterval(updateList, 50000);
|
//listInterval = setInterval(updateList, 50000);
|
||||||
@@ -193,7 +182,7 @@ function startNextSong()
|
|||||||
if(checkEnd() && !changed)
|
if(checkEnd() && !changed)
|
||||||
{
|
{
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
response = $.ajax({
|
arr = $.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "php/change.php",
|
url: "php/change.php",
|
||||||
async: false,
|
async: false,
|
||||||
@@ -203,12 +192,14 @@ function startNextSong()
|
|||||||
console.log("saved song-switch - "+response);
|
console.log("saved song-switch - "+response);
|
||||||
}
|
}
|
||||||
}).responseText;
|
}).responseText;
|
||||||
|
arr = $.parseJSON(arr);
|
||||||
|
response = arr.id;
|
||||||
console.log("next video: "+response);
|
console.log("next video: "+response);
|
||||||
getTitle(response);
|
getTitle(response);
|
||||||
if(!window.mobilecheck())
|
if(!window.mobilecheck())
|
||||||
{
|
{
|
||||||
ytplayer.loadVideoById(response);
|
ytplayer.loadVideoById(response);
|
||||||
|
notifyUser(response, arr.title);
|
||||||
}
|
}
|
||||||
beginning = true;
|
beginning = true;
|
||||||
setBGimage(response);
|
setBGimage(response);
|
||||||
@@ -275,10 +266,16 @@ function getTime()
|
|||||||
{
|
{
|
||||||
ytplayer.pauseVideo();
|
ytplayer.pauseVideo();
|
||||||
ytplayer.loadVideoById(timeDifference[1]);
|
ytplayer.loadVideoById(timeDifference[1]);
|
||||||
|
notifyUser(timeDifference[1], timeDifference[4]);
|
||||||
|
wasPaused = false;
|
||||||
|
if(!syncInterval)
|
||||||
|
syncInterval = setInterval(getTime, 5000);
|
||||||
}
|
}
|
||||||
|
response = timeDifference[1];
|
||||||
|
getTitle();
|
||||||
setBGimage(timeDifference[1]);
|
setBGimage(timeDifference[1]);
|
||||||
updateList();
|
updateList();
|
||||||
setTimeout(function(){
|
/*setTimeout(function(){
|
||||||
//console.log(response);
|
//console.log(response);
|
||||||
diffVideo = true;
|
diffVideo = true;
|
||||||
beginning = true;
|
beginning = true;
|
||||||
@@ -296,7 +293,7 @@ function getTime()
|
|||||||
wasPaused = false;
|
wasPaused = false;
|
||||||
if(!syncInterval)
|
if(!syncInterval)
|
||||||
syncInterval = setInterval(getTime, 5000);
|
syncInterval = setInterval(getTime, 5000);
|
||||||
},2500);
|
},2500);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,7 +318,7 @@ function getTitle()
|
|||||||
function errorHandler(newState)
|
function errorHandler(newState)
|
||||||
{
|
{
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
response = $.ajax({
|
arr = $.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "php/change.php",
|
url: "php/change.php",
|
||||||
async: false,
|
async: false,
|
||||||
@@ -331,9 +328,12 @@ function errorHandler(newState)
|
|||||||
console.log("error! deleted video");
|
console.log("error! deleted video");
|
||||||
}
|
}
|
||||||
}).responseText;
|
}).responseText;
|
||||||
|
arr = $.parseJSON(arr);
|
||||||
|
response = arr.id;
|
||||||
if(!window.mobilecheck())
|
if(!window.mobilecheck())
|
||||||
{
|
{
|
||||||
ytplayer.loadVideoById(response);
|
ytplayer.loadVideoById(response);
|
||||||
|
notifyUser(response);
|
||||||
}
|
}
|
||||||
setBGimage(response);
|
setBGimage(response);
|
||||||
},2500);
|
},2500);
|
||||||
@@ -395,3 +395,13 @@ function setBGimage(id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notifyUser(id, title) {
|
||||||
|
title= title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&");
|
||||||
|
if (Notification.permission === "granted" && !notified && document.hidden) {
|
||||||
|
var notification = new Notification("Now Playing", {body: title, icon: "http://i.ytimg.com/vi/"+id+"/hqdefault.jpg"});
|
||||||
|
setTimeout(function(){
|
||||||
|
notification.close();
|
||||||
|
},10000);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -110,7 +110,7 @@ if(isset($_REQUEST['thisUrl'])){
|
|||||||
file_put_contents($list, json_encode($data));
|
file_put_contents($list, json_encode($data));
|
||||||
}
|
}
|
||||||
$newPlaying = array_values($data["nowPlaying"]); //returning the new songs id to the javascript so it gets what song to start next
|
$newPlaying = array_values($data["nowPlaying"]); //returning the new songs id to the javascript so it gets what song to start next
|
||||||
echo $newPlaying[0]["id"];
|
echo json_encode(array( "id" => $newPlaying[0]["id"], "title" => $newPlaying[0]["title"]));
|
||||||
}
|
}
|
||||||
else if(isset($_GET['v'])){ //if it gets v, we start our add "function"
|
else if(isset($_GET['v'])){ //if it gets v, we start our add "function"
|
||||||
$q = $data["conf"];
|
$q = $data["conf"];
|
||||||
|
|||||||
Reference in New Issue
Block a user