Files
Local-Booru/templates/index.html
T
2026-05-26 17:31:44 +03:00

233 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LocalBooru</title>
<style>
:root {
--bg-main: #1e1e1e;
--bg-header: #252525;
--bg-card: #2a2a2a;
--bg-panel: #222;
--bg-input: #333;
--text-main: #eee;
--text-muted: #aaa;
--border-color: #444;
--color-g: #4caf50; --color-s: #ff9800; --color-q: #ffeb3b; --color-e: #f44336;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background-color: var(--bg-main); color: var(--text-main); font-family: sans-serif; font-size: 14px; }
/* Header */
header { display: flex; align-items: center; background-color: var(--bg-header); padding: 10px 20px; border-bottom: 1px solid var(--border-color); gap: 15px; flex-wrap: wrap; }
.logo { font-weight: bold; font-size: 18px; color: white; text-decoration: none; }
.analytics { color: #88bece; text-decoration: none; font-size: 12px; }
/* Search & Autocomplete */
.search-wrapper { flex-grow: 1; max-width: 400px; position: relative; }
.search-wrapper input { width: 100%; background-color: var(--bg-input); border: 1px solid var(--border-color); color: white; padding: 6px 10px; border-radius: 3px; outline: none; }
.search-wrapper input:focus { border-color: var(--text-muted); }
.autocomplete-list {
position: absolute; top: 100%; left: 0; right: 0; background-color: var(--bg-card);
border: 1px solid var(--border-color); border-radius: 3px; margin-top: 4px;
list-style: none; z-index: 1000; max-height: 250px; overflow-y: auto;
box-shadow: 0 4px 10px rgba(0,0,0,0.5); display: none;
}
.autocomplete-item {
padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; border-bottom: 1px solid #333;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background-color: var(--bg-input); }
.autocomplete-count { color: var(--text-muted); font-size: 12px; }
/* Filters */
.rating-filters { display: flex; gap: 5px; }
.rating-btn { background: transparent; color: white; border: 1px solid; width: 24px; height: 24px; border-radius: 3px; cursor: pointer; font-size: 12px; font-weight: bold; }
.rating-btn.active { opacity: 1; }
.rating-btn:not(.active) { opacity: 0.3; }
#btn-e { border-color: var(--color-e); color: var(--color-e); }
#btn-q { border-color: var(--color-q); color: var(--color-q); }
#btn-s { border-color: var(--color-s); color: var(--color-s); }
#btn-g { border-color: var(--color-g); color: var(--color-g); }
/* Main Content */
main { padding: 20px; max-width: 1600px; margin: 0 auto; }
.results-header { font-size: 18px; font-weight: bold; margin-bottom: 20px; }
.pagination-container { display: flex; justify-content: center; gap: 10px; margin: 20px 0; }
.pagination-btn { background-color: var(--bg-header); border: 1px solid var(--border-color); color: var(--text-muted); padding: 5px 12px; cursor: pointer; border-radius: 3px; }
.pagination-btn:hover:not(:disabled) { background-color: var(--bg-input); color: white; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.card { background-color: var(--bg-card); display: flex; flex-direction: column; border-radius: 3px; overflow: hidden; }
.card-image-container { width: 100%; aspect-ratio: 1/1; background-color: #333; }
.card-meta { padding: 6px; text-align: center; font-size: 10px; color: var(--text-muted); }
.loader { text-align: center; padding: 50px; color: var(--text-muted); grid-column: 1/-1; }
@media (max-width: 600px) { .search-wrapper { order: 3; max-width: 100%; width: 100%; margin-top: 10px; } }
</style>
</head>
<body>
<header>
<a href="index.html" class="logo">LocalBooru</a>
<a class="analytics" href="analytics.html">📊 Analytics</a>
<div class="search-wrapper">
<input type="text" id="searchInput" placeholder="Search tags...">
<ul id="autocompleteList" class="autocomplete-list"></ul>
</div>
<div class="rating-filters">
<button id="btn-e" class="rating-btn active" data-rating="e">E</button>
<button id="btn-q" class="rating-btn active" data-rating="q">Q</button>
<button id="btn-s" class="rating-btn active" data-rating="s">S</button>
<button id="btn-g" class="rating-btn active" data-rating="g">G</button>
</div>
</header>
<main>
<div class="results-header" id="resultsCount">Results (0)</div>
<div class="pagination-container" id="paginationTop"></div>
<div class="grid" id="imageGrid"></div>
<div class="pagination-container" id="paginationBottom"></div>
</main>
<script>
const state = { page: 0, query: "", ratings: { e: true, q: true, s: true, g: true }, totalPages: 1, totalResults: 0 };
// Инициализация
function init() {
setupAutocomplete('searchInput', 'autocompleteList');
const searchInput = document.getElementById('searchInput');
searchInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
document.getElementById('autocompleteList').style.display = 'none';
state.query = searchInput.value;
state.page = 0;
fetchData();
}
});
document.querySelectorAll('.rating-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const r = e.target.getAttribute('data-rating');
state.ratings[r] = !state.ratings[r];
e.target.classList.toggle('active', state.ratings[r]);
state.page = 0; fetchData();
});
});
fetchData();
}
// Логика автозаполнения
function setupAutocomplete(inputId, listId) {
const input = document.getElementById(inputId);
const list = document.getElementById(listId);
let debounceTimer;
input.addEventListener('input', () => {
clearTimeout(debounceTimer);
const words = input.value.split(' ');
const currentWord = words[words.length - 1];
if (currentWord.length < 2) {
list.style.display = 'none';
return;
}
debounceTimer = setTimeout(async () => {
const req = { type: "autocomplete", q: currentWord };
console.log("-> Отправка API Автозаполнения:", JSON.stringify(req));
// Заглушка API. Для реального бэка: fetch('/api', { body: JSON.stringify(req)... })
const data = await mockAutocompleteAPI(req);
if (data.length === 0) {
list.style.display = 'none';
return;
}
list.innerHTML = data.map(item => `
<li class="autocomplete-item" data-tag="${item.tag}">
<span>${item.tag}</span><span class="autocomplete-count">${item.count}</span>
</li>
`).join('');
list.style.display = 'block';
list.querySelectorAll('.autocomplete-item').forEach(li => {
li.addEventListener('click', () => {
words[words.length - 1] = li.getAttribute('data-tag');
input.value = words.join(' ') + ' ';
list.style.display = 'none';
input.focus();
});
});
}, 200); // 200ms задержка перед запросом
});
// Скрываем список при клике вне него
document.addEventListener('click', (e) => {
if (e.target !== input && e.target !== list) list.style.display = 'none';
});
}
async function fetchData() {
const grid = document.getElementById('imageGrid');
grid.innerHTML = `<div class="loader">Загрузка...</div>`;
const activeRatings = Object.keys(state.ratings).filter(k => state.ratings[k]).join('+');
const req = { page: state.page, query: state.query.trim(), rating: activeRatings };
// Заглушка API Поиска
const data = await mockSearchAPI(req);
state.totalResults = data.total_results; state.totalPages = data.total_pages;
document.getElementById('resultsCount').textContent = `Results (${state.totalResults})`;
grid.innerHTML = data.items.map(i => `
<div class="card">
<div class="card-image-container" style="background-color: hsl(${Math.random() * 360}, 20%, 30%);"></div>
<div class="card-meta">Date: ${i.date}<br>Score: ${i.score} | Rating: <span style="color:var(--color-${i.rating[0].toLowerCase()})">${i.rating}</span></div>
</div>
`).join('');
renderPagination();
}
function renderPagination() {
const html = `
<button class="pagination-btn" onclick="changePage(0)" ${state.page === 0 ? 'disabled' : ''}>&laquo; First</button>
<button class="pagination-btn" onclick="changePage(${state.page - 1})" ${state.page === 0 ? 'disabled' : ''}>&lsaquo; Prev</button>
<span style="font-size:12px; font-weight:bold;">Page ${state.page + 1} of ${state.totalPages}</span>
<button class="pagination-btn" onclick="changePage(${state.page + 1})" ${state.page >= state.totalPages - 1 ? 'disabled' : ''}>Next &rsaquo;</button>
<button class="pagination-btn" onclick="changePage(${state.totalPages - 1})" ${state.page >= state.totalPages - 1 ? 'disabled' : ''}>Last &raquo;</button>
`;
document.getElementById('paginationTop').innerHTML = html;
document.getElementById('paginationBottom').innerHTML = html;
}
window.changePage = (p) => { state.page = p; fetchData(); window.scrollTo(0,0); };
// --- ВРЕМЕННЫЕ API ЗАГЛУШКИ ---
function mockAutocompleteAPI(req) {
return new Promise(res => {
const db = [{tag: "long_hair", count: 8184}, {tag: "long_sleeves", count: 2828}, {tag: "looking_at_viewer", count: 8062}, {tag: "1girl", count: 11061}, {tag: "highres", count: 12700}, {tag: "absurdres", count: 6742}];
res(db.filter(t => t.tag.includes(req.q.toLowerCase())));
});
}
function mockSearchAPI(req) {
return new Promise(res => { setTimeout(() => {
const items = [];
if(req.rating.length > 0) {
const rArr = req.rating.split('+');
const rMap = {'g':'general','s':'sensitive','q':'questionable','e':'explicit'};
for(let i=0; i<48; i++) items.push({ date: '2026-05-20', score: 10, rating: rMap[rArr[Math.floor(Math.random()*rArr.length)]] });
}
res({ total_results: 14003, total_pages: 281, items });
}, 300);});
}
init();
</script>
</body>
</html>