Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -78,28 +78,42 @@ function setupPhotoUpload() {
|
|
| 78 |
const uploadArea = document.getElementById('uploadArea');
|
| 79 |
const photoInput = document.getElementById('photoInput');
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
}
|
| 101 |
|
| 102 |
function handlePhotoSelect(file) {
|
|
|
|
|
|
|
| 103 |
if (!file.type.startsWith('image/')) {
|
| 104 |
showAlert('Select image file', 'error');
|
| 105 |
return;
|
|
@@ -109,6 +123,7 @@ function handlePhotoSelect(file) {
|
|
| 109 |
reader.onload = async (e) => {
|
| 110 |
uploadedPhoto = new Image();
|
| 111 |
uploadedPhoto.onload = async () => {
|
|
|
|
| 112 |
document.getElementById('photoPreview').src = e.target.result;
|
| 113 |
document.getElementById('photoName').textContent = file.name;
|
| 114 |
document.getElementById('photoPreviewContainer').style.display = 'block';
|
|
@@ -125,25 +140,31 @@ function handlePhotoSelect(file) {
|
|
| 125 |
async function extractFaceEmbedding(image) {
|
| 126 |
try {
|
| 127 |
if (!detector) {
|
|
|
|
| 128 |
showAlert('Face detection loading...', 'error');
|
| 129 |
return;
|
| 130 |
}
|
| 131 |
|
|
|
|
| 132 |
const faces = await detector.estimateFaces(image);
|
|
|
|
| 133 |
|
| 134 |
if (faces.length === 0) {
|
| 135 |
showAlert('No face detected in image', 'error');
|
|
|
|
| 136 |
return;
|
| 137 |
}
|
| 138 |
|
| 139 |
if (faces.length > 1) {
|
| 140 |
showAlert('Only one face allowed', 'error');
|
|
|
|
| 141 |
return;
|
| 142 |
}
|
| 143 |
|
| 144 |
uploadedPhotoEmbedding = faces[0];
|
| 145 |
showAlert('✓ Face detected from photo', 'success');
|
| 146 |
} catch (err) {
|
|
|
|
| 147 |
showAlert('Error processing face', 'error');
|
| 148 |
}
|
| 149 |
}
|
|
@@ -152,31 +173,59 @@ function checkStep1Complete() {
|
|
| 152 |
const username = document.getElementById('instagramUsername').value.trim();
|
| 153 |
const btn = document.getElementById('nextToStep2');
|
| 154 |
|
|
|
|
|
|
|
| 155 |
if (uploadedPhotoEmbedding && username.length > 0) {
|
| 156 |
btn.disabled = false;
|
|
|
|
| 157 |
} else {
|
| 158 |
btn.disabled = true;
|
| 159 |
}
|
| 160 |
}
|
| 161 |
|
| 162 |
function setupButtons() {
|
| 163 |
-
document.getElementById('instagramUsername')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
}
|
| 181 |
|
| 182 |
function setupWebcam() {
|
|
@@ -189,15 +238,18 @@ function setupWebcam() {
|
|
| 189 |
audio: false
|
| 190 |
})
|
| 191 |
.then(stream => {
|
|
|
|
| 192 |
video.srcObject = stream;
|
| 193 |
})
|
| 194 |
.catch(err => {
|
|
|
|
| 195 |
showAlert('Cannot access camera', 'error');
|
| 196 |
});
|
| 197 |
}
|
| 198 |
|
| 199 |
async function initializeDetector() {
|
| 200 |
try {
|
|
|
|
| 201 |
const model = await faceDetection.createDetector(
|
| 202 |
faceDetection.SupportedModels.MediaPipeFaceDetector,
|
| 203 |
{
|
|
@@ -206,12 +258,15 @@ async function initializeDetector() {
|
|
| 206 |
}
|
| 207 |
);
|
| 208 |
detector = model;
|
|
|
|
| 209 |
} catch (err) {
|
| 210 |
-
console.error('Detector error:', err);
|
| 211 |
}
|
| 212 |
}
|
| 213 |
|
| 214 |
async function startVerification() {
|
|
|
|
|
|
|
| 215 |
if (!userLocation) {
|
| 216 |
showAlert('GPS location required', 'error');
|
| 217 |
return;
|
|
@@ -276,7 +331,7 @@ async function startDetectionLoop(tasks) {
|
|
| 276 |
}
|
| 277 |
lastFrameProcessed = now;
|
| 278 |
|
| 279 |
-
if (video.readyState === video.HAVE_ENOUGH_DATA && detector) {
|
| 280 |
try {
|
| 281 |
canvas.width = video.videoWidth;
|
| 282 |
canvas.height = video.videoHeight;
|
|
@@ -477,6 +532,7 @@ function reportAccount(username) {
|
|
| 477 |
}
|
| 478 |
|
| 479 |
function goToStep(stepNum) {
|
|
|
|
| 480 |
document.querySelectorAll('.step').forEach(step => step.classList.remove('active'));
|
| 481 |
document.getElementById(`step${stepNum}`).classList.add('active');
|
| 482 |
}
|
|
|
|
| 78 |
const uploadArea = document.getElementById('uploadArea');
|
| 79 |
const photoInput = document.getElementById('photoInput');
|
| 80 |
|
| 81 |
+
if (uploadArea) {
|
| 82 |
+
uploadArea.addEventListener('click', () => {
|
| 83 |
+
photoInput.click();
|
| 84 |
+
});
|
| 85 |
+
|
| 86 |
+
uploadArea.addEventListener('dragover', (e) => {
|
| 87 |
+
e.preventDefault();
|
| 88 |
+
e.stopPropagation();
|
| 89 |
+
uploadArea.classList.add('has-file');
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
uploadArea.addEventListener('dragleave', () => {
|
| 93 |
+
uploadArea.classList.remove('has-file');
|
| 94 |
+
});
|
| 95 |
+
|
| 96 |
+
uploadArea.addEventListener('drop', (e) => {
|
| 97 |
+
e.preventDefault();
|
| 98 |
+
e.stopPropagation();
|
| 99 |
+
if (e.dataTransfer.files.length) {
|
| 100 |
+
handlePhotoSelect(e.dataTransfer.files[0]);
|
| 101 |
+
}
|
| 102 |
+
});
|
| 103 |
+
}
|
| 104 |
|
| 105 |
+
if (photoInput) {
|
| 106 |
+
photoInput.addEventListener('change', (e) => {
|
| 107 |
+
if (e.target.files.length) {
|
| 108 |
+
handlePhotoSelect(e.target.files[0]);
|
| 109 |
+
}
|
| 110 |
+
});
|
| 111 |
+
}
|
| 112 |
}
|
| 113 |
|
| 114 |
function handlePhotoSelect(file) {
|
| 115 |
+
console.log('Photo selected:', file.name);
|
| 116 |
+
|
| 117 |
if (!file.type.startsWith('image/')) {
|
| 118 |
showAlert('Select image file', 'error');
|
| 119 |
return;
|
|
|
|
| 123 |
reader.onload = async (e) => {
|
| 124 |
uploadedPhoto = new Image();
|
| 125 |
uploadedPhoto.onload = async () => {
|
| 126 |
+
console.log('Photo loaded');
|
| 127 |
document.getElementById('photoPreview').src = e.target.result;
|
| 128 |
document.getElementById('photoName').textContent = file.name;
|
| 129 |
document.getElementById('photoPreviewContainer').style.display = 'block';
|
|
|
|
| 140 |
async function extractFaceEmbedding(image) {
|
| 141 |
try {
|
| 142 |
if (!detector) {
|
| 143 |
+
console.log('Detector not ready');
|
| 144 |
showAlert('Face detection loading...', 'error');
|
| 145 |
return;
|
| 146 |
}
|
| 147 |
|
| 148 |
+
console.log('Extracting face...');
|
| 149 |
const faces = await detector.estimateFaces(image);
|
| 150 |
+
console.log('Faces found:', faces.length);
|
| 151 |
|
| 152 |
if (faces.length === 0) {
|
| 153 |
showAlert('No face detected in image', 'error');
|
| 154 |
+
uploadedPhotoEmbedding = null;
|
| 155 |
return;
|
| 156 |
}
|
| 157 |
|
| 158 |
if (faces.length > 1) {
|
| 159 |
showAlert('Only one face allowed', 'error');
|
| 160 |
+
uploadedPhotoEmbedding = null;
|
| 161 |
return;
|
| 162 |
}
|
| 163 |
|
| 164 |
uploadedPhotoEmbedding = faces[0];
|
| 165 |
showAlert('✓ Face detected from photo', 'success');
|
| 166 |
} catch (err) {
|
| 167 |
+
console.error('Face extraction error:', err);
|
| 168 |
showAlert('Error processing face', 'error');
|
| 169 |
}
|
| 170 |
}
|
|
|
|
| 173 |
const username = document.getElementById('instagramUsername').value.trim();
|
| 174 |
const btn = document.getElementById('nextToStep2');
|
| 175 |
|
| 176 |
+
console.log('Checking step 1:', uploadedPhotoEmbedding ? 'Face OK' : 'No face', username ? 'Username OK' : 'No username');
|
| 177 |
+
|
| 178 |
if (uploadedPhotoEmbedding && username.length > 0) {
|
| 179 |
btn.disabled = false;
|
| 180 |
+
console.log('Step 1 complete - Next button enabled');
|
| 181 |
} else {
|
| 182 |
btn.disabled = true;
|
| 183 |
}
|
| 184 |
}
|
| 185 |
|
| 186 |
function setupButtons() {
|
| 187 |
+
const usernameInput = document.getElementById('instagramUsername');
|
| 188 |
+
const nextBtn = document.getElementById('nextToStep2');
|
| 189 |
+
const backBtn = document.getElementById('backToStep1');
|
| 190 |
+
const startVerBtn = document.getElementById('startVerificationBtn');
|
| 191 |
+
const startOverBtn = document.getElementById('startOverBtn');
|
| 192 |
+
|
| 193 |
+
if (usernameInput) {
|
| 194 |
+
usernameInput.addEventListener('input', () => {
|
| 195 |
+
console.log('Username changed');
|
| 196 |
+
checkStep1Complete();
|
| 197 |
+
});
|
| 198 |
+
}
|
| 199 |
|
| 200 |
+
if (nextBtn) {
|
| 201 |
+
nextBtn.addEventListener('click', () => {
|
| 202 |
+
console.log('Next button clicked');
|
| 203 |
+
if (!userLocation) {
|
| 204 |
+
showAlert('Enable GPS location first', 'error');
|
| 205 |
+
return;
|
| 206 |
+
}
|
| 207 |
+
if (!uploadedPhotoEmbedding) {
|
| 208 |
+
showAlert('Upload photo first', 'error');
|
| 209 |
+
return;
|
| 210 |
+
}
|
| 211 |
+
goToStep(2);
|
| 212 |
+
});
|
| 213 |
+
}
|
| 214 |
|
| 215 |
+
if (backBtn) {
|
| 216 |
+
backBtn.addEventListener('click', () => {
|
| 217 |
+
verificationInProgress = false;
|
| 218 |
+
goToStep(1);
|
| 219 |
+
});
|
| 220 |
+
}
|
| 221 |
|
| 222 |
+
if (startVerBtn) {
|
| 223 |
+
startVerBtn.addEventListener('click', startVerification);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
if (startOverBtn) {
|
| 227 |
+
startOverBtn.addEventListener('click', reset);
|
| 228 |
+
}
|
| 229 |
}
|
| 230 |
|
| 231 |
function setupWebcam() {
|
|
|
|
| 238 |
audio: false
|
| 239 |
})
|
| 240 |
.then(stream => {
|
| 241 |
+
console.log('Webcam started');
|
| 242 |
video.srcObject = stream;
|
| 243 |
})
|
| 244 |
.catch(err => {
|
| 245 |
+
console.error('Camera error:', err);
|
| 246 |
showAlert('Cannot access camera', 'error');
|
| 247 |
});
|
| 248 |
}
|
| 249 |
|
| 250 |
async function initializeDetector() {
|
| 251 |
try {
|
| 252 |
+
console.log('Initializing detector...');
|
| 253 |
const model = await faceDetection.createDetector(
|
| 254 |
faceDetection.SupportedModels.MediaPipeFaceDetector,
|
| 255 |
{
|
|
|
|
| 258 |
}
|
| 259 |
);
|
| 260 |
detector = model;
|
| 261 |
+
console.log('Detector ready');
|
| 262 |
} catch (err) {
|
| 263 |
+
console.error('Detector init error:', err);
|
| 264 |
}
|
| 265 |
}
|
| 266 |
|
| 267 |
async function startVerification() {
|
| 268 |
+
console.log('Starting verification');
|
| 269 |
+
|
| 270 |
if (!userLocation) {
|
| 271 |
showAlert('GPS location required', 'error');
|
| 272 |
return;
|
|
|
|
| 331 |
}
|
| 332 |
lastFrameProcessed = now;
|
| 333 |
|
| 334 |
+
if (video && video.readyState === video.HAVE_ENOUGH_DATA && detector) {
|
| 335 |
try {
|
| 336 |
canvas.width = video.videoWidth;
|
| 337 |
canvas.height = video.videoHeight;
|
|
|
|
| 532 |
}
|
| 533 |
|
| 534 |
function goToStep(stepNum) {
|
| 535 |
+
console.log('Going to step:', stepNum);
|
| 536 |
document.querySelectorAll('.step').forEach(step => step.classList.remove('active'));
|
| 537 |
document.getElementById(`step${stepNum}`).classList.add('active');
|
| 538 |
}
|