var states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]; var names = ["Elizabeth S.", "John D.", "Sarah M.", "Michael W.", "Jessica T.", "Emily R.", "James C.", "Linda K."]; function getBottles() { const randomValue = Math.random(); if (randomValue < 0.6) { return 6; } else if (randomValue < 0.9) { return 3; } else { return 1; } } function showOrderNotification() { let stock1Span = document.getElementById('stock1'); let currentValue1 = parseInt(stock1Span.textContent, 10); let stock2Span = document.getElementById('stock2'); if (currentValue1 < 20) { return; } let orderReel = document.querySelector(".orderreel-container, .orderreel"); orderReel.className = 'orderreel'; // Clear previous content orderReel.innerHTML = ""; // Get a random state and customer name var randomState = getRandomState(); var randomName = getRandomName(); // Create image element for state map var mapImg = document.createElement("img"); mapImg.className = "map"; mapImg.src = "https://vitrafoxin.com/assets-mbn/popup_assets/states_images/" + randomState + ".png"; mapImg.alt = randomState + " map"; // Create message container var message = document.createElement("div"); message.className = "message"; // Create main text for message var text = document.createElement("div"); text.className = "text"; numBottles = getBottles(); let newValue = currentValue1 - numBottles; stock1Span.textContent = newValue; stock2Span.textContent = newValue; text.innerHTML = `${randomName} from ${randomState} just bought ${numBottles} Bottles of Vitrafoxin`; // Add verified purchase icon var verifiedIcon = document.createElement("img"); verifiedIcon.className = "verified-icon"; verifiedIcon.src = "https://vitrafoxin.com/assets-mbn/popup_assets/images/verified_purchase.png"; verifiedIcon.alt = "Verified Purchase"; // Append elements to message message.appendChild(text); message.appendChild(verifiedIcon); // Append elements to order reel orderReel.appendChild(mapImg); orderReel.appendChild(mapImg); orderReel.appendChild(message); // Show order reel orderReel.style.transform = "scale(1)"; orderReel.style.left = "2px"; // Hide notification after a delay setTimeout(hideOrderNotification, 7000); } function hideOrderNotification() { let orderReel = document.querySelector(".orderreel-container, .orderreel"); orderReel.style.transform = "scale(0.01)"; orderReel.style.left = "-15px"; //orderReel.innerHTML = ' < div icon = "" class = "icon" id = "orders_icon" > < /div>'; // Clear content when hiding // Wait for transition to complete before hiding setTimeout(() => { orderReel.className = 'orderreel-container'; //orderReel.innerHTML = ' < div icon = "" class = "icon" id = "orders_icon" > < /div>'; // Clear content when hiding orderReel.innerHTML = ''; const div = document.createElement('div'); div.setAttribute('icon', ''); div.className = 'icon'; div.id = 'orders_icon'; orderReel.appendChild(div); }, 500); // 500ms matches your transition duration } function getRandomState() { return states[Math.floor(Math.random() * states.length)]; } function getRandomName() { return names[Math.floor(Math.random() * names.length)]; } function scheduleRandomNotifications() { showOrderNotification(); setTimeout(scheduleRandomNotifications, Math.random() * 20000 + 10000); // Between 10s and 30s //setTimeout(scheduleRandomNotifications, 15000); // Testing - Between 10s and 30s }