Created
May 22, 2018 22:08
-
-
Save seppenen/4aa9f9552d7ca12fc17ad4aeb7927a3d to your computer and use it in GitHub Desktop.
Js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="format-detection" content="telephone=no" /> | |
<meta name="msapplication-tap-highlight" content="no" /> | |
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" /> | |
<!-- This is a wide open CSP declaration. To lock this down for production, see below. --> | |
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *" /> | |
<!-- Good default declaration: | |
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication | |
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly | |
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: | |
* Enable inline JS: add 'unsafe-inline' to default-src | |
* Enable eval(): add 'unsafe-eval' to default-src | |
* Create your own at http://cspisawesome.com | |
--> | |
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: 'unsafe-inline' https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *" /> --> | |
<title>Hello World</title> | |
</head> | |
<body> | |
<div class="m-3 container"> | |
<div id="link"></div> | |
<?php | |
echo "Parsing... <span class='count'></span>"; | |
?> | |
<canvas class=" " id="myChart"></canvas> | |
</div> | |
</body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script> | |
<script> | |
var b = $.Deferred(); | |
var chartlabels = [];// Dates | |
var labels = []; | |
var timeFormat = 'DD.MM.YYYY'; | |
var timeFormat2 = 'DD MMM'; | |
var parsedData = []; | |
var now = newDate(0, timeFormat); | |
$(document).ready(function() { | |
if (labels[0] == null) { | |
labelFunction(30); | |
} | |
}); | |
function newDate(days, f) { | |
return moment().add(days, 'd').format(f); | |
} | |
function labelFunction(num) { | |
for (i = 0; i < num; i++) { | |
labels.push(newDate(0 - i, timeFormat)); | |
chartlabels.push(newDate(0 - i, timeFormat2)); | |
} | |
b.resolve(); | |
getData(); | |
// labels.reverse(); | |
myChart.update(); | |
} | |
var config = { | |
type : 'bar', | |
beginAtZero : false, | |
data : { | |
datasets : [], | |
labels : chartlabels, | |
}, | |
options : { | |
scales : { | |
xAxes : [ { | |
} ], | |
yAxes : [ { | |
ticks : { | |
beginAtZero : false | |
} | |
} ] | |
}, | |
legend : { | |
display : true, | |
}, | |
} | |
}; | |
var ctx = document.getElementById("myChart"); | |
var myChart = new Chart(ctx, config); | |
function getData() { | |
$.when(b).done(function(){ | |
$.ajax({ | |
type : 'GET', | |
url : 'json.php', | |
success : function(data) { | |
parseData(data); | |
}, | |
error : function() { | |
console.log(2); | |
} | |
}); | |
}); | |
} | |
function parseData(data) { | |
if (parsedData.length > 0) { | |
parsedData = []; | |
} | |
var paikat = JSON.parse(data); | |
for (var i = 0; i < labels.length; i++) { | |
var q = 0; | |
for (var j = 0; j < paikat.length; j++) { | |
if (paikat[j].date == labels[i]) { | |
q=paikat[j].count; | |
console.log(paikat[j].date); | |
} | |
} | |
parsedData[i] = q; | |
} | |
dataPush(); | |
} | |
function dataPush(){ | |
for (var i = 0; i < parsedData.length; i++) { | |
newDataset = { | |
label : ["Bookings"], | |
backgroundColor : '#3e95cd', | |
fill : false, | |
data : parsedData, | |
borderWidth : 0, | |
pointBackgroundColor : '#3e95cd' | |
}; | |
config.data.datasets.push(newDataset); | |
parsedData = []; | |
} | |
myChart.update(); | |
} | |
function parser(){ | |
var a=0; | |
$.ajax({ | |
type: 'GET', | |
url: 'mail.php', | |
data: {'action': 'get'}, | |
success: function(data){ | |
if (data.trim().length > 0 && data.indexOf("partner") !== -1 ){ | |
console.log("parser"); | |
a=1 | |
if(a == 1){ | |
window.open(data); | |
addData(); | |
} | |
} | |
} | |
}); | |
} | |
function addData(){ | |
var a = $.Deferred(); | |
$.ajax({ | |
type : 'GET', | |
url : 'select.php?date='+now, | |
success : function(data) { | |
var data = JSON.parse(data); | |
a.resolve(); | |
if (data.length > 0){ | |
var count=parseInt(data[0].count); | |
update(count); | |
console.log("update" +data.length); | |
}else{ | |
console.log("insert"); | |
insert(); | |
} | |
}, | |
error : function() { | |
console.log(2); | |
} | |
}); | |
} | |
function insert(){ | |
$.ajax({ | |
type: 'GET', | |
url: 'insert.php', | |
data: { date : now }, | |
success: function(data){ | |
location.reload(); } | |
}); | |
} | |
function update(data){ | |
var newCount = data + 1; | |
$.ajax({ | |
type: 'GET', | |
url: 'update.php', | |
data: {count: newCount , date : now }, | |
success: function(data){ | |
location.reload(); | |
} | |
}); | |
} | |
function call(){ | |
setInterval(() => { | |
parser(); | |
}, 500); | |
} | |
call(); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment