@@ -1173,7 +1327,7 @@ function renderVerifier(array $config, ?string $error = null): never
@@ -1190,10 +1344,133 @@ function renderVerifier(array $config, ?string $error = null): never
const skip = document.querySelector('#skip-form');
if (!input || !form) return;
+ const card = document.querySelector('.verify-card');
+ const image = document.querySelector('#captcha-image');
+ const saveButton = document.querySelector('#save-button');
+ const mobile = window.matchMedia('(max-width: 760px)');
+ const queueMode = form.elements.mode?.value === 'queue';
+ const formatter = new Intl.NumberFormat();
+ const toast = document.querySelector('#fast-toast');
+ let busy = false;
+ let toastTimer;
+ let viewportTimer;
+
const digitMap = {
'۰':'0','۱':'1','۲':'2','۳':'3','۴':'4','۵':'5','۶':'6','۷':'7','۸':'8','۹':'9',
'٠':'0','١':'1','٢':'2','٣':'3','٤':'4','٥':'5','٦':'6','٧':'7','٨':'8','٩':'9'
};
+
+ const fastEntryEnabled = () => mobile.matches && queueMode && skip;
+ const setText = (selector, value) => {
+ const element = document.querySelector(selector);
+ if (element) element.textContent = value;
+ };
+ const showToast = (message, isError = false) => {
+ if (!toast) return;
+ window.clearTimeout(toastTimer);
+ toast.textContent = message;
+ toast.classList.toggle('error', isError);
+ toast.classList.add('visible');
+ toastTimer = window.setTimeout(
+ () => toast.classList.remove('visible'),
+ isError ? 2600 : 650
+ );
+ };
+ const updateViewport = () => {
+ const viewport = window.visualViewport;
+ const height = viewport ? viewport.height : window.innerHeight;
+ document.documentElement.style.setProperty('--visual-height', `${height}px`);
+ if (mobile.matches && document.activeElement === input && card) {
+ window.clearTimeout(viewportTimer);
+ viewportTimer = window.setTimeout(
+ () => card.scrollIntoView({block: 'start', behavior: 'auto'}),
+ 40
+ );
+ }
+ };
+ const focusEntry = () => {
+ if (!mobile.matches) return;
+ document.body.classList.add('entry-focused');
+ updateViewport();
+ window.setTimeout(updateViewport, 180);
+ };
+ const updateSnapshot = payload => {
+ if (!payload.row) {
+ window.location.reload();
+ return;
+ }
+
+ const {row, stats, revision} = payload;
+ document.querySelectorAll('input[name="row_id"]').forEach(
+ element => element.value = row.id
+ );
+ document.querySelectorAll('input[name="revision"]').forEach(
+ element => element.value = revision
+ );
+ setText('#row-position', `Row ${formatter.format(row.number)}`);
+ setText('#mobile-counts', `${formatter.format(stats.verified)} done · ${formatter.format(stats.remaining)} left`);
+ setText('#current-filename', row.filename);
+ const filename = document.querySelector('#current-filename');
+ if (filename) filename.title = row.filename;
+
+ setText('#verified-count', formatter.format(stats.verified));
+ setText('#remaining-count', formatter.format(stats.remaining));
+ setText('#complete-count', `${stats.progress.toFixed(2)}%`);
+ setText('#progress-summary', `${formatter.format(stats.verified)} of ${formatter.format(stats.total)}`);
+ setText('#pending-summary', `${formatter.format(stats.pending)} pending CSV sync`);
+ setText('#sync-pill', stats.pending > 0 ? `${formatter.format(stats.pending)} unsynced` : 'CSV up to date');
+ const progress = document.querySelector('#main-progress');
+ if (progress) progress.style.width = `${Math.min(100, stats.progress)}%`;
+ const syncButton = document.querySelector('#sync-button');
+ if (syncButton) syncButton.disabled = stats.pending === 0;
+
+ image.src = row.image_url;
+ image.alt = `Number image for row ${row.number}`;
+ input.value = row.label || '';
+ input.focus({preventScroll: true});
+ input.select();
+ focusEntry();
+
+ if (payload.next_image_url) {
+ const preload = new Image();
+ preload.src = payload.next_image_url;
+ }
+ };
+ const submitFast = async targetForm => {
+ if (busy) return;
+ busy = true;
+ saveButton.disabled = true;
+ try {
+ const response = await fetch('./', {
+ method: 'POST',
+ body: new FormData(targetForm),
+ headers: {'Accept': 'application/json'}
+ });
+ let payload;
+ try {
+ payload = await response.json();
+ } catch {
+ throw Object.assign(new Error('The server returned an invalid response.'), {status: response.status});
+ }
+ if (!response.ok) {
+ throw Object.assign(new Error(payload.error || 'Could not save the label.'), {status: response.status});
+ }
+ updateSnapshot(payload);
+ showToast(payload.status === 'skipped' ? 'Skipped' : 'Saved');
+ } catch (problem) {
+ showToast(problem.message || 'Connection error. Reloading the queue…', true);
+ if (problem.status === 422) {
+ input.focus({preventScroll: true});
+ input.select();
+ } else {
+ window.setTimeout(() => window.location.reload(), 1200);
+ }
+ } finally {
+ busy = false;
+ saveButton.disabled = false;
+ }
+ };
+
input.addEventListener('input', () => {
input.value = Array.from(input.value, character => digitMap[character] ?? character)
.join('')
@@ -1203,10 +1480,47 @@ function renderVerifier(array $config, ?string $error = null): never
if (input.value.trim() === '' && skip) {
event.preventDefault();
skip.requestSubmit();
+ return;
+ }
+ if (fastEntryEnabled()) {
+ event.preventDefault();
+ submitFast(form);
}
});
+ if (skip) {
+ skip.addEventListener('submit', event => {
+ if (!fastEntryEnabled()) return;
+ event.preventDefault();
+ submitFast(skip);
+ });
+ }
+ input.addEventListener('focus', focusEntry);
+ input.addEventListener('blur', () => {
+ window.setTimeout(() => {
+ if (!busy && document.activeElement !== input) {
+ document.body.classList.remove('entry-focused');
+ }
+ }, 180);
+ });
+ if (window.visualViewport) {
+ window.visualViewport.addEventListener('resize', updateViewport);
+ window.visualViewport.addEventListener('scroll', updateViewport);
+ }
+ mobile.addEventListener('change', () => {
+ if (!mobile.matches) {
+ document.body.classList.remove('entry-focused');
+ document.documentElement.style.removeProperty('--visual-height');
+ }
+ });
+
+ const pageNotice = document.querySelector('#page-notice:not(.error)');
+ if (pageNotice && mobile.matches) {
+ window.setTimeout(() => pageNotice.hidden = true, 1400);
+ }
+
input.focus();
input.select();
+ updateViewport();
$error->getMessage()], $error->status);
}
if ($action === 'image') {
@@ -1289,7 +1609,7 @@ function handleRequest(): never
renderSetup($config, $error->getMessage());
} catch (Throwable $error) {
error_log((string) $error);
- if ($action === 'initialize') {
+ if ($action === 'initialize' || wantsJson()) {
jsonResponse(['error' => 'Unexpected initialization error. Check the PHP error log.'], 500);
}
http_response_code(500);