Files
furatalog-old-web/assets/scripts/account.js
T

110 lines
3.7 KiB
JavaScript
Raw Normal View History

2025-05-20 12:36:47 +02:00
function addFav(id) {
return new Promise(function (resolve) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function () {
}
xmlhttp.open("POST", "/addFav.php");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send('id=' + id);
});
}
function remFav(id) {
return new Promise(function (resolve) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function () {
}
xmlhttp.open("POST", "/remFav.php");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send('id=' + id);
});
}
function getFav() {
return new Promise(function (resolve) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function () {
document.getElementById("wishlist").innerHTML = this.responseText;
console.log(this.responseText);
}
xmlhttp.open("POST", "/getFav.php");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
});
}
function refreshLiked() {
document.querySelectorAll('.likebutton').forEach(element => {
var exists = false;
try {
wishlistArray.forEach(function(item) {
if (element.attributes[1].value == String(item["id"])) {
exists = true;
}
});
} catch (err) {
err.message;
}
if (exists) {
element.innerHTML = "<icon>favorite</icon>";
} else {
element.innerHTML = "<icon>favorite_border</icon>";
}
return new Promise(function (resolve) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = async function () {
document.getElementById("wishlistScript").innerHTML = "var wishlistArray = " + this.responseText;
wishlistArray = JSON.parse(this.responseText);
}
xmlhttp.open("POST", "/getFavArray.php");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
});
});
}
getFav();
async function accOpen() {
if (!login) {
document.getElementById("wishlist").innerHTML = "<p>Please Login into your Wishlist to see your Wishlist</p>";
}
currentpos = document.body.scrollTop;
document.getElementById("footer").classList.add("addHeight");
await sleep(100);
try { document.getElementById("filter").style = "top: " + document.body.scrollTop + "px;"; } catch(err) {}
await sleep(400);
document.getElementById("body").classList.add("disableScrollbar");
try { document.getElementById("filter").classList.add("filterDisplay"); } catch(err) {}
try { document.getElementById("filterdiv").style = "display: none !important;"; } catch(err) {}
try { document.getElementById("accdiv").style = "display: grid !important;"; } catch(err) {}
document.getElementById("filterbutton").href = "#foclose";
filterisopened = true;
}
async function accClose() {
await sleep(200);
document.getElementById("body").classList.remove("disableScrollbar");
try { document.getElementById("filter").classList.remove("filterDisplay"); } catch(err) {}
await sleep(400);
await sleep(200);
document.getElementById("footer").classList.remove("addHeight");
document.getElementById("filterbutton").href = "#fo";
try { document.getElementById("filterdiv").style = "display: none !important;"; } catch(err) {}
try { document.getElementById("accdiv").style = "display: grid !important;"; } catch(err) {}
filterisopened = false;
}