feat: localize tags and genres; improve search, duration and sorting
CI / test (push) Successful in 27s
CI / test (push) Successful in 27s
This commit is contained in:
1 parent
ea3074e0a9
commit
be4fbf6864
31 files changed
+1126
-145
No files matched your search
+89
-17
@@ -20,7 +20,7 @@ function defaultFilters() {
|
||||
return {
|
||||
status: "", genres: [], tags: [], installed: false, unplayed: false, favorite: false,
|
||||
ownership: "", duration: "", minHours: "", maxHours: "", minYear: "", maxYear: "",
|
||||
minReview: "", maxReview: "",
|
||||
minReview: "", maxReview: "", minDuration: "", maxDuration: "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ const state = {
|
||||
sort: "review",
|
||||
dir: "desc",
|
||||
q: "",
|
||||
nameOnly: false,
|
||||
filters: defaultFilters(),
|
||||
preset: null,
|
||||
loading: false,
|
||||
@@ -218,11 +219,21 @@ function fmtHours(h) {
|
||||
return `${h >= 100 ? Math.round(h) : h.toFixed(1).replace(".0", "")} ч`;
|
||||
}
|
||||
|
||||
function fmtDuration(h) {
|
||||
function fmtDuration(h, approx = true) {
|
||||
if (!h) return "";
|
||||
return `≈${h >= 10 ? Math.round(h) : h.toFixed(1).replace(".0", "")} ч`;
|
||||
return `${approx ? "≈" : ""}${h >= 10 ? Math.round(h) : h.toFixed(1).replace(".0", "")} ч`;
|
||||
}
|
||||
|
||||
function durationInfo(g) {
|
||||
if (g.hltb && g.hltb.main) {
|
||||
return { value: g.hltb.main, approx: false, title: "HowLongToBeat: основное прохождение" };
|
||||
}
|
||||
if (g.duration) {
|
||||
return { value: g.duration, approx: true, title: "Оценка по жанрам и тегам" };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function defaultDir(field) {
|
||||
return ["hours", "review", "year", "favorite", "added"].includes(field) ? "desc" : "asc";
|
||||
}
|
||||
@@ -243,6 +254,16 @@ function saveSort() {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
function updateSortDirButton() {
|
||||
const button = $("#sortDir");
|
||||
if (!button) return;
|
||||
const asc = state.dir === "asc";
|
||||
button.textContent = asc ? "↑" : "↓";
|
||||
button.title = asc ? "По возрастанию" : "По убыванию";
|
||||
button.setAttribute("aria-label",
|
||||
`Направление сортировки: ${asc ? "по возрастанию" : "по убыванию"}`);
|
||||
}
|
||||
|
||||
function loadTableWidths() {
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(COLS_KEY) || "{}");
|
||||
@@ -280,12 +301,17 @@ function cardHtml(g, mode = "library") {
|
||||
? `<label class="select-box" title="Выбрать игру"><input type="checkbox" value="${g.appid}" data-select="${g.appid}"${state.selected.has(g.appid) ? " checked" : ""} aria-label="Выбрать игру"></label>`
|
||||
: "";
|
||||
const genres = (g.genres || []).slice(0, 3).map((x) => `<span class="genre">${esc(x)}</span>`).join("");
|
||||
const duration = durationInfo(g);
|
||||
const meta = [
|
||||
g.year ? esc(g.year) : null,
|
||||
mode === "library" ? fmtHours(g.hours) : null,
|
||||
g.duration ? `<span title="оценка по тегам">${fmtDuration(g.duration)}</span>` : null,
|
||||
g.rating ? `${g.rating}/10` : null,
|
||||
].filter(Boolean).map((x) => `<span>${x}</span>`).join('<span class="dot"></span>');
|
||||
g.year ? `<span>${esc(g.year)}</span>` : null,
|
||||
mode === "library" && g.hours
|
||||
? `<span class="stat" title="Наиграно в Steam">${fmtHours(g.hours)}<span class="stat-hint">наиграно</span></span>`
|
||||
: null,
|
||||
duration
|
||||
? `<span class="stat" title="${duration.title}">${fmtDuration(duration.value, duration.approx)}<span class="stat-hint">длина</span></span>`
|
||||
: null,
|
||||
g.rating ? `<span>${g.rating}/10</span>` : null,
|
||||
].filter(Boolean).join('<span class="dot"></span>');
|
||||
const desc = g.description
|
||||
? `<p class="card-desc">${esc(decodeEntities(g.description))}</p>`
|
||||
: g.desc_status === "missing"
|
||||
@@ -327,8 +353,8 @@ const TABLE_COLS = [
|
||||
{ key: "name", label: "Игра", width: 300, cls: "", sort: "name" },
|
||||
{ key: "year", label: "Год", width: 64, cls: "t-year", sort: "year" },
|
||||
{ key: "review", label: "Отзывы", width: 76, cls: "", sort: "review" },
|
||||
{ key: "hours", label: "Часы", width: 80, cls: "", sort: "hours" },
|
||||
{ key: "duration", label: "Длительность", width: 104, cls: "t-duration", sort: "duration" },
|
||||
{ key: "hours", label: "Наиграно, ч", width: 96, cls: "", sort: "hours" },
|
||||
{ key: "duration", label: "Длина, ч", width: 88, cls: "t-duration", sort: "duration" },
|
||||
{ key: "genres", label: "Жанры", width: 180, cls: "t-genres", sort: "genre" },
|
||||
{ key: "fav", label: "★", width: 30, cls: "t-fav", sort: "favorite" },
|
||||
];
|
||||
@@ -359,6 +385,7 @@ function rowHtml(g) {
|
||||
: "";
|
||||
const genres = (g.genres || []).slice(0, 3).map(esc).join(", ") || "—";
|
||||
const review = g.review != null ? `${g.review}%` : "—";
|
||||
const duration = durationInfo(g);
|
||||
return `
|
||||
<tr data-appid="${g.appid}" tabindex="0" role="button" aria-label="Открыть ${esc(g.name)}">
|
||||
<td class="t-select">${select}</td>
|
||||
@@ -374,7 +401,7 @@ function rowHtml(g) {
|
||||
<td class="t-year">${g.year ? esc(g.year) : "—"}</td>
|
||||
<td>${review}</td>
|
||||
<td>${modeHours(g)}</td>
|
||||
<td class="t-duration">${g.duration ? fmtDuration(g.duration) : "—"}</td>
|
||||
<td class="t-duration">${duration ? fmtDuration(duration.value, duration.approx) : "—"}</td>
|
||||
<td class="t-genres">${genres}</td>
|
||||
<td class="t-fav">${g.favorite ? "★" : ""}</td>
|
||||
</tr>`;
|
||||
@@ -669,7 +696,9 @@ function renderSavedViews(selected = "") {
|
||||
|
||||
function syncFilterControls() {
|
||||
$("#search").value = state.q;
|
||||
$("#searchNameOnly").checked = !!state.nameOnly;
|
||||
$("#sort").value = state.sort;
|
||||
updateSortDirButton();
|
||||
$("#fStatus").value = state.filters.status;
|
||||
$("#fOwnership").value = state.filters.ownership;
|
||||
$("#fDuration").value = state.filters.duration;
|
||||
@@ -694,6 +723,7 @@ function syncFilterControls() {
|
||||
function applySavedView(view) {
|
||||
const saved = view.filters || {};
|
||||
state.q = view.q || "";
|
||||
state.nameOnly = !!view.nameOnly;
|
||||
state.sort = view.sort || "review";
|
||||
state.dir = view.dir || defaultDir(state.sort);
|
||||
state.filters = {
|
||||
@@ -879,6 +909,7 @@ $("#activityYear").addEventListener("change", () => loadActivity($("#activityYea
|
||||
function filterParams() {
|
||||
const p = new URLSearchParams();
|
||||
if (state.q) p.set("q", state.q);
|
||||
if (state.q && state.nameOnly) p.set("name_only", "1");
|
||||
if (state.filters.status) p.set("status", state.filters.status);
|
||||
state.filters.genres.forEach((value) => p.append("genre", value));
|
||||
state.filters.tags.forEach((value) => p.append("tag", value));
|
||||
@@ -892,6 +923,7 @@ function filterParams() {
|
||||
["minHours", "min_hours"], ["maxHours", "max_hours"],
|
||||
["minYear", "min_year"], ["maxYear", "max_year"],
|
||||
["minReview", "min_review"], ["maxReview", "max_review"],
|
||||
["minDuration", "min_duration"], ["maxDuration", "max_duration"],
|
||||
].forEach(([key, param]) => {
|
||||
if (state.filters[key] !== "") p.set(param, state.filters[key]);
|
||||
});
|
||||
@@ -1032,9 +1064,9 @@ function openMoodEditor(mood = null) {
|
||||
$("#meName").value = mood ? mood.name : "";
|
||||
$("#meName").disabled = !!mood;
|
||||
$("#meDesc").value = mood ? (mood.description || "") : "";
|
||||
$("#meGenres").value = mood ? (mood.genres || []).join(", ") : "";
|
||||
$("#meGenres").value = mood ? (mood.genres_display || mood.genres || []).join(", ") : "";
|
||||
$("#meTags").value = mood
|
||||
? Object.entries(mood.tags || {}).map(([tag, weight]) => `${tag}: ${weight}`).join("\n")
|
||||
? Object.entries(mood.tags_display || mood.tags || {}).map(([tag, weight]) => `${tag}: ${weight}`).join("\n")
|
||||
: "";
|
||||
$("#moodEditor").classList.remove("hidden");
|
||||
$("#meName").focus();
|
||||
@@ -1814,18 +1846,41 @@ async function loadAchievements(appid) {
|
||||
}
|
||||
}
|
||||
|
||||
function setupTagExpansion() {
|
||||
const row = $("#modalTags");
|
||||
const toggle = $("#tagsToggle");
|
||||
if (!row || !toggle) return;
|
||||
const count = row.querySelectorAll(".genre").length;
|
||||
if (count <= 6 || row.scrollHeight <= row.clientHeight + 2) {
|
||||
row.classList.remove("clamped");
|
||||
return;
|
||||
}
|
||||
const label = (collapsed) => collapsed
|
||||
? `Показать все теги (${count})`
|
||||
: "Свернуть теги";
|
||||
toggle.classList.remove("hidden");
|
||||
toggle.setAttribute("aria-expanded", "false");
|
||||
toggle.textContent = label(true);
|
||||
toggle.addEventListener("click", () => {
|
||||
const collapsed = row.classList.toggle("clamped");
|
||||
toggle.setAttribute("aria-expanded", String(!collapsed));
|
||||
toggle.textContent = label(collapsed);
|
||||
});
|
||||
}
|
||||
|
||||
function renderModal(g) {
|
||||
const statusOptions = Object.entries(STATUS_LABEL)
|
||||
.map(([k, v]) => `<option value="${k}" ${k === g.status ? "selected" : ""}>${v}</option>`).join("");
|
||||
const genres = (g.genres || []).map((x) => `<span class="genre">${esc(x)}</span>`).join("");
|
||||
const tags = (g.tags || []).map((x) => `<span class="genre">${esc(x)}</span>`).join("");
|
||||
const duration = durationInfo(g);
|
||||
const meta = [
|
||||
g.year ? `<span><b>${esc(g.year)}</b></span>` : "",
|
||||
g.review != null ? `<span><b>${g.review}%</b> отзывов</span>` : "",
|
||||
g.duration ? `<span title="${g.hltb ? "HowLongToBeat" : "оценка по тегам"}"><b>${fmtDuration(g.duration)}</b></span>` : "",
|
||||
duration ? `<span class="stat" title="${duration.title}"><b>${fmtDuration(duration.value, duration.approx)}</b><span class="stat-hint">длина</span></span>` : "",
|
||||
g.hltb?.complete ? `<span class="muted" title="HLTB: main / main+extra / 100%">HLTB ${Math.round(g.hltb.main || g.duration)} / ${Math.round(g.hltb.complete)} ч</span>` : "",
|
||||
g.metacritic != null ? `<span>MC <b>${g.metacritic}</b></span>` : "",
|
||||
g.hours ? `<span><b>${fmtHours(g.hours)}</b></span>` : "",
|
||||
g.hours ? `<span class="stat" title="Наиграно в Steam"><b>${fmtHours(g.hours)}</b><span class="stat-hint">наиграно</span></span>` : "",
|
||||
g.installed ? `<span class="muted">установлена${g.size_gb ? " · " + g.size_gb + " ГБ" : ""}</span>` : "",
|
||||
g.last_played ? `<span class="muted">последний запуск ${esc(g.last_played)}</span>` : "",
|
||||
].filter(Boolean).join("");
|
||||
@@ -1897,7 +1952,9 @@ function renderModal(g) {
|
||||
<div class="chip-row">${genres}</div>
|
||||
<p class="modal-desc">${esc(shortText)}</p>
|
||||
${about ? `<details class="about-block"><summary>Полное описание</summary><p class="modal-desc about">${esc(about.slice(0, 2400))}${about.length > 2400 ? "…" : ""}</p></details>` : ""}
|
||||
${tags ? `<div class="chip-row">${tags}</div>` : ""}
|
||||
${tags ? `<div class="chip-row tags-row clamped" id="modalTags">${tags}</div>
|
||||
<button class="tags-toggle hidden" id="tagsToggle" type="button"
|
||||
aria-controls="modalTags" aria-expanded="false"></button>` : ""}
|
||||
<div id="achievementsBlock" class="achievements-block hidden"></div>
|
||||
${parentLink}
|
||||
${addons}
|
||||
@@ -1908,6 +1965,7 @@ function renderModal(g) {
|
||||
|
||||
$("#modalCoverBlur").style.backgroundImage = `url("${coverUrl(g.appid)}")`;
|
||||
attachCoverFallback($("#modalCover img"));
|
||||
setupTagExpansion();
|
||||
loadAchievements(g.appid);
|
||||
|
||||
$("#modalClose").addEventListener("click", () => $("#modal").close());
|
||||
@@ -2048,11 +2106,22 @@ $("#search").addEventListener("input", debounce((e) => {
|
||||
state.q = e.target.value.trim();
|
||||
loadGames(true);
|
||||
}, 280));
|
||||
$("#searchNameOnly").addEventListener("change", (e) => {
|
||||
state.nameOnly = e.target.checked;
|
||||
if (state.q) loadGames(true);
|
||||
});
|
||||
|
||||
$("#sort").addEventListener("change", (e) => {
|
||||
state.sort = e.target.value;
|
||||
state.dir = defaultDir(state.sort);
|
||||
saveSort();
|
||||
updateSortDirButton();
|
||||
loadGames(true);
|
||||
});
|
||||
$("#sortDir").addEventListener("click", () => {
|
||||
state.dir = state.dir === "asc" ? "desc" : "asc";
|
||||
saveSort();
|
||||
updateSortDirButton();
|
||||
loadGames(true);
|
||||
});
|
||||
|
||||
@@ -2096,7 +2165,7 @@ $("#saveView").addEventListener("click", () => {
|
||||
const name = (prompt("Название вида:", "") || "").trim();
|
||||
if (!name) return;
|
||||
const views = loadViews();
|
||||
const view = { name, q: state.q, sort: state.sort, dir: state.dir,
|
||||
const view = { name, q: state.q, nameOnly: state.nameOnly, sort: state.sort, dir: state.dir,
|
||||
filters: cloneFilters(state.filters) };
|
||||
const existing = views.findIndex((item) => item.name === name);
|
||||
let selected;
|
||||
@@ -2134,6 +2203,7 @@ renderSavedViews();
|
||||
$("#resetFilters").addEventListener("click", () => {
|
||||
state.filters = defaultFilters();
|
||||
state.q = "";
|
||||
state.nameOnly = false;
|
||||
$("#savedView").value = "";
|
||||
syncFilterControls();
|
||||
loadGames(true);
|
||||
@@ -2157,6 +2227,7 @@ grid.addEventListener("click", (event) => {
|
||||
}
|
||||
$("#sort").value = state.sort;
|
||||
saveSort();
|
||||
updateSortDirButton();
|
||||
loadGames(true);
|
||||
});
|
||||
|
||||
@@ -2634,6 +2705,7 @@ if ("serviceWorker" in navigator) {
|
||||
(async function boot() {
|
||||
loadSort();
|
||||
$("#sort").value = state.sort;
|
||||
updateSortDirButton();
|
||||
await Promise.all([loadMeta(), loadMoods()]);
|
||||
pollJob(true);
|
||||
|
||||
|
||||
+13
-1
@@ -121,7 +121,7 @@ try {
|
||||
<label class="check"><input type="checkbox" id="fUnplayed"> не запускались</label>
|
||||
<label class="check"><input type="checkbox" id="fFavorite"> избранные</label>
|
||||
|
||||
<label class="field">
|
||||
<label class="field" title="Пресет по длительности (HLTB или оценка)">
|
||||
<span>Длина игры</span>
|
||||
<select id="fDuration">
|
||||
<option value="">любая</option>
|
||||
@@ -130,6 +130,13 @@ try {
|
||||
<option value="long">больше 25 ч</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="field" title="Диапазон длительности: HLTB, иначе оценка по жанрам/тегам">
|
||||
<span>Длительность, ч</span>
|
||||
<div class="range-row">
|
||||
<input id="fDurationMin" type="number" min="0" step="1" placeholder="от" data-filter="minDuration" aria-label="Минимальная длительность">
|
||||
<input id="fDurationMax" type="number" min="0" step="1" placeholder="до" data-filter="maxDuration" aria-label="Максимальная длительность">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
@@ -198,6 +205,9 @@ try {
|
||||
</button>
|
||||
<input id="search" type="search" placeholder="Поиск: название, описание, тег…" autocomplete="off"
|
||||
aria-label="Поиск по библиотеке" aria-keyshortcuts="/">
|
||||
<label class="toolbar-check" title="Искать только в названии игры">
|
||||
<input id="searchNameOnly" type="checkbox"> в названии
|
||||
</label>
|
||||
<select id="sort" aria-label="Сортировка">
|
||||
<option value="name">по названию</option>
|
||||
<option value="hours">по времени</option>
|
||||
@@ -208,6 +218,8 @@ try {
|
||||
<option value="genre">по жанру</option>
|
||||
<option value="added">по добавлению</option>
|
||||
</select>
|
||||
<button id="sortDir" class="ghost toolbar-select" type="button"
|
||||
title="По убыванию" aria-label="Направление сортировки">↓</button>
|
||||
<button id="layoutToggle" class="ghost toolbar-select" type="button"
|
||||
aria-pressed="false" title="Компактный список" aria-keyshortcuts="g">список</button>
|
||||
<button id="exportLibrary" class="ghost toolbar-select" type="button"
|
||||
|
||||
@@ -465,6 +465,17 @@ summary:focus-visible,
|
||||
.toolbar input { flex: 1; }
|
||||
.toolbar select { width: auto; min-width: 150px; }
|
||||
.toolbar .ghost { flex: 0 0 auto; }
|
||||
#sortDir { min-width: 34px; padding-left: 8px; padding-right: 8px; }
|
||||
.toolbar-check {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
.toolbar-check input { flex: 0 0 auto; width: auto; }
|
||||
.count { color: var(--muted); font-size: 13px; white-space: nowrap; }
|
||||
|
||||
.undo-bar {
|
||||
@@ -774,6 +785,8 @@ html[data-theme="light"] .game-table tbody tr:hover { background: rgba(23, 32, 5
|
||||
overflow: hidden;
|
||||
}
|
||||
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); }
|
||||
.card-meta .stat, .modal-meta .stat { display: inline-flex; align-items: baseline; gap: 3px; }
|
||||
.stat-hint { font-size: 9.5px; color: var(--muted); opacity: .85; }
|
||||
.card-meta .dot::before { content: "·"; margin-right: 6px; }
|
||||
.card-genres { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.genre {
|
||||
@@ -1471,6 +1484,28 @@ button.addon:hover { border-color: var(--accent); color: var(--text); }
|
||||
|
||||
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
|
||||
|
||||
.tags-row { position: relative; }
|
||||
.tags-row.clamped { max-height: 46px; overflow: hidden; padding-bottom: 0; }
|
||||
.tags-row.clamped::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0; right: 0; bottom: 0;
|
||||
height: 22px;
|
||||
background: linear-gradient(to bottom, transparent, var(--panel));
|
||||
pointer-events: none;
|
||||
}
|
||||
.tags-toggle {
|
||||
margin: -10px 0 16px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: var(--accent-2);
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tags-toggle:hover { text-decoration: underline; }
|
||||
|
||||
.personal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in new issue
Block a user