-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
146 lines (134 loc) · 3.63 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
$("#divLoading").removeClass("show");
document.getElementById('login').style = 'display:none';
document.getElementById('play').style = 'display:true';
$("#play").click(function () {
document.getElementById("canvas").style.backgroundColor = '#4797F3';
testAPI();
});
} else {
console.log('please login');
$("#divLoading").removeClass("show");
document.getElementById('play').style = 'display:none';
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : '1702339276748394',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.8' // use graph api version 2.8
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function again(){
window.location.href="index.php";
}
function testAPI() {
load();
FB.api('/me', 'GET', {
fields: 'first_name,last_name,name,id,picture.width(320),gender'
},
function (response) {
document.getElementById('login').style = 'display:none';
var name_f = [
'Daisy',
'Rose',
'Violet',
'Jasmine',
'Fern',
'Helen',
'Clara',
'Clara',
'Grace',
'Ella',
'Eliza'
];
var name_m = [
'Dion',
'Cosmo',
'Cruz',
'Gaston',
'Gunnar',
'Luciano',
'Nicasino',
'Niko',
'Odin',
'Paolo',
'Pascal',
'Jame',
'Denial',
'Tadeo'
]
if(response.gender == 'male'){
var name = name_m;
}else{
var name = name_f;
}
var randomNumber = Math.floor(Math.random()*name.length);
console.log(response);
$('#profile').attr('src', response.picture.data.url);
var name = name[randomNumber];
document.getElementById('name').innerHTML = name;
var d = new Date();
var time = d.getTime();
$(function () {
var captureArea = $("#canvas");
html2canvas(captureArea, {
onrendered: function (canvas) {
// $("#canvas").html("").append(canvas);
var img = canvas.toDataURL("image/jpg", 1.0);
$.ajax({
type: 'POST',
url: "index.php",
data: {
"img": img,
"id": response.id,
"time": time
},
success: function (data) {
setTimeout(function(){
window.location.href="index.php?play_id="+response.id+time+"&name="+name;
}, 2000);
}
});
},
useCORS: true
});
});
});
}
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/th_TH/sdk.js#xfbml=1&version=v2.10&appId=1702339276748394";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
$("#share").click(function () {
FB.ui({
method: 'feed',
link: document.URL,
caption: '',
}, function(response){
window.location.href = "index.php";
});
});