main.js.download

This commit is contained in:
Adil Sadqi 2023-09-10 20:33:37 +01:00 committed by GitHub
parent 5d0593a9bc
commit 1afbfb38b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 0 deletions

View File

@ -343,3 +343,46 @@ function loopLines(name, style, time) {
addLine(item, style, index * time); addLine(item, style, index * time);
}); });
} }
// Function to get the current date and time
function getCurrentDateTime() {
const now = new Date();
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' };
const formattedDateTime = now.toLocaleDateString(undefined, options);
return formattedDateTime;
}
// Function to get the user's local IP address
function getLocalIpAddress() {
return new Promise((resolve, reject) => {
const rtcPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
const connection = new rtcPeerConnection({ iceServers: [] });
connection.createDataChannel("");
connection.createOffer()
.then(offer => connection.setLocalDescription(offer))
.catch(error => reject(error));
connection.onicecandidate = (event) => {
if (event.candidate) {
const ipAddress = event.candidate.candidate.split(" ")[4];
resolve(ipAddress);
connection.onicecandidate = null;
connection.close();
}
};
});
}
// Update the banner content with current date, time, and local IP address
async function updateBanner() {
const formattedDateTime = getCurrentDateTime();
const localIpAddress = await getLocalIpAddress();
document.getElementById("datetime").innerText = formattedDateTime;
document.getElementById("ipaddress").innerText = `Local IP Address: ${localIpAddress}`;
}
// Execute the updateBanner function when the page loads
window.addEventListener("load", updateBanner);
// Define your banner array with the updated HTML content