This commit is contained in:
1 parent
a3c25c943c
commit
db3e6e4f94
15 files changed
+133
-22
No files matched your search
+68
-5
@@ -37,6 +37,7 @@ const state = {
|
||||
selectionMode: false,
|
||||
selected: new Set(),
|
||||
recommendContext: null,
|
||||
lastReco: null,
|
||||
};
|
||||
|
||||
const $ = (sel) => document.querySelector(sel);
|
||||
@@ -235,7 +236,7 @@ function fmtDuration(h) {
|
||||
}
|
||||
|
||||
function defaultDir(field) {
|
||||
return ["hours", "review", "year", "added"].includes(field) ? "desc" : "asc";
|
||||
return ["hours", "review", "year", "favorite", "added"].includes(field) ? "desc" : "asc";
|
||||
}
|
||||
|
||||
function loadSort() {
|
||||
@@ -337,8 +338,8 @@ const TABLE_COLS = [
|
||||
{ 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: "genres", label: "Жанры", width: 180, cls: "t-genres" },
|
||||
{ key: "fav", label: "★", width: 30, cls: "t-fav" },
|
||||
{ key: "genres", label: "Жанры", width: 180, cls: "t-genres", sort: "genre" },
|
||||
{ key: "fav", label: "★", width: 30, cls: "t-fav", sort: "favorite" },
|
||||
];
|
||||
|
||||
function tableHead() {
|
||||
@@ -635,7 +636,9 @@ async function loadMeta() {
|
||||
let coldDismissed = false;
|
||||
try { coldDismissed = localStorage.getItem(COLD_START_KEY) === "1"; } catch (_) {}
|
||||
const signals = Number(meta.signals || 0);
|
||||
$("#coldStart").classList.toggle("hidden", coldDismissed || signals >= 3);
|
||||
const coldAvailable = signals < 3;
|
||||
$("#coldStart").classList.toggle("hidden", coldDismissed || !coldAvailable);
|
||||
$("#coldStartShow").classList.toggle("hidden", !(coldDismissed && coldAvailable));
|
||||
}
|
||||
|
||||
/* ---------- saved views ---------- */
|
||||
@@ -889,6 +892,13 @@ document.querySelectorAll("#coldStart .chips").forEach((group) => {
|
||||
$("#coldStartClose").addEventListener("click", () => {
|
||||
try { localStorage.setItem(COLD_START_KEY, "1"); } catch (_) {}
|
||||
$("#coldStart").classList.add("hidden");
|
||||
$("#coldStartShow").classList.remove("hidden");
|
||||
});
|
||||
|
||||
$("#coldStartShow").addEventListener("click", () => {
|
||||
try { localStorage.removeItem(COLD_START_KEY); } catch (_) {}
|
||||
$("#coldStartShow").classList.add("hidden");
|
||||
$("#coldStart").classList.remove("hidden");
|
||||
});
|
||||
|
||||
$("#csGo").addEventListener("click", () => {
|
||||
@@ -911,6 +921,8 @@ async function runRecommend(scroll = true) {
|
||||
}
|
||||
const btn = $("#recommendBtn");
|
||||
btn.disabled = true;
|
||||
state.lastReco = null;
|
||||
$("#recoActions").classList.add("hidden");
|
||||
recoGrid.innerHTML = skeletons(8);
|
||||
try {
|
||||
const body = {
|
||||
@@ -933,7 +945,9 @@ async function runRecommend(scroll = true) {
|
||||
<div>${data.results.length} совпадений</div>`;
|
||||
recoGrid.innerHTML = data.results.length
|
||||
? data.results.map((g) => cardHtml(g, "reco")).join("")
|
||||
: '<div class="empty">ничего не нашлось — попробуй другие слова</div>';
|
||||
: '<div class="empty">ничего не подошло — попробуй другие слова</div>';
|
||||
state.lastReco = { mood, results: data.results };
|
||||
$("#recoActions").classList.toggle("hidden", !data.results.length);
|
||||
bindCards(recoGrid);
|
||||
scheduleDescriptions();
|
||||
if (scroll) $("#recoSummary").scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
@@ -944,6 +958,55 @@ async function runRecommend(scroll = true) {
|
||||
}
|
||||
}
|
||||
|
||||
function downloadText(filename, text, content_type) {
|
||||
const blob = new Blob([text], { type: content_type });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
|
||||
function exportCell(value) {
|
||||
const text = String(value ?? "");
|
||||
return /[",\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
||||
}
|
||||
|
||||
function exportRecommendations(format) {
|
||||
if (!state.lastReco) {
|
||||
toast("Сначала получите рекомендации");
|
||||
return;
|
||||
}
|
||||
const stamp = new Date().toISOString().slice(0, 19).replace(/[:T]/g, "-");
|
||||
const { mood, results } = state.lastReco;
|
||||
const safeResults = results.map(({ notes, ...rest }) => rest);
|
||||
if (format === "json") {
|
||||
downloadText(`steambase-reco-${stamp}.json`,
|
||||
JSON.stringify({ generated_at: new Date().toISOString(), mood,
|
||||
results: safeResults }, null, 2),
|
||||
"application/json");
|
||||
return;
|
||||
}
|
||||
const columns = ["appid", "name", "score", "review", "metacritic", "hours", "duration",
|
||||
"status", "favorite", "installed", "matched", "reasons", "genres", "release"];
|
||||
const lines = [columns.join(",")];
|
||||
for (const game of results) {
|
||||
lines.push([
|
||||
game.appid, game.name, game.score, game.review, game.metacritic, game.hours,
|
||||
game.duration, game.status, game.favorite ? 1 : 0, game.installed ? 1 : 0,
|
||||
(game.matched || []).join("|"), (game.reasons || []).join("|"),
|
||||
(game.genres || []).join("|"), game.release,
|
||||
].map(exportCell).join(","));
|
||||
}
|
||||
downloadText(`steambase-reco-${stamp}.csv`, lines.join("\n"), "text/csv;charset=utf-8");
|
||||
}
|
||||
|
||||
$("#exportRecoJson").addEventListener("click", () => exportRecommendations("json"));
|
||||
$("#exportRecoCsv").addEventListener("click", () => exportRecommendations("csv"));
|
||||
|
||||
recoGrid.addEventListener("click", async (event) => {
|
||||
const button = event.target instanceof Element && event.target.closest("button[data-verdict]");
|
||||
if (!button) return;
|
||||
|
||||
Reference in new issue
Block a user