Fixes the leaderboard
This commit is contained in:
@@ -23,6 +23,7 @@ if (array_key_exists("board", $_POST) && array_key_exists("history", $_POST) &&
|
||||
"message" => "You are not logged in",
|
||||
]);
|
||||
} else {
|
||||
writeLog("klumpy", "$USERNAME scored $points on leaderboard for position $position");
|
||||
echo json_encode([
|
||||
"position" => $position,
|
||||
"points" => $points,
|
||||
|
||||
@@ -13,7 +13,6 @@ function render_game(state) {
|
||||
$("#play").button("disable");
|
||||
}
|
||||
const new_score = render(state);
|
||||
console.log(new_score);
|
||||
$("#winGamePoints").text(new_score[new_score.length - 1]);
|
||||
const game_finished =
|
||||
state.board.filter((e) => e.filter((e) => !e).length !== 0).length === 0;
|
||||
|
||||
@@ -71,8 +71,8 @@
|
||||
<div id='winGame' class='popup'>
|
||||
<div class='popup-content'>
|
||||
<h1>You have finished!</h1>
|
||||
<p>You are in <span id='winGamePlace'></span> place.</p>
|
||||
<p>You have <span id='winGamePoints'></span> points.</p>
|
||||
<p>You are number <span id='winGamePlace'></span> on the leaderboard.</p>
|
||||
<p>Score: <span id='winGamePoints'></span></p>
|
||||
<a href='/klumpy'><button>Restart</button></a>
|
||||
<a href="/klumpy/leaderboard"><button>View leaderboard</button></a>
|
||||
<a id="share" href="" style="display: none"><button>View Game and Share</button></a>
|
||||
|
||||
@@ -71,7 +71,7 @@ async function loadMore() {
|
||||
leaderboard.data = data;
|
||||
for (const e of data) {
|
||||
if (
|
||||
leaderboard.unique.filter((e) => e.username === e.username).length === 0
|
||||
leaderboard.unique.filter((b) => b.username === e.username).length === 0
|
||||
) {
|
||||
leaderboard.unique.push(e);
|
||||
}
|
||||
|
||||
@@ -1,157 +1,162 @@
|
||||
[
|
||||
{
|
||||
"type": "0",
|
||||
"name": "Log In",
|
||||
"color": "#0000ff"
|
||||
},
|
||||
{
|
||||
"type": "1",
|
||||
"name": "Delete User",
|
||||
"color": "#ffff00"
|
||||
},
|
||||
{
|
||||
"type": "2",
|
||||
"name": "Create User",
|
||||
"color": "#ffff00"
|
||||
},
|
||||
{
|
||||
"type": "3",
|
||||
"name": "Change Credentials",
|
||||
"color": "#0000ff"
|
||||
},
|
||||
{
|
||||
"type": "4",
|
||||
"name": "Log Cleared",
|
||||
"color": "#800000"
|
||||
},
|
||||
{
|
||||
"type": "5",
|
||||
"name": "Button Pressed",
|
||||
"color": "#ffffff"
|
||||
},
|
||||
{
|
||||
"type": "6",
|
||||
"name": "Internet Turns Off",
|
||||
"color": "#ffa500"
|
||||
},
|
||||
{
|
||||
"type": "7",
|
||||
"name": "Internet Turns On",
|
||||
"color": "#ffa500"
|
||||
},
|
||||
{
|
||||
"type": "8",
|
||||
"name": "Schedule Change",
|
||||
"color": "#ffffff"
|
||||
},
|
||||
{
|
||||
"type": "9",
|
||||
"name": "Server Error",
|
||||
"color": "#ff0000"
|
||||
},
|
||||
{
|
||||
"type": "10",
|
||||
"name": "Edit User",
|
||||
"color": "#ffff00"
|
||||
},
|
||||
{
|
||||
"type": "11",
|
||||
"name": "Internet Schedule Edit",
|
||||
"color": "#ffffff"
|
||||
},
|
||||
{
|
||||
"type": "12",
|
||||
"name": "Server Status Change",
|
||||
"color": "#00ff00"
|
||||
},
|
||||
{
|
||||
"type": "13",
|
||||
"name": "Fan",
|
||||
"color": "#646464"
|
||||
},
|
||||
{
|
||||
"type": "14",
|
||||
"name": "Golf Game Created",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "15",
|
||||
"name": "Golf Game Joined",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "16",
|
||||
"name": "Deleted Game",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "17",
|
||||
"name": "Golf New Round",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "18",
|
||||
"name": "Backup created",
|
||||
"color": "#009966"
|
||||
},
|
||||
{
|
||||
"type": "19",
|
||||
"name": "Update",
|
||||
"color": "#00ff00"
|
||||
},
|
||||
{
|
||||
"type": "20",
|
||||
"name": "Backup deleted",
|
||||
"color": "#009966"
|
||||
},
|
||||
{
|
||||
"type": "21",
|
||||
"name": "Session revoked",
|
||||
"color": "#00ccff"
|
||||
},
|
||||
{
|
||||
"type": "22",
|
||||
"name": "Session created",
|
||||
"color": "#00ccff"
|
||||
},
|
||||
{
|
||||
"type": "23",
|
||||
"name": "Started Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "24",
|
||||
"name": "Stopped Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "25",
|
||||
"name": "Created Image",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "26",
|
||||
"name": "Deleted Image",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "27",
|
||||
"name": "Created Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "28",
|
||||
"name": "Deleted Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "29",
|
||||
"name": "Sent Email",
|
||||
"color": "#003333"
|
||||
},
|
||||
{
|
||||
"type": "30",
|
||||
"name": "Download Game",
|
||||
"color": "#FF00FF"
|
||||
}
|
||||
]
|
||||
{
|
||||
"type": "0",
|
||||
"name": "Log In",
|
||||
"color": "#0000ff"
|
||||
},
|
||||
{
|
||||
"type": "1",
|
||||
"name": "Delete User",
|
||||
"color": "#ffff00"
|
||||
},
|
||||
{
|
||||
"type": "2",
|
||||
"name": "Create User",
|
||||
"color": "#ffff00"
|
||||
},
|
||||
{
|
||||
"type": "3",
|
||||
"name": "Change Credentials",
|
||||
"color": "#0000ff"
|
||||
},
|
||||
{
|
||||
"type": "4",
|
||||
"name": "Log Cleared",
|
||||
"color": "#800000"
|
||||
},
|
||||
{
|
||||
"type": "5",
|
||||
"name": "Button Pressed",
|
||||
"color": "#ffffff"
|
||||
},
|
||||
{
|
||||
"type": "6",
|
||||
"name": "Internet Turns Off",
|
||||
"color": "#ffa500"
|
||||
},
|
||||
{
|
||||
"type": "7",
|
||||
"name": "Internet Turns On",
|
||||
"color": "#ffa500"
|
||||
},
|
||||
{
|
||||
"type": "8",
|
||||
"name": "Schedule Change",
|
||||
"color": "#ffffff"
|
||||
},
|
||||
{
|
||||
"type": "9",
|
||||
"name": "Server Error",
|
||||
"color": "#ff0000"
|
||||
},
|
||||
{
|
||||
"type": "10",
|
||||
"name": "Edit User",
|
||||
"color": "#ffff00"
|
||||
},
|
||||
{
|
||||
"type": "11",
|
||||
"name": "Internet Schedule Edit",
|
||||
"color": "#ffffff"
|
||||
},
|
||||
{
|
||||
"type": "12",
|
||||
"name": "Server Status Change",
|
||||
"color": "#00ff00"
|
||||
},
|
||||
{
|
||||
"type": "13",
|
||||
"name": "Fan",
|
||||
"color": "#646464"
|
||||
},
|
||||
{
|
||||
"type": "14",
|
||||
"name": "Golf Game Created",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "15",
|
||||
"name": "Golf Game Joined",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "16",
|
||||
"name": "Deleted Game",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "17",
|
||||
"name": "Golf New Round",
|
||||
"color": "#006600"
|
||||
},
|
||||
{
|
||||
"type": "18",
|
||||
"name": "Backup created",
|
||||
"color": "#009966"
|
||||
},
|
||||
{
|
||||
"type": "19",
|
||||
"name": "Update",
|
||||
"color": "#00ff00"
|
||||
},
|
||||
{
|
||||
"type": "20",
|
||||
"name": "Backup deleted",
|
||||
"color": "#009966"
|
||||
},
|
||||
{
|
||||
"type": "21",
|
||||
"name": "Session revoked",
|
||||
"color": "#00ccff"
|
||||
},
|
||||
{
|
||||
"type": "22",
|
||||
"name": "Session created",
|
||||
"color": "#00ccff"
|
||||
},
|
||||
{
|
||||
"type": "23",
|
||||
"name": "Started Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "24",
|
||||
"name": "Stopped Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "25",
|
||||
"name": "Created Image",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "26",
|
||||
"name": "Deleted Image",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "27",
|
||||
"name": "Created Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "28",
|
||||
"name": "Deleted Container",
|
||||
"color": "#660099"
|
||||
},
|
||||
{
|
||||
"type": "29",
|
||||
"name": "Sent Email",
|
||||
"color": "#003333"
|
||||
},
|
||||
{
|
||||
"type": "30",
|
||||
"name": "Download Game",
|
||||
"color": "#FF00FF"
|
||||
},
|
||||
{
|
||||
"type": "31",
|
||||
"name": "Klumpy",
|
||||
"color": "#003333"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,168 +1,205 @@
|
||||
function deleteUser() { // Used to delete a user
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function() {
|
||||
setTimeout(() => { $("#saveStatus").text(""); }, 5000);
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.responseText}`);
|
||||
if (user == username) {
|
||||
location.replace("/login.php");
|
||||
} else {
|
||||
$(`option[value='${user}']`).remove();
|
||||
$("#user").val(username);
|
||||
search();
|
||||
}
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while deleting user: ${this.responseText}.`);
|
||||
}
|
||||
function deleteUser() {
|
||||
// Used to delete a user
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function () {
|
||||
setTimeout(() => {
|
||||
$("#saveStatus").text("");
|
||||
}, 5000);
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.responseText}`);
|
||||
if (user == username) {
|
||||
location.replace("/login.php");
|
||||
} else {
|
||||
$(`option[value='${user}']`).remove();
|
||||
$("#user").val(username);
|
||||
search();
|
||||
}
|
||||
} else {
|
||||
$("#saveStatus").append(
|
||||
`Error while deleting user: ${this.responseText}.`
|
||||
);
|
||||
}
|
||||
ajax.open("POST", `/api/user.php`);
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`type=delete&key=${getCookie("user")}&user=${user}`);
|
||||
};
|
||||
ajax.open("POST", `/api/user.php`);
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`type=delete&key=${getCookie("user")}&user=${user}`);
|
||||
}
|
||||
function password() { // Used to change the password
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function() {
|
||||
setTimeout(() => { $("#saveStatus").text(""); }, 5000);
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.responseText}`);
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while changing password: ${this.responseText}. `);
|
||||
}
|
||||
function password() {
|
||||
// Used to change the password
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function () {
|
||||
setTimeout(() => {
|
||||
$("#saveStatus").text("");
|
||||
}, 5000);
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.responseText}`);
|
||||
} else {
|
||||
$("#saveStatus").append(
|
||||
`Error while changing password: ${this.responseText}. `
|
||||
);
|
||||
}
|
||||
ajax.open("POST", `/api/user.php`);
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`type=password&key=${getCookie("user")}&user=${user}&password=${$("#password").val()}`);
|
||||
};
|
||||
ajax.open("POST", `/api/user.php`);
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(
|
||||
`type=password&key=${getCookie("user")}&user=${user}&password=${$(
|
||||
"#password"
|
||||
).val()}`
|
||||
);
|
||||
}
|
||||
function search() { // Gets the data for the search
|
||||
user = $("#user").val();
|
||||
if (editUser || username == user) {
|
||||
$("#save").show();
|
||||
var progress = 0 // Used to see how many requests have gone through
|
||||
// Requests the privileges of the user currently logged in
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function() {
|
||||
if (ajax.status == 200) {
|
||||
window.userPriv = JSON.parse(ajax.responseText);
|
||||
if (progress == 1) {
|
||||
if (user == username) {
|
||||
window.requestUser = userPriv;
|
||||
}
|
||||
search2(userPriv, requestUser);
|
||||
} else {
|
||||
progress = 1;
|
||||
}
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.responseText}. `);
|
||||
}
|
||||
function search() {
|
||||
// Gets the data for the search
|
||||
user = $("#user").val();
|
||||
if (editUser || username == user) {
|
||||
$("#save").show();
|
||||
var progress = 0; // Used to see how many requests have gone through
|
||||
// Requests the privileges of the user currently logged in
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function () {
|
||||
if (ajax.status == 200) {
|
||||
window.userPriv = JSON.parse(ajax.responseText);
|
||||
if (progress == 1) {
|
||||
if (user == username) {
|
||||
window.requestUser = userPriv;
|
||||
}
|
||||
search2(userPriv, requestUser);
|
||||
} else {
|
||||
progress = 1;
|
||||
}
|
||||
ajax.open("GET", `/api/user.php?type=view&key=${getCookie("user")}`);
|
||||
ajax.send();
|
||||
// Gets the privileges of the user selected
|
||||
if (user == username) {
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.responseText}. `);
|
||||
}
|
||||
};
|
||||
ajax.open("GET", `/api/user.php?type=view&key=${getCookie("user")}`);
|
||||
ajax.send();
|
||||
// Gets the privileges of the user selected
|
||||
if (user == username) {
|
||||
progress = 1;
|
||||
} else {
|
||||
let ajax2 = new XMLHttpRequest();
|
||||
ajax2.onload = function () {
|
||||
if (ajax.status == 200) {
|
||||
window.requestUser = JSON.parse(this.responseText);
|
||||
if (progress == 0) {
|
||||
progress = 1;
|
||||
} else {
|
||||
search2(userPriv, requestUser);
|
||||
}
|
||||
} else {
|
||||
console.log(1)
|
||||
let ajax2 = new XMLHttpRequest();
|
||||
ajax2.onload = function() {
|
||||
if (ajax.status == 200) {
|
||||
window.requestUser = JSON.parse(this.responseText);
|
||||
if (progress == 0) {
|
||||
progress = 1
|
||||
} else {
|
||||
search2(userPriv, requestUser)
|
||||
}
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.responseText}. `);
|
||||
}
|
||||
}
|
||||
ajax2.open("GET", `/api/user.php?type=view&key=${getCookie("user")}&user=${user}`);
|
||||
ajax2.send();
|
||||
$("#header").text(`Privileges for ${user}`);
|
||||
$("#saveStatus").append(
|
||||
`Error while loading: ${this.responseText}. `
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$("#privilege").empty();
|
||||
$("#header").text("");
|
||||
$("#save").hide();
|
||||
};
|
||||
ajax2.open(
|
||||
"GET",
|
||||
`/api/user.php?type=view&key=${getCookie("user")}&user=${user}`
|
||||
);
|
||||
ajax2.send();
|
||||
$("#header").text(`Privileges for ${user}`);
|
||||
}
|
||||
}
|
||||
function search2(userPriv, requestUser) { // When the search is done it will update the user interface
|
||||
howMany = userPriv.length
|
||||
} else {
|
||||
$("#privilege").empty();
|
||||
for (let i=0; i<howMany;i++) {
|
||||
element = userPriv[i];
|
||||
if (requestUser.includes(element)) {
|
||||
checked = "checked";
|
||||
} else {
|
||||
checked = "";
|
||||
}
|
||||
$("#privilege").append(`<input type='checkbox' name='${element}' id='${element}' ${checked} value='True'>${element}<br>`);
|
||||
}
|
||||
if ($("#changeCredintials").length || user == username) { // Checks if the user can change the Credintials
|
||||
$("#passwordChange").show()
|
||||
$("#header").text("");
|
||||
$("#save").hide();
|
||||
}
|
||||
}
|
||||
function search2(userPriv, requestUser) {
|
||||
// When the search is done it will update the user interface
|
||||
howMany = userPriv.length;
|
||||
$("#privilege").empty();
|
||||
for (let i = 0; i < howMany; i++) {
|
||||
element = userPriv[i];
|
||||
if (requestUser.includes(element)) {
|
||||
checked = "checked";
|
||||
} else {
|
||||
$("#passwordChange").hide()
|
||||
checked = "";
|
||||
}
|
||||
if ($("#changeCredintials").length || user == username) { // Checks if the user can delete that user
|
||||
$("#delete").show()
|
||||
} else {
|
||||
$("#delete").hide()
|
||||
}
|
||||
setTimeout(() => { $("#saveStatus").text(""); }, 5000);
|
||||
$("#privilege").append(
|
||||
`<input type='checkbox' name='${element}' id='${element}' ${checked} value='True'>${element}<br>`
|
||||
);
|
||||
}
|
||||
if ($("#changeCredintials").length || user == username) {
|
||||
// Checks if the user can change the Credintials
|
||||
$("#passwordChange").show();
|
||||
} else {
|
||||
$("#passwordChange").hide();
|
||||
}
|
||||
if ($("#changeCredintials").length || user == username) {
|
||||
// Checks if the user can delete that user
|
||||
$("#delete").show();
|
||||
} else {
|
||||
$("#delete").hide();
|
||||
}
|
||||
setTimeout(() => {
|
||||
$("#saveStatus").text("");
|
||||
}, 5000);
|
||||
}
|
||||
function save() {
|
||||
let checkboxes = $("#privilege").find("input[type=checkbox]");
|
||||
let text = `type=edit&key=${getCookie('user')}&user=${$("#user").val()}`;
|
||||
let checkboxLength = checkboxes.length;
|
||||
for (let i=0; i<checkboxLength;i++) {
|
||||
let check = checkboxes[i];
|
||||
text += `&${check.name}=${check.checked}`;
|
||||
let checkboxes = $("#privilege").find("input[type=checkbox]");
|
||||
let text = `type=edit&key=${getCookie("user")}&user=${$("#user").val()}`;
|
||||
let checkboxLength = checkboxes.length;
|
||||
for (let i = 0; i < checkboxLength; i++) {
|
||||
let check = checkboxes[i];
|
||||
text += `&${check.name}=${check.checked}`;
|
||||
}
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function () {
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.responseText}. `);
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.responseText}. `);
|
||||
}
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function() {
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.responseText}. `);
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.responseText}. `);
|
||||
}
|
||||
search()
|
||||
}
|
||||
ajax.open("POST", "/api/user.php");
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(text);
|
||||
}
|
||||
$(document).ready(function() {
|
||||
search();
|
||||
$("#user").change(function() {search()});
|
||||
$("#save").click(function() {save()});
|
||||
$("#changePassword").click(function() {password()});
|
||||
$("#delete").click(function() {deleteUser()});
|
||||
$("#download").click(function() {
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function() {
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`Downloaded Preferences. `);
|
||||
newLocalStorage = JSON.parse(this.response);
|
||||
Object.keys(newLocalStorage).forEach(function(value) {
|
||||
localStorage[value] = newLocalStorage[value];
|
||||
});
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.response}. `);
|
||||
}
|
||||
}
|
||||
ajax.open("GET", `/api/localStorage.php?load='true'&key=${getCookie("user")}`);
|
||||
ajax.send();
|
||||
});
|
||||
$("#upload").click(function() {
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function() {
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.response}. `);
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.response}. `);
|
||||
}
|
||||
}
|
||||
ajax.open("POST", "/api/localStorage.php");
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`save=${JSON.stringify(localStorage)}&key=${getCookie("user")}`);
|
||||
});
|
||||
});
|
||||
};
|
||||
ajax.open("POST", "/api/user.php");
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(text);
|
||||
}
|
||||
$(document).ready(function () {
|
||||
search();
|
||||
$("#user").change(function () {
|
||||
search();
|
||||
});
|
||||
$("#save").click(function () {
|
||||
save();
|
||||
});
|
||||
$("#changePassword").click(function () {
|
||||
password();
|
||||
});
|
||||
$("#delete").click(function () {
|
||||
deleteUser();
|
||||
});
|
||||
$("#download").click(function () {
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function () {
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`Downloaded Preferences. `);
|
||||
newLocalStorage = JSON.parse(this.response);
|
||||
Object.keys(newLocalStorage).forEach(function (value) {
|
||||
localStorage[value] = newLocalStorage[value];
|
||||
});
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.response}. `);
|
||||
}
|
||||
};
|
||||
ajax.open(
|
||||
"GET",
|
||||
`/api/localStorage.php?load='true'&key=${getCookie("user")}`
|
||||
);
|
||||
ajax.send();
|
||||
});
|
||||
$("#upload").click(function () {
|
||||
let ajax = new XMLHttpRequest();
|
||||
ajax.onload = function () {
|
||||
if (ajax.status == 200) {
|
||||
$("#saveStatus").append(`${this.response}. `);
|
||||
} else {
|
||||
$("#saveStatus").append(`Error while loading: ${this.response}. `);
|
||||
}
|
||||
};
|
||||
ajax.open("POST", "/api/localStorage.php");
|
||||
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
ajax.send(`save=${JSON.stringify(localStorage)}&key=${getCookie("user")}`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user