feat: add Belichya Nora calculator and VK bot
This commit is contained in:
1 parent
cd6a594ed4
commit
c86d077f9f
20 files changed
+2002
-18
No files matched your search
@@ -0,0 +1,204 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Беличья нора — калькулятор отчётов</title>
|
||||
<style>
|
||||
:root { color-scheme: dark; font-family: system-ui, sans-serif; }
|
||||
body { margin: 0; background: #171516; color: #f4eeee; }
|
||||
main { width: min(980px, calc(100% - 32px)); margin: 32px auto; }
|
||||
h1 { margin-bottom: 4px; }
|
||||
.muted { color: #b9aaad; }
|
||||
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 24px 0 16px; }
|
||||
button, select, input, textarea { font: inherit; }
|
||||
button { cursor: pointer; border: 1px solid #80656c; border-radius: 8px; padding: 9px 14px; background: #33262a; color: inherit; }
|
||||
button.active, button.primary { background: #d59b62; color: #211818; border-color: #d59b62; }
|
||||
.panel { background: #251e20; border: 1px solid #4a383d; border-radius: 12px; padding: 20px; }
|
||||
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
|
||||
label { display: grid; gap: 6px; color: #d8cace; }
|
||||
input, select, textarea { width: 100%; box-sizing: border-box; border: 1px solid #665159; border-radius: 7px; padding: 9px; background: #171516; color: inherit; }
|
||||
textarea { min-height: 210px; resize: vertical; }
|
||||
.wide { grid-column: 1 / -1; }
|
||||
.actions { display: flex; gap: 10px; margin-top: 18px; }
|
||||
.bulk { margin-bottom: 20px; padding-bottom: 18px; border-bottom: 1px solid #4a383d; }
|
||||
.bulk textarea { min-height: 100px; margin: 8px 0; }
|
||||
.bulk-status { white-space: pre-wrap; }
|
||||
.identity-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||
dialog { max-width: min(440px, calc(100% - 32px)); background: #251e20; color: inherit; border: 1px solid #80656c; border-radius: 10px; padding: 20px; }
|
||||
dialog::backdrop { background: #0009; }
|
||||
.result { margin-top: 20px; }
|
||||
.hidden { display: none; }
|
||||
.error { color: #ff9f9f; white-space: pre-wrap; }
|
||||
@media (max-width: 700px) { .grid { grid-template-columns: 1fr; } .wide { grid-column: auto; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Беличья нора — калькулятор отчётов</h1>
|
||||
<p class="muted">Один заход — один отчёт. Скриншоты к готовому отчёту нужно приложить вручную.</p>
|
||||
|
||||
<div class="tabs" role="tablist">
|
||||
<button class="active" data-mode="coaching">Прокачка ЛУ/ЗУ</button>
|
||||
<button data-mode="training">Тренировка</button>
|
||||
<button data-mode="inspection">Осмотры</button>
|
||||
</div>
|
||||
|
||||
<section class="panel">
|
||||
<div class="bulk">
|
||||
<strong>Быстрый ввод</strong>
|
||||
<p class="muted">Вставьте данные одной строкой — символы <code>|</code> не нужны. Мы распознаем заполненные поля и подскажем, что ещё указать.</p>
|
||||
<textarea id="bulkText" placeholder="15.08 11:00 11:20 Дикая Вишня 1604614 Серолап 1617140"></textarea>
|
||||
<button type="button" id="inspectBulk">Распознать данные</button>
|
||||
<p class="muted bulk-status" id="bulkStatus"></p>
|
||||
</div>
|
||||
<form id="form">
|
||||
<div id="coaching" class="grid mode">
|
||||
<label>Дата<input name="date" value="15.08" required></label>
|
||||
<label>Навык<select name="skill"><option>ЛУ</option><option>ЗУ</option></select></label>
|
||||
<label>Начало<input name="start" type="time" value="11:00" required></label>
|
||||
<label>Конец<input name="end" type="time" value="11:20" required></label>
|
||||
<label>Имя сопровождающего<input name="escort_name" required></label>
|
||||
<label>ID сопровождающего<input name="escort_id" type="number" min="1" required></label>
|
||||
<label>Имя котёнка<input name="kitten_name" required></label>
|
||||
<label>ID котёнка<input name="kitten_id" type="number" min="1" required></label>
|
||||
<label>Котёнок<select name="kitten_independence"><option value="самостоятельно">самостоятельно</option><option value="несамостоятельно">несамостоятельно</option></select></label>
|
||||
</div>
|
||||
|
||||
<div id="training" class="grid mode hidden">
|
||||
<label>Имя сопровождающего<input name="escort_name"></label>
|
||||
<label>ID сопровождающего<input name="escort_id" type="number" min="1"></label>
|
||||
<label>Имя котёнка<input name="kitten_name"></label>
|
||||
<label>ID котёнка<input name="kitten_id" type="number" min="1"></label>
|
||||
</div>
|
||||
|
||||
<div id="inspection" class="grid mode hidden">
|
||||
<label>Имя персонажа<input name="character_name"></label>
|
||||
<label>ID персонажа<input name="character_id" type="number" min="1"></label>
|
||||
<div class="wide identity-tools"><button type="button" id="resolveIdentity">Найти связку имени и ID</button><span class="muted" id="identityStatus"></span></div>
|
||||
<label>Место<select name="place"><option>дупло</option><option>расщелина</option></select></label>
|
||||
<label>Количество осмотров<input name="inspections" type="number" min="0" value="0"></label>
|
||||
<label class="wide">Ресурсы, по одному на строку: название; количество<br><textarea name="resources" placeholder="вьюнок; -2 паук; 1"></textarea></label>
|
||||
</div>
|
||||
|
||||
<div class="actions"><button class="primary" type="submit">Подготовить сообщение</button><button type="button" id="copy" disabled>Скопировать</button></div>
|
||||
</form>
|
||||
<div class="result hidden" id="result"><h2>Сообщение</h2><textarea id="message" readonly></textarea><p class="muted" id="summary"></p></div>
|
||||
<p class="error" id="error"></p>
|
||||
</section>
|
||||
</main>
|
||||
<dialog id="identityDialog">
|
||||
<p id="identityDialogText"></p>
|
||||
<label id="identityMissingLabel">Недостающее значение<input id="identityMissingValue"></label>
|
||||
<p class="muted">Связка сохранится в локальную базу и будет доступна в следующих расчётах.</p>
|
||||
<button type="button" id="saveIdentity">Добавить связку</button>
|
||||
<button type="button" id="closeIdentityDialog">Понятно</button>
|
||||
</dialog>
|
||||
<script>
|
||||
const form = document.querySelector('#form');
|
||||
const error = document.querySelector('#error');
|
||||
const result = document.querySelector('#result');
|
||||
const message = document.querySelector('#message');
|
||||
const summary = document.querySelector('#summary');
|
||||
const copy = document.querySelector('#copy');
|
||||
const bulkText = document.querySelector('#bulkText');
|
||||
const bulkStatus = document.querySelector('#bulkStatus');
|
||||
const identityStatus = document.querySelector('#identityStatus');
|
||||
const identityDialog = document.querySelector('#identityDialog');
|
||||
const identityDialogText = document.querySelector('#identityDialogText');
|
||||
const identityMissingLabel = document.querySelector('#identityMissingLabel');
|
||||
const identityMissingValue = document.querySelector('#identityMissingValue');
|
||||
let mode = 'coaching';
|
||||
function selectMode(nextMode) {
|
||||
mode = nextMode;
|
||||
document.querySelectorAll('[data-mode]').forEach(item => item.classList.toggle('active', item.dataset.mode === mode));
|
||||
document.querySelectorAll('.mode').forEach(panel => panel.classList.toggle('hidden', panel.id !== mode));
|
||||
error.textContent = '';
|
||||
}
|
||||
document.querySelectorAll('[data-mode]').forEach(button => button.addEventListener('click', () => selectMode(button.dataset.mode)));
|
||||
function setField(panel, name, value) {
|
||||
const field = document.querySelector(`#${panel} [name="${name}"]`);
|
||||
if (field && value !== undefined && value !== null) field.value = value;
|
||||
}
|
||||
document.querySelector('#inspectBulk').addEventListener('click', async () => {
|
||||
bulkStatus.textContent = '';
|
||||
try {
|
||||
const response = await fetch('/api/inspect-bulk', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({text: bulkText.value}) });
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Не удалось распознать данные');
|
||||
const fields = data.fields || {};
|
||||
if (fields.mode) selectMode(fields.mode);
|
||||
const target = fields.mode || mode;
|
||||
Object.entries(fields).forEach(([key, value]) => {
|
||||
if (['mode', 'raw', 'resources'].includes(key)) return;
|
||||
setField(target, key, value);
|
||||
});
|
||||
if (fields.resources) setField(target, 'resources', fields.resources.map(item => `${item[0]}; ${item[1]}`).join('\n'));
|
||||
bulkStatus.textContent = data.status === 'complete'
|
||||
? 'Данные распознаны. Проверьте поля и нажмите «Подготовить сообщение».'
|
||||
: `Нужно уточнить:\n${(data.questions || []).join('\n')}`;
|
||||
} catch (err) { bulkStatus.textContent = err.message; }
|
||||
});
|
||||
document.querySelector('#resolveIdentity').addEventListener('click', async () => {
|
||||
identityStatus.textContent = '';
|
||||
try {
|
||||
const name = document.querySelector('#inspection [name="character_name"]').value.trim();
|
||||
const characterId = document.querySelector('#inspection [name="character_id"]').value.trim();
|
||||
const response = await fetch('/api/resolve-identity', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({name, character_id: characterId}) });
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Не удалось проверить связку');
|
||||
if (data.status === 'found') {
|
||||
setField('inspection', 'character_name', data.name);
|
||||
setField('inspection', 'character_id', data.character_id);
|
||||
identityStatus.textContent = 'Связка найдена и подставлена.';
|
||||
} else {
|
||||
identityDialogText.textContent = data.message;
|
||||
const missing = name ? 'ID персонажа' : 'Имя персонажа';
|
||||
identityMissingLabel.firstChild.textContent = `Введите ${missing}`;
|
||||
identityMissingValue.value = '';
|
||||
identityMissingValue.type = name ? 'number' : 'text';
|
||||
if (identityDialog.showModal) identityDialog.showModal();
|
||||
else window.alert(data.message);
|
||||
}
|
||||
} catch (err) { identityStatus.textContent = err.message; }
|
||||
});
|
||||
document.querySelector('#saveIdentity').addEventListener('click', async () => {
|
||||
const nameField = document.querySelector('#inspection [name="character_name"]');
|
||||
const idField = document.querySelector('#inspection [name="character_id"]');
|
||||
const name = nameField.value.trim() || (identityMissingValue.type === 'text' ? identityMissingValue.value.trim() : '');
|
||||
const characterId = idField.value.trim() || (identityMissingValue.type === 'number' ? identityMissingValue.value.trim() : '');
|
||||
if (!name || !characterId) { identityDialogText.textContent = 'Нужно указать и имя, и ID персонажа.'; return; }
|
||||
const response = await fetch('/api/resolve-identity', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({name, character_id: characterId, remember: true}) });
|
||||
const data = await response.json();
|
||||
if (!response.ok) { identityDialogText.textContent = data.error || 'Не удалось сохранить связку'; return; }
|
||||
setField('inspection', 'character_name', data.name); setField('inspection', 'character_id', data.character_id);
|
||||
identityDialog.close(); identityStatus.textContent = 'Связка добавлена в текущий процесс.';
|
||||
});
|
||||
document.querySelector('#closeIdentityDialog').addEventListener('click', () => identityDialog.close());
|
||||
function payload() {
|
||||
const data = {};
|
||||
document.querySelectorAll(`#${mode} [name]`).forEach(field => { data[field.name] = field.value; });
|
||||
data.mode = mode;
|
||||
['escort_id', 'kitten_id', 'character_id', 'inspections'].forEach(key => { if (data[key] !== undefined && data[key] !== '') data[key] = Number(data[key]); });
|
||||
if (mode === 'inspection') {
|
||||
data.resources = (data.resources || '').split('\n').map(line => line.trim()).filter(Boolean).map(line => {
|
||||
const [name, amount] = line.split(';').map(item => item.trim());
|
||||
return [name, Number(amount)];
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}
|
||||
form.addEventListener('submit', async event => {
|
||||
event.preventDefault(); error.textContent = '';
|
||||
try {
|
||||
const response = await fetch('/api/calculate', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload()) });
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Ошибка калькулятора');
|
||||
message.value = data.message; summary.textContent = data.result ? `Результат: ${JSON.stringify(data.result)}` : '';
|
||||
result.classList.remove('hidden'); copy.disabled = false;
|
||||
} catch (err) { error.textContent = err.message; }
|
||||
});
|
||||
copy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); copy.textContent = 'Скопировано'; setTimeout(() => copy.textContent = 'Скопировать', 1500); });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user