forked from Adleraci/adlerka.top
Fix script on open page
This commit is contained in:
parent
2cade060cf
commit
7dbb38913b
@ -126,12 +126,13 @@ function navigateTo(site, page){
|
|||||||
data.append("site", site);
|
data.append("site", site);
|
||||||
data.append("page", page);
|
data.append("page", page);
|
||||||
doPageAction(data);
|
doPageAction(data);
|
||||||
pageData.currentSite = site;
|
localStorage.setItem("currentSite", site);
|
||||||
pageData.currentPage = page;
|
localStorage.setItem("currentPage", page);
|
||||||
|
onPageLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
function softReload(){
|
function softReload(){
|
||||||
navigateTo(pageData.currentSite, pageData.currentPage);
|
navigateTo(localStorage.getItem("currentSite"), localStorage.getItem("currentPage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshNavbar(){
|
function refreshNavbar(){
|
||||||
@ -146,7 +147,7 @@ function logout() {
|
|||||||
|
|
||||||
doAccountAction(data, "Logout Successful!", "Logout failed.").then(() => {
|
doAccountAction(data, "Logout Successful!", "Logout failed.").then(() => {
|
||||||
refreshNavbar();
|
refreshNavbar();
|
||||||
navigateTo("", pageData.defaultPage);
|
navigateTo("", localStorage.getItem("defaultPage"));
|
||||||
// Expected output: "Success!"
|
// Expected output: "Success!"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -170,10 +171,27 @@ function initAjax() {
|
|||||||
// You can use this information to update the URL or perform other actions
|
// You can use this information to update the URL or perform other actions
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
onPageLoad();
|
||||||
}
|
}
|
||||||
document.addEventListener('DOMContentLoaded', initAjax);
|
document.addEventListener('DOMContentLoaded', initAjax);
|
||||||
|
|
||||||
|
|
||||||
|
function onPageLoad(){
|
||||||
|
let currentSite = localStorage.getItem("currentSite");
|
||||||
|
let currentPage = localStorage.getItem("currentPage");
|
||||||
|
if(currentSite === "home" && currentPage === "settings"){
|
||||||
|
if(document.getElementById("user-settings")){
|
||||||
|
getUserInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(currentSite === "home" && currentPage === "settings"){
|
||||||
|
if(document.getElementById("admin-settings")){
|
||||||
|
listActivationCodes();
|
||||||
|
listUsers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Login
|
//Login
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
@ -279,8 +297,6 @@ async function getUserInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', getUserInfo);
|
|
||||||
|
|
||||||
//User settings end
|
//User settings end
|
||||||
|
|
||||||
//Admin settings start
|
//Admin settings start
|
||||||
@ -337,8 +353,4 @@ function deleteActivationCode(activationCode) {
|
|||||||
doAccountAction(data, "Activation code deleted Successfully!", "Activation code deletion failed.");
|
doAccountAction(data, "Activation code deleted Successfully!", "Activation code deletion failed.");
|
||||||
listActivationCodes();
|
listActivationCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', listUsers);
|
|
||||||
document.addEventListener('DOMContentLoaded', listActivationCodes);
|
|
||||||
//Admin settings end
|
//Admin settings end
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
function generateScriptData($input) :string
|
function generateScriptData($phpArray) {
|
||||||
{
|
// Check if the array is associative and single-level
|
||||||
// Convert PHP array to JSON string
|
if (is_array($phpArray) && count($phpArray) > 0 && count(array_filter(array_keys($phpArray), 'is_string')) === count($phpArray)) {
|
||||||
$jsonString = json_encode($input);
|
// Generate JavaScript code to save each array element to local storage
|
||||||
|
echo "<script>";
|
||||||
|
foreach ($phpArray as $key => $value) {
|
||||||
|
$escapedKey = addslashes($key); // Escape special characters in the key
|
||||||
|
$escapedValue = addslashes($value); // Escape special characters in the value
|
||||||
|
|
||||||
// Output JavaScript code with the JSON string
|
echo "localStorage.setItem('$escapedKey', '$escapedValue');";
|
||||||
return "<script>let pageData = JSON.parse('$jsonString');</script>";
|
}
|
||||||
|
echo "</script>";
|
||||||
|
} else {
|
||||||
|
echo "<script>console.error('Invalid PHP array. Must be single-level and associative.');</script>";
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
<div class="form-container" id="addActivationCodesForm">
|
<div class="admin-settings">
|
||||||
|
<div class="form-container" id="addActivationCodesForm">
|
||||||
<h1>Activation Codes</h1>
|
<h1>Activation Codes</h1>
|
||||||
|
|
||||||
<h2>List Activation Codes</h2>
|
<h2>List Activation Codes</h2>
|
||||||
@ -10,15 +11,15 @@
|
|||||||
<br>
|
<br>
|
||||||
<table id="codeListTable"></table>
|
<table id="codeListTable"></table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div class="form-container" id="listUsersForm">
|
<div class="form-container" id="listUsersForm">
|
||||||
<h1>List Users</h1>
|
<h1>List Users</h1>
|
||||||
<button type="button" onclick="listUsers()">List Users</button><br>
|
<button type="button" onclick="listUsers()">List Users</button><br>
|
||||||
<br>
|
<br>
|
||||||
<table id="userListTable"></table>
|
<table id="userListTable"></table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
@ -1,9 +1,9 @@
|
|||||||
<!-- Centralized Status Message -->
|
<!-- Centralized Status Message -->
|
||||||
<p id="StatusMessage"></p>
|
<p id="StatusMessage"></p>
|
||||||
|
<div id="user-settings">
|
||||||
|
<button type="button" onclick="logout()">Logout</button><br>
|
||||||
|
|
||||||
<button type="button" onclick="logout()">Logout</button><br>
|
<div class="form-container" id="updateUserProfileForm">
|
||||||
|
|
||||||
<div class="form-container" id="updateUserProfileForm">
|
|
||||||
<h1>Update User</h1>
|
<h1>Update User</h1>
|
||||||
|
|
||||||
<h2>Profile</h2>
|
<h2>Profile</h2>
|
||||||
@ -41,7 +41,7 @@
|
|||||||
<input type="password" id="changeNewPassword" name="changeNewPassword" required><br>
|
<input type="password" id="changeNewPassword" name="changeNewPassword" required><br>
|
||||||
|
|
||||||
<button type="button" onclick="changePassword()">Change Password</button>
|
<button type="button" onclick="changePassword()">Change Password</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user