submit user data in all games
This commit is contained in:
@@ -97,9 +97,11 @@ import Layout from "../../layouts/Layout.astro";
|
||||
</Layout>
|
||||
<script is:inline>
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const paramsID = params.get('id');
|
||||
const gameId = params.get('id');
|
||||
const userId = params.get('userid');
|
||||
let startTime = Date.now();
|
||||
|
||||
fetch(`https://game-du.teachertrainingkolkata.in/items/game_cross_varient2/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
|
||||
fetch(`https://game-du.teachertrainingkolkata.in/items/game_cross_varient2/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
gameData = data.data;
|
||||
@@ -147,26 +149,24 @@ import Layout from "../../layouts/Layout.astro";
|
||||
|
||||
if (checkbox.checked) {
|
||||
if (gameData[id.replace('image', 'a')] === true) {
|
||||
element.classList.add('greenBorder');
|
||||
} else {
|
||||
element.classList.add('redBorder');
|
||||
} else {
|
||||
element.classList.add('greenBorder');
|
||||
}
|
||||
} else {
|
||||
element.classList.remove('greenBorder', 'redBorder');
|
||||
element.classList.remove('redBorder', 'greenBorder');
|
||||
}
|
||||
}
|
||||
|
||||
let url = window.location.href;
|
||||
let urlSplit = url.split('/');
|
||||
let gameName = urlSplit[3] + '-' + urlSplit[4];
|
||||
let formatedDateTime;
|
||||
|
||||
window.onload = function () {
|
||||
let currentTime = new Date();
|
||||
formatedDateTime = currentTime.toLocaleString();
|
||||
};
|
||||
|
||||
function saveUserData() {
|
||||
const endTime = Date.now();
|
||||
const timeDifference = endTime - startTime;
|
||||
const timeDifferenceInSeconds = timeDifference / 1000;
|
||||
|
||||
// const checkboxValues = {
|
||||
// a1: document.getElementById('a1').checked,
|
||||
// a2: document.getElementById('a2').checked,
|
||||
@@ -192,19 +192,20 @@ import Layout from "../../layouts/Layout.astro";
|
||||
// Count points based on checkbox values and "greenBorder" class
|
||||
let totalPoints = 0;
|
||||
checkboxValues.forEach(checkbox => {
|
||||
if (checkbox.checked && checkbox.element.classList.contains('greenBorder')) {
|
||||
if (checkbox.checked && checkbox.element.classList.contains('redBorder')) {
|
||||
totalPoints += 1;
|
||||
}
|
||||
});
|
||||
let userData = {
|
||||
'user': 'tick-v2@beanstalkedu.com',
|
||||
'game_name': gameName,
|
||||
'starts': formatedDateTime,
|
||||
// 'game_start' : gameStartTime,
|
||||
'score' : totalPoints,
|
||||
'gameName': gameName,
|
||||
'gameID': gameId,
|
||||
'userId': userId,
|
||||
'gameTime': timeDifferenceInSeconds,
|
||||
'score': totalPoints,
|
||||
};
|
||||
console.log(userData);
|
||||
|
||||
fetch(`https://2016.dev2-cs.siliconpin.com/save/`, {
|
||||
fetch(`https://phaser-game-api.s38.siliconpin.com/save-data`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
Reference in New Issue
Block a user