<script>
// Array of 100 users with Indian names and locations
const users = [{
name: "Aarav",
location: "Mumbai"
},
{
name: "Isha",
location: "Delhi"
},
{
name: "Rohan",
location: "Bengaluru"
},
{
name: "Priya",
location: "Chennai"
},
{
name: "Aditya",
location: "Hyderabad"
},
{
name: "Ananya",
location: "Kolkata"
},
{
name: "Karthik",
location: "Pune"
},
{
name: "Sneha",
location: "Ahmedabad"
},
{
name: "Vikram",
location: "Jaipur"
},
{
name: "Meera",
location: "Lucknow"
},
{
name: "Arjun",
location: "Chandigarh"
},
{
name: "Riya",
location: "Bhopal"
},
{
name: "Varun",
location: "Guwahati"
},
{
name: "Swati",
location: "Surat"
},
{
name: "Nikhil",
location: "Vadodara"
},
{
name: "Pooja",
location: "Nagpur"
},
{
name: "Siddharth",
location: "Coimbatore"
},
{
name: "Tanya",
location: "Vishakhapatnam"
},
{
name: "Manish",
location: "Thiruvananthapuram"
},
{
name: "Deepika",
location: "Mysuru"
},
{
name: "Rahul",
location: "Patna"
},
{
name: "Sonali",
location: "Ranchi"
},
{
name: "Aakash",
location: "Kanpur"
},
{
name: "Neha",
location: "Agra"
},
{
name: "Harish",
location: "Dehradun"
},
{
name: "Payal",
location: "Indore"
},
{
name: "Rajesh",
location: "Amritsar"
},
{
name: "Simran",
location: "Raipur"
},
{
name: "Anil",
location: "Nashik"
},
{
name: "Bhavna",
location: "Meerut"
},
{
name: "Vivek",
location: "Kochi"
},
{
name: "Alok",
location: "Puducherry"
},
{
name: "Divya",
location: "Shimla"
},
{
name: "Kiran",
location: "Panaji"
},
{
name: "Prateek",
location: "Jodhpur"
},
{
name: "Shweta",
location: "Gwalior"
},
{
name: "Rakesh",
location: "Udaipur"
},
{
name: "Ishita",
location: "Varanasi"
},
{
name: "Amit",
location: "Madurai"
},
{
name: "Komal",
location: "Bareilly"
},
{
name: "Ravi",
location: "Jalandhar"
},
{
name: "Anushka",
location: "Cuttack"
},
{
name: "Tarun",
location: "Aurangabad"
},
{
name: "Seema",
location: "Jhansi"
},
{
name: "Mahesh",
location: "Hubballi"
},
{
name: "Nisha",
location: "Vellore"
},
{
name: "Suraj",
location: "Tirupati"
},
{
name: "Pallavi",
location: "Siliguri"
},
{
name: "Arvind",
location: "Aligarh"
},
{
name: "Lavanya",
location: "Moradabad"
},
{
name: "Ganesh",
location: "Guntur"
},
{
name: "Suman",
location: "Bhilai"
},
{
name: "Ajay",
location: "Jammu"
},
{
name: "Radha",
location: "Dharamshala"
},
{
name: "Santosh",
location: "Thrissur"
},
{
name: "Archana",
location: "Rajkot"
},
{
name: "Yash",
location: "Allahabad"
},
{
name: "Snehal",
location: "Erode"
},
{
name: "Bharat",
location: "Kozhikode"
},
{
name: "Veena",
location: "Ludhiana"
},
{
name: "Mukesh",
location: "Imphal"
},
{
name: "Neetu",
location: "Jamshedpur"
},
{
name: "Prakash",
location: "Ajmer"
},
{
name: "Rachna",
location: "Rourkela"
},
{
name: "Vinay",
location: "Nellore"
},
{
name: "Jyoti",
location: "Shirdi"
},
{
name: "Ashish",
location: "Vijayawada"
},
{
name: "Monika",
location: "Kolhapur"
},
{
name: "Chirag",
location: "Panipat"
},
{
name: "Ekta",
location: "Ambala"
},
{
name: "Gopal",
location: "Solapur"
},
{
name: "Anjali",
location: "Bikaner"
},
{
name: "Rohit",
location: "Hisar"
},
{
name: "Kalpana",
location: "Ujjain"
},
{
name: "Shivam",
location: "Rohtak"
},
{
name: "Megha",
location: "Bilaspur"
},
{
name: "Anand",
location: "Bhagalpur"
},
{
name: "Rekha",
location: "Haridwar"
},
{
name: "Chetan",
location: "Saharanpur"
},
{
name: "Priti",
location: "Haldwani"
},
{
name: "Yogesh",
location: "Anantapur"
},
{
name: "Harsha",
location: "Tirunelveli"
},
{
name: "Kunal",
location: "Salem"
},
{
name: "Trisha",
location: "Gaya"
},
{
name: "Lalit",
location: "Warangal"
},
{
name: "Tanvi",
location: "Noida"
},
{
name: "Naveen",
location: "Faridabad"
},
{
name: "Ruchi",
location: "Ghaziabad"
}
];
// Function to generate a random time ago message
function getRandomTimeAgo() {
const timeUnits = [{
unit: "min",
max: 60
},
{
unit: "hr",
max: 24
}
];
const selectedUnit = timeUnits[Math.floor(Math.random() * timeUnits.length)];
const value = Math.floor(Math.random() * selectedUnit.max) + 1; // 1 to max value
return `${value} ${selectedUnit.unit}${value > 1 ? "s" : ""} ago`;
}
// Function to create and display notifications
function displayRandomUserActivity() {
const randomUser = users[Math.floor(Math.random() * users.length)];
const activities = ["purchased a course", "signed up on the site"];
const randomActivity = activities[Math.floor(Math.random() * activities.length)];
const timeAgo = getRandomTimeAgo();
// Create notification element
const notification = document.createElement("div");
notification.className = "fomo-notification";
// Create profile picture
const profilePic = document.createElement("div");
profilePic.className = "profile-pic";
profilePic.innerText = randomUser.name.charAt(0).toUpperCase(); // First letter of the name
// Create text content
const textContent = document.createElement("div");
textContent.className = "notification-text";
const mainMessage = document.createElement("span");
mainMessage.innerText = `${randomUser.name} from ${randomUser.location} just ${randomActivity}`;
const timeMessage = document.createElement("span");
timeMessage.className = "notification-time";
timeMessage.innerText = `\n(${timeAgo})`;
// Append messages to text content
textContent.appendChild(mainMessage);
textContent.appendChild(timeMessage);
// Append profile picture and text content to notification
notification.appendChild(profilePic);
notification.appendChild(textContent);
// Append to the container
const container = document.getElementById("fomo-container");
container.appendChild(notification);
// Remove notification after 5 seconds
setTimeout(() => {
container.removeChild(notification);
}, 5000);
}
// Function to start showing notifications
function startFomoNotifications() {
setInterval(displayRandomUserActivity, 7000); // Display a new notification every 7 seconds
}
// Add styles dynamically for the notification
const style = document.createElement("style");
style.innerText = `
#fomo-container {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}
.fomo-notification {
display: flex;
align-items: center;
background-color: #007bff;
color: #fff;
padding: 10px 20px;
margin: 5px 0;
border-radius: 5px;
font-family: Arial, sans-serif;
font-size: 14px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
animation: fadeIn 0.5s, fadeOut 0.5s 4.5s;
}
.profile-pic {
width: 40px;
height: 40px;
background-color: #fff;
color: #007bff;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
border-radius: 50%;
margin-right: 10px;
font-size: 16px;
}
.notification-text {
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: 5px; /* Adds a small gap between the main message and the time */
}
.notification-time {
font-size: 12px;
color: #d0d8e2;
margin-left: 5px; /* Adds a slight margin to separate it visually */
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
from { opacity: 1; transform: translateY(0); }
to { opacity: 0; transform: translateY(10px); }
}
`;
document.head.appendChild(style);
// Create the container for notifications
const fomoContainer = document.createElement("div");
fomoContainer.id = "fomo-container";
document.body.appendChild(fomoContainer);
// Start showing FOMO notifications
startFomoNotifications();
</script>