File size: 3,904 Bytes
20cef05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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 = `
            <span class="${isPositive ? 'price-up' : 'price-down'}">
                ${isPositive ? '+' : ''}${change}%
            </span>
            <i data-feather="${isPositive ? 'arrow-up-right' : 'arrow-down-right'}" 
               class="w-4 h-4 ml-1 ${isPositive ? 'price-up' : 'price-down'}"></i>
        `;
        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'
                });
            }
        });
    });
});