// Main JavaScript for Golden Pulse Tracker
document.addEventListener('DOMContentLoaded', function() {
// Initialize Feather Icons
feather.replace();
// Back to top button
const backToTopButton = document.getElementById('back-to-top');
window.addEventListener('scroll', function() {
if (window.pageYOffset > 300) {
backToTopButton.classList.add('visible');
backToTopButton.classList.remove('opacity-0', 'invisible');
} else {
backToTopButton.classList.remove('visible');
backToTopButton.classList.add('opacity-0', 'invisible');
}
});
backToTopButton.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Simulate real-time gold price updates (in a real app, this would be API calls)
function updateGoldPrices() {
// Generate random prices for demonstration
const gramPrice = (Math.random() * 100 + 1800).toFixed(2);
const quarterPrice = (Math.random() * 100 + 4500).toFixed(2);
const halfPrice = (Math.random() * 100 + 9000).toFixed(2);
const republicPrice = (Math.random() * 100 + 18000).toFixed(2);
const ouncePrice = (Math.random() * 100 + 56000).toFixed(2);
// Generate random change percentages (-2% to +2%)
const gramChange = (Math.random() * 4 - 2).toFixed(2);
const quarterChange = (Math.random() * 4 - 2).toFixed(2);
const halfChange = (Math.random() * 4 - 2).toFixed(2);
const republicChange = (Math.random() * 4 - 2).toFixed(2);
const ounceChange = (Math.random() * 4 - 2).toFixed(2);
// Update DOM
document.getElementById('gram-price').textContent = `₺${gramPrice}`;
document.getElementById('quarter-price').textContent = `₺${quarterPrice}`;
document.getElementById('half-price').textContent = `₺${halfPrice}`;
document.getElementById('republic-price').textContent = `₺${republicPrice}`;
document.getElementById('ounce-price').textContent = `₺${ouncePrice}`;
// Update change indicators
updateChangeIndicator('gram', gramChange);
updateChangeIndicator('quarter', quarterChange);
updateChangeIndicator('half', halfChange);
updateChangeIndicator('republic', republicChange);
updateChangeIndicator('ounce', ounceChange);
// Update timestamp
const now = new Date();
document.getElementById('last-updated').textContent = now.toLocaleTimeString();
}
function updateChangeIndicator(type, change) {
const element = document.getElementById(`${type}-change`);
const isPositive = parseFloat(change) >= 0;
element.innerHTML = `
${isPositive ? '+' : ''}${change}%
`;
feather.replace();
}
// Initial price update
updateGoldPrices();
// Update prices every second
setInterval(updateGoldPrices, 1000);
// Smooth scrolling for navigation
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
});