File size: 2,287 Bytes
0d453b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', function() {
    const fetchBtn = document.getElementById('fetch-btn');
    const instagramUrl = document.getElementById('instagram-url');
    const loading = document.getElementById('loading');
    const results = document.getElementById('results');
    const winner = document.getElementById('winner');
    const participants = document.getElementById('participants');
    const pickAgain = document.getElementById('pick-again');

    // Mock data for demonstration
    const mockParticipants = [
        "@user123", "@giveawaylover", "@instafan", "@shopaholic", 
        "@fitnessguru", "@travelbug", "@foodieforever", "@techgeek",
        "@fashionista", "@bookworm", "@petlover", "@musicfan",
        "@artistlife", "@photographypro", "@entrepreneur", "@studentlife"
    ];

    fetchBtn.addEventListener('click', function() {
        if (!instagramUrl.value) {
            alert('Please enter an Instagram post URL');
            return;
        }

        // Show loading state
        loading.classList.remove('hidden');
        results.classList.add('hidden');

        // Simulate API call with timeout
        setTimeout(() => {
            loading.classList.add('hidden');
            results.classList.remove('hidden');
            
            // Display all participants
            participants.innerHTML = '';
            mockParticipants.forEach(participant => {
                const p = document.createElement('p');
                p.textContent = participant;
                p.className = 'py-1 border-b border-gray-100 last:border-0';
                participants.appendChild(p);
            });

            // Pick a random winner
            pickRandomWinner();
        }, 2000);
    });

    pickAgain.addEventListener('click', pickRandomWinner);

    function pickRandomWinner() {
        // Reset animation
        winner.classList.remove('winner-pulse');
        
        // Force reflow to restart animation
        void winner.offsetWidth;
        
        // Pick random winner
        const randomIndex = Math.floor(Math.random() * mockParticipants.length);
        winner.textContent = mockParticipants[randomIndex];
        
        // Add animation
        winner.classList.add('winner-pulse');
    }
});