Исправление: кнопка Сканировать не показывалась, т.к. ранний return зависел от закомментированного блока загрузки

This commit is contained in:
apuc committed 2026-09-18 14:20:40 +03:00
1 parent 91c63fd652
commit b419fe2092
1 file changed
+18 -14
+18 -14
View File
@@ -52,10 +52,13 @@
var resultCard = document.getElementById('resultCard');
var resultContent = document.getElementById('resultContent');
if (!uploadArea || !fileInput || !analyzeBtn) return; // шорткод не выведен
// Блок загрузки может быть закомментирован (осталось только сканирование с камеры),
// поэтому НЕ выходим раньше времени — инициализируем сканирование всегда.
var hasUpload = !!(uploadArea && fileInput && analyzeBtn);
var selectedFile = null;
if (hasUpload) {
uploadArea.addEventListener('click', function () { fileInput.click(); });
uploadArea.addEventListener('dragover', function (e) {
e.preventDefault();
@@ -84,11 +87,12 @@
if (!selectedFile) return;
sendVideo(selectedFile, selectedFile.name);
});
}
async function sendVideo(blob, filename) {
analyzeBtn.disabled = true;
progressContainer.style.display = 'block';
resultCard.style.display = 'none';
if (analyzeBtn) analyzeBtn.disabled = true;
if (progressContainer) progressContainer.style.display = 'block';
if (resultCard) resultCard.style.display = 'none';
setProgress(5, 'Загрузка видео...');
var formData = new FormData();
@@ -125,7 +129,7 @@
setProgress(100, 'Готово!');
document.getElementById('scanLoader').classList.remove('open');
setTimeout(function () {
progressContainer.style.display = 'none';
if (progressContainer) progressContainer.style.display = 'none';
renderResult(data);
}, 300);
return;
@@ -147,27 +151,27 @@
}
function setProgress(pct, text) {
progressFill.style.width = pct + '%';
progressText.textContent = text;
if (progressFill) progressFill.style.width = pct + '%';
if (progressText) progressText.textContent = text;
}
function showError(msg, videoUrl) {
document.getElementById('scanLoader').classList.remove('open');
progressContainer.style.display = 'none';
resultCard.style.display = 'block';
if (progressContainer) progressContainer.style.display = 'none';
if (resultCard) resultCard.style.display = 'block';
var html = '<div class="med-error-box"><strong>Ошибка:</strong> ' + escapeHtml(msg) + '</div>';
if (videoUrl) {
html += '<div style="text-align:center; margin-top:15px">' +
'<a class="med-btn-download" href="' + downloadUrl(videoUrl) + '">🎬 Скачать записанное видео</a>' +
'</div>';
}
resultContent.innerHTML = html;
analyzeBtn.disabled = false;
if (resultContent) resultContent.innerHTML = html;
if (analyzeBtn) analyzeBtn.disabled = false;
}
function renderResult(data) {
document.getElementById('scanLoader').classList.remove('open');
resultCard.style.display = 'block';
if (resultCard) resultCard.style.display = 'block';
var html = '';
@@ -227,8 +231,8 @@
'</div>';
}
resultContent.innerHTML = html;
resultCard.scrollIntoView({ behavior: 'smooth' });
if (resultContent) resultContent.innerHTML = html;
if (resultCard) resultCard.scrollIntoView({ behavior: 'smooth' });
}
// Поделиться (глобальная функция для inline-onclick)