File size: 5,818 Bytes
fa6316c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8614a6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa6316c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
document.addEventListener('DOMContentLoaded', function() {
    const dropZone = document.getElementById('drop-zone');
    const fileInput = document.getElementById('file-input');
    const browseBtn = document.getElementById('browse-btn');
    const previewContainer = document.getElementById('preview-container');
    const uploadContent = document.getElementById('upload-content');
    const imagePreview = document.getElementById('image-preview');
    const clearBtn = document.getElementById('clear-btn');
    const searchBtn = document.getElementById('search-btn');
    const resultsSection = document.getElementById('results-section');
    const resultsGrid = document.getElementById('results-grid');
    const loader = document.querySelector('custom-loader');

    // Drag and drop functionality
    ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
        dropZone.addEventListener(eventName, preventDefaults, false);
    });

    function preventDefaults(e) {
        e.preventDefault();
        e.stopPropagation();
    }

    ['dragenter', 'dragover'].forEach(eventName => {
        dropZone.addEventListener(eventName, highlight, false);
    });

    ['dragleave', 'drop'].forEach(eventName => {
        dropZone.addEventListener(eventName, unhighlight, false);
    });

    function highlight() {
        dropZone.classList.add('active');
    }

    function unhighlight() {
        dropZone.classList.remove('active');
    }

    dropZone.addEventListener('drop', handleDrop, false);

    function handleDrop(e) {
        const dt = e.dataTransfer;
        const files = dt.files;
        handleFiles(files);
    }

    browseBtn.addEventListener('click', () => {
        fileInput.click();
    });

    fileInput.addEventListener('change', function() {
        if (this.files.length) {
            handleFiles(this.files);
        }
    });

    clearBtn.addEventListener('click', resetUpload);
    
    function resetUpload() {
        fileInput.value = '';
        previewContainer.classList.add('hidden');
        uploadContent.classList.remove('hidden');
        resultsSection.classList.add('hidden');
    }

    function handleFiles(files) {
        const file = files[0];
        if (!file.type.match('image.*')) {
            alert('Please upload an image file');
            return;
        }

        const reader = new FileReader();
        reader.onload = function(e) {
            imagePreview.src = e.target.result;
            uploadContent.classList.add('hidden');
            previewContainer.classList.remove('hidden');
        }
        reader.readAsDataURL(file);
    }

    searchBtn.addEventListener('click', function() {
        if (!fileInput.files.length) {
            alert('Please select an image first');
            return;
        }

        // Show loader
        loader.toggleLoader(true);
        
        // Simulate API call (in a real app, you would call your backend API here)
        setTimeout(() => {
            loader.toggleLoader(false);
            displayMockResults();
            resultsSection.classList.remove('hidden');
            
            // Scroll to results
            resultsSection.scrollIntoView({ behavior: 'smooth' });
        }, 2000);
    });
    function displayMockResults() {
        // In a real app, you would display actual API results here
        resultsGrid.innerHTML = '';
        
        // Structured data for SEO
        const structuredData = {
            "@context": "https://schema.org",
            "@type": "WebApplication",
            "name": "FaceFlip Detective",
            "description": "Reverse face search engine to find people by photo",
            "applicationCategory": "SearchApplication",
            "operatingSystem": "Web Browser",
            "offers": {
                "@type": "Offer",
                "price": "0",
                "priceCurrency": "USD"
            }
        };
        
        const script = document.createElement('script');
        script.type = 'application/ld+json';
        script.text = JSON.stringify(structuredData);
        document.head.appendChild(script);
const mockResults = [
            { url: 'https://static.photos/people/320x240/1', source: 'Social Media', similarity: '85%' },
            { url: 'https://static.photos/people/320x240/2', source: 'News Article', similarity: '78%' },
            { url: 'https://static.photos/people/320x240/3', source: 'Public Records', similarity: '72%' },
            { url: 'https://static.photos/people/320x240/4', source: 'Forum Post', similarity: '65%' },
            { url: 'https://static.photos/people/320x240/5', source: 'Blog', similarity: '60%' },
            { url: 'https://static.photos/people/320x240/6', source: 'Archive', similarity: '55%' },
            { url: 'https://static.photos/people/320x240/7', source: 'Portfolio', similarity: '50%' },
            { url: 'https://static.photos/people/320x240/8', source: 'Dating Site', similarity: '48%' },
        ];

        mockResults.forEach(result => {
            const resultCard = document.createElement('div');
            resultCard.className = 'result-card bg-white rounded-lg overflow-hidden shadow-md hover:shadow-lg';
            resultCard.innerHTML = `
                <div class="relative pb-[100%]">
                    <img src="${result.url}" alt="Result" class="absolute h-full w-full object-cover">
                </div>
                <div class="p-3">
                    <p class="text-sm text-gray-600">Source: <span class="font-medium">${result.source}</span></p>
                    <p class="text-sm text-gray-600">Similarity: <span class="font-medium text-blue-500">${result.similarity}</span></p>
                </div>
            `;
            resultsGrid.appendChild(resultCard);
        });
    }
});