File size: 2,067 Bytes
5c17346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
async function fetchAvatarData() {
    const apiKey = document.getElementById('apiKey').value.trim();
    const resultContainer = document.getElementById('resultContainer');
    const errorContainer = document.getElementById('errorContainer');
    const fetchBtn = document.getElementById('fetchBtn');

    // Clear previous results
    resultContainer.classList.add('hidden');
    errorContainer.classList.add('hidden');
    
    if (!apiKey) {
        showError('Please enter your X-Avatar-Key');
        return;
    }

    try {
        // Show loading state
        fetchBtn.disabled = true;
        fetchBtn.innerHTML = `<i data-feather="loader" class="loading"></i> Fetching...`;
        feather.replace();

        // Mock API call - replace with your actual API endpoint
        const mockAvatar = {
            name: "Generated Avatar",
            imageUrl: "https://static.photos/abstract/200x200/" + Math.floor(Math.random() * 1000),
            details: "This is a mock response. Replace with actual API call.",
            id: Math.random().toString(36).substring(2, 9)
        };

        // Simulate network delay
        await new Promise(resolve => setTimeout(resolve, 1000));

        // Display results
        document.getElementById('avatarName').textContent = mockAvatar.name;
        document.getElementById('avatarDetails').textContent = mockAvatar.details;
        document.getElementById('avatarPreview').innerHTML = 
            `<img src="${mockAvatar.imageUrl}" alt="${mockAvatar.name}" class="w-full h-full object-cover">`;
        
        resultContainer.classList.remove('hidden');
    } catch (error) {
        showError(`Error: ${error.message}`);
    } finally {
        // Reset button
        fetchBtn.disabled = false;
        fetchBtn.innerHTML = `<i data-feather="download"></i> Fetch Avatar Data`;
        feather.replace();
    }
}

function showError(message) {
    const errorContainer = document.getElementById('errorContainer');
    errorContainer.textContent = message;
    errorContainer.classList.remove('hidden');
}