diff --git a/index_files/main.js.download b/index_files/main.js.download index 99354a7..ae34728 100644 --- a/index_files/main.js.download +++ b/index_files/main.js.download @@ -343,3 +343,46 @@ function loopLines(name, style, 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