feat: estimate game duration from genres and tags
CI / test (push) Successful in 15s

This commit is contained in:
strsv committed 2026-11-06 17:21:21 +03:00
1 parent b65c8c39fe
commit b2ab347129
18 files changed
+166 -25

No files matched your search

+12 -1
View File
@@ -15,7 +15,8 @@ const LAYOUT_KEY = "sb.layout";
function defaultFilters() {
return {
status: "", genres: [], tags: [], installed: false, unplayed: false, favorite: false,
minHours: "", maxHours: "", minYear: "", maxYear: "", minReview: "", maxReview: "",
duration: "", minHours: "", maxHours: "", minYear: "", maxYear: "",
minReview: "", maxReview: "",
};
}
@@ -220,6 +221,11 @@ function fmtHours(h) {
return `${h >= 100 ? Math.round(h) : h.toFixed(1).replace(".0", "")} ч`;
}
function fmtDuration(h) {
if (!h) return "";
return `≈${h >= 10 ? Math.round(h) : h.toFixed(1).replace(".0", "")} ч`;
}
function initials(name) {
return name.split(/\s+/).slice(0, 2).map((w) => w[0] || "").join("").toUpperCase();
}
@@ -241,6 +247,7 @@ function cardHtml(g, mode = "library") {
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>');
const desc = g.description
@@ -477,6 +484,7 @@ function syncFilterControls() {
$("#search").value = state.q;
$("#sort").value = state.sort;
$("#fStatus").value = state.filters.status;
$("#fDuration").value = state.filters.duration;
$("#fInstalled").checked = !!state.filters.installed;
$("#fUnplayed").checked = !!state.filters.unplayed;
$("#fFavorite").checked = !!state.filters.favorite;
@@ -568,6 +576,7 @@ function filterParams() {
if (state.filters.installed) p.set("installed", "1");
if (state.filters.unplayed) p.set("unplayed", "1");
if (state.filters.favorite) p.set("favorite", "1");
if (state.filters.duration) p.set("duration", state.filters.duration);
[
["minHours", "min_hours"], ["maxHours", "max_hours"],
["minYear", "min_year"], ["maxYear", "max_year"],
@@ -748,6 +757,7 @@ function renderModal(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="оценка по тегам"><b>${fmtDuration(g.duration)}</b></span>` : "",
g.metacritic != null ? `<span>MC <b>${g.metacritic}</b></span>` : "",
g.hours ? `<span><b>${fmtHours(g.hours)}</b></span>` : "",
g.installed ? `<span class="muted">установлена${g.size_gb ? " · " + g.size_gb + " ГБ" : ""}</span>` : "",
@@ -885,6 +895,7 @@ $("#sort").addEventListener("change", (e) => {
});
$("#fStatus").addEventListener("change", (e) => { state.filters.status = e.target.value; loadGames(true); });
$("#fDuration").addEventListener("change", (e) => { state.filters.duration = e.target.value; loadGames(true); });
let rangeTimer = null;
document.querySelectorAll("[data-filter]").forEach((input) => {
input.addEventListener("input", (e) => {
+11
View File
@@ -105,6 +105,16 @@ try {
<label class="check"><input type="checkbox" id="fUnplayed"> не запускались</label>
<label class="check"><input type="checkbox" id="fFavorite"> избранные</label>
<label class="field">
<span>Длина игры</span>
<select id="fDuration">
<option value="">любая</option>
<option value="short">до 8 ч</option>
<option value="medium">8–25 ч</option>
<option value="long">больше 25 ч</option>
</select>
</label>
<div class="field">
<span>Часы</span>
<div class="range-row">
@@ -193,6 +203,7 @@ try {
<option value="hours">по времени</option>
<option value="review" selected>по отзывам</option>
<option value="year">по году</option>
<option value="duration">по длительности</option>
<option value="added">по добавлению</option>
</select>
<button id="layoutToggle" class="ghost toolbar-select" type="button"