Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- HTML for Product Page 2 -->
- <div id="sold-message-2" style="display: flex; align-items: center; gap: 5px; background-color:#fdf7f4; padding: 6px; border-radius: 14px; font-size: 11px; font-weight: bold; color: #333; position: relative;">
- <span>✅</span> <!-- New emoji -->
- <span id="sold-number-2">none</span> sold in last 24 hours
- <div id="stock-message" style="margin-left: auto;">
- <span class="limited-stock">* Few Left</span> <!-- Updated text -->
- </div>
- </div>
- <!-- CSS (Same for all product pages) -->
- <style>
- #sold-message-2 {
- background-color: #f9f4e4; /* Light but slightly darker color */
- }
- .limited-stock {
- color: red; /* Text color red */
- font-weight: bold; /* Bold text */
- animation: blinkText 2s infinite; /* Slower blinking animation */
- }
- @keyframes blinkText {
- 0% { opacity: 1; }
- 50% { opacity: 0; }
- 100% { opacity: 1; }
- }
- </style>
- <!-- JavaScript for Product Page 2 -->
- <script>
- function updateSoldNumber2() {
- // Generate a random number between 18 and 29
- const soldNumber = Math.floor(Math.random() * (29 - 18 + 1)) + 18;
- document.getElementById('sold-number-2').textContent = soldNumber;
- localStorage.setItem('lastSoldNumber_2', soldNumber); // Store the number with a unique key for this product
- localStorage.setItem('lastUpdate_2', Date.now()); // Store the update time with a unique key for this product
- }
- function initializeSoldNumber2() {
- const lastSoldNumber = localStorage.getItem('lastSoldNumber_2');
- const lastUpdate = localStorage.getItem('lastUpdate_2');
- const now = Date.now();
- const interval = 77000; // 1 minute and 17 seconds in milliseconds
- if (lastSoldNumber) {
- // If there is a stored number, use it
- document.getElementById('sold-number-2').textContent = lastSoldNumber;
- }
- if (!lastUpdate) {
- // If no update time is stored, perform an initial update
- updateSoldNumber2();
- } else {
- const elapsed = now - lastUpdate;
- if (elapsed >= interval) {
- // If it's been 77 seconds or more since the last update, update the number
- updateSoldNumber2();
- } else {
- // Schedule the next update based on the remaining time
- const timeLeft = interval - elapsed;
- setTimeout(updateSoldNumber2, timeLeft);
- }
- }
- }
- // Initialize on page load
- initializeSoldNumber2();
- // Update number every 1 minute and 17 seconds
- setInterval(updateSoldNumber2, 77000);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment