- favorites.txt (git-ignored): profiles listed there show as buttons in the web UI that load the profile with one click - stories are saved as '<date> <id> story.<ext>' so they stand apart from posts
466 lines
22 KiB
HTML
466 lines
22 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="referrer" content="no-referrer">
|
|
<title>Profile Downloader</title>
|
|
<style>
|
|
:root {
|
|
--bg: #f6f6f4; --surface: #ffffff; --surface-2: #efefec; --text: #1c1c1a; --muted: #6b6b66;
|
|
--border: #dcdcd6; --accent: #e5304f; --accent-text: #ffffff; --ok: #1f8a4c; --warn: #b26a00; --bad: #c62828;
|
|
--ring: rgba(229, 48, 79, .35); --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
|
|
}
|
|
@media (prefers-color-scheme: dark) {
|
|
:root {
|
|
--bg: #121212; --surface: #1c1c1c; --surface-2: #262626; --text: #ececea; --muted: #9a9a94;
|
|
--border: #333331; --accent: #ff4d6a; --accent-text: #ffffff; --ok: #4cc07f; --warn: #f0a63a; --bad: #ff6b6b;
|
|
--ring: rgba(255, 77, 106, .4); --shadow: 0 1px 2px rgba(0,0,0,.4);
|
|
}
|
|
}
|
|
* { box-sizing: border-box; }
|
|
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 140px; }
|
|
h1 { font-size: 20px; margin: 0 0 14px; letter-spacing: -.01em; }
|
|
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; display: flex; gap: 8px; align-items: center; }
|
|
h2 .count { background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 0 8px; font-size: 12px; letter-spacing: 0; }
|
|
button, input { font: inherit; color: inherit; }
|
|
button { border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; }
|
|
button:hover:not(:disabled) { background: var(--surface-2); }
|
|
button:disabled { opacity: .45; cursor: default; }
|
|
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
|
|
button.primary:hover:not(:disabled) { filter: brightness(1.05); background: var(--accent); }
|
|
button:focus-visible, input:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
|
|
|
|
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
|
|
.search { display: flex; gap: 8px; }
|
|
.search input { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
|
|
.options { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 10px; color: var(--muted); align-items: center; }
|
|
.options label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
|
|
.options input[type=text] { width: min(420px, 100%); padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
|
|
.favorites { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
|
|
.favorites .label { color: var(--muted); margin-right: 4px; }
|
|
.favorites button { padding: 4px 11px; border-radius: 999px; font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
.favorites button[aria-current=true] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
|
|
.status { margin-top: 10px; color: var(--muted); min-height: 1.4em; }
|
|
.status.error { color: var(--bad); }
|
|
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
|
|
.profile { display: flex; gap: 12px; align-items: center; margin-top: 16px; }
|
|
.profile img { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); object-fit: cover; }
|
|
.profile .name { font-weight: 600; font-size: 16px; }
|
|
.profile .meta { color: var(--muted); }
|
|
|
|
.toolbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0; margin-top: 8px; background: var(--bg); border-bottom: 1px solid var(--border); }
|
|
.toolbar .spacer { flex: 1; }
|
|
.toolbar .selected { color: var(--muted); }
|
|
.chips { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
|
|
.chips button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
|
|
.chips button:last-child { border-right: 0; }
|
|
.chips button[aria-pressed=true] { background: var(--surface-2); font-weight: 600; }
|
|
|
|
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
|
|
.card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; user-select: none; transition: box-shadow .12s, border-color .12s; }
|
|
.card:hover { border-color: var(--muted); }
|
|
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--ring); }
|
|
.card.story { border-style: dashed; }
|
|
.thumb { position: relative; aspect-ratio: 9 / 13; background: var(--surface-2); }
|
|
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
.thumb .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
|
|
.check { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 6px; background: rgba(0,0,0,.45); border: 2px solid #fff; display: grid; place-items: center; color: #fff; font-size: 14px; }
|
|
.card.selected .check { background: var(--accent); border-color: var(--accent); }
|
|
.card.selected .check::after { content: "✓"; font-weight: 700; }
|
|
.badge { position: absolute; left: 8px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: rgba(0,0,0,.6); color: #fff; }
|
|
.badge.type { bottom: 8px; }
|
|
.badge.state { top: 8px; }
|
|
.badge.downloaded, .badge.done { background: var(--ok); }
|
|
.badge.failed { background: var(--bad); }
|
|
.badge.downloading, .badge.waiting, .badge.queued { background: var(--warn); }
|
|
.info { padding: 7px 9px 9px; }
|
|
.info .date { font-size: 12px; color: var(--muted); }
|
|
.info .caption { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; word-break: break-word; }
|
|
.empty { color: var(--muted); padding: 6px 0 4px; }
|
|
|
|
.progress { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(0,0,0,.08); }
|
|
.progress .inner { max-width: 1280px; margin: 0 auto; padding: 12px 16px; display: grid; gap: 8px; }
|
|
.progress .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
|
|
.progress .row .text { flex: 1; min-width: 200px; }
|
|
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
|
|
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
|
|
.failures { max-height: 120px; overflow: auto; font-size: 12px; color: var(--bad); margin: 0; padding-left: 18px; }
|
|
.hidden { display: none !important; }
|
|
@media (max-width: 560px) {
|
|
.grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
|
|
.search { flex-direction: column; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<h1>Profile Downloader</h1>
|
|
|
|
<form class="panel" id="form" autocomplete="off">
|
|
<div class="search">
|
|
<input id="profile" placeholder="Username, @username, profile URL, post link, or secUid" required>
|
|
<button class="primary" id="loadBtn" type="submit">Load profile</button>
|
|
</div>
|
|
<div class="options">
|
|
<label><input type="checkbox" id="useCookies" checked> Use cookies</label>
|
|
<input type="text" id="cookies" placeholder="Path to cookies.txt (optional)">
|
|
<label><input type="checkbox" id="stories" checked> Include stories</label>
|
|
<label><input type="checkbox" id="refresh"> Fetch fresh list (ignore cache)</label>
|
|
</div>
|
|
<div class="favorites hidden" id="favorites" role="group" aria-label="Favorites"><span class="label">Favorites</span></div>
|
|
<div class="status" id="status"></div>
|
|
</form>
|
|
|
|
<section id="results" class="hidden">
|
|
<div class="profile">
|
|
<img id="avatar" alt="">
|
|
<div>
|
|
<div class="name" id="nickname"></div>
|
|
<div class="meta" id="profileMeta"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="toolbar">
|
|
<button type="button" id="selectAll">Select all</button>
|
|
<button type="button" id="selectNone">Deselect all</button>
|
|
<button type="button" id="selectNew">Select not downloaded</button>
|
|
<div class="chips" role="group" aria-label="Filter">
|
|
<button type="button" data-filter="all" aria-pressed="true">All</button>
|
|
<button type="button" data-filter="video" aria-pressed="false">Videos</button>
|
|
<button type="button" data-filter="photo" aria-pressed="false">Photos</button>
|
|
<button type="button" data-filter="new" aria-pressed="false">Not downloaded</button>
|
|
</div>
|
|
<span class="spacer"></span>
|
|
<span class="selected" id="selectedCount">0 selected</span>
|
|
<button type="button" class="primary" id="downloadBtn" disabled>Download selected</button>
|
|
</div>
|
|
|
|
<h2>Stories <span class="count" id="storyCount">0</span></h2>
|
|
<div class="grid" id="storyGrid"></div>
|
|
<div class="empty hidden" id="storyEmpty">No active stories.</div>
|
|
|
|
<h2>Posts <span class="count" id="postCount">0</span></h2>
|
|
<div class="grid" id="postGrid"></div>
|
|
<div class="empty hidden" id="postEmpty">No posts match this filter.</div>
|
|
</section>
|
|
</main>
|
|
|
|
<div class="progress hidden" id="progress">
|
|
<div class="inner">
|
|
<div class="row">
|
|
<div class="text" id="progressText"></div>
|
|
<button type="button" id="stopBtn">Stop</button>
|
|
<button type="button" id="closeBtn" class="hidden">Close</button>
|
|
</div>
|
|
<div class="bar"><div id="progressBar"></div></div>
|
|
<ol class="failures hidden" id="failures"></ol>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const $ = (id) => document.getElementById(id);
|
|
const state = { listing: null, selected: new Set(), filter: "all", lastClicked: null, job: null, polling: null };
|
|
const STATUS_LABEL = { downloaded: "Downloaded", failed: "Failed", done: "Downloaded", downloading: "Downloading…", waiting: "Waiting…", queued: "Queued" };
|
|
|
|
async function api(path, body) {
|
|
const options = body === undefined ? {} : { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) };
|
|
const res = await fetch(path, options);
|
|
const data = await res.json().catch(() => ({}));
|
|
if (!res.ok) throw new Error(data.error || `Request failed (${res.status})`);
|
|
return data;
|
|
}
|
|
|
|
function setStatus(text, kind) {
|
|
const el = $("status");
|
|
el.className = "status" + (kind === "error" ? " error" : "");
|
|
el.innerHTML = "";
|
|
if (kind === "busy") el.insertAdjacentHTML("afterbegin", '<span class="spinner"></span>');
|
|
el.append(text || "");
|
|
}
|
|
|
|
function requestBody(extra) {
|
|
return Object.assign({ use_cookies: $("useCookies").checked, cookies: $("cookies").value.trim() }, extra);
|
|
}
|
|
|
|
// --- Loading ---
|
|
$("form").addEventListener("submit", async (event) => {
|
|
event.preventDefault();
|
|
const profile = $("profile").value.trim();
|
|
if (!profile || $("loadBtn").disabled) return;
|
|
$("loadBtn").disabled = true;
|
|
setFavoritesDisabled(true);
|
|
markFavorite(profile);
|
|
setStatus("Loading profile…", "busy");
|
|
try {
|
|
let task = await api("/api/profile", requestBody({ profile, refresh: $("refresh").checked, stories: $("stories").checked }));
|
|
while (task.state === "running") {
|
|
setStatus(task.message, "busy");
|
|
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
task = await api("/api/profile/status");
|
|
}
|
|
if (task.state === "error") throw new Error(task.message);
|
|
const listing = task.result;
|
|
state.listing = listing;
|
|
state.selected.clear();
|
|
$("refresh").checked = false;
|
|
const age = listing.cache_age > 60 ? ` · list cached ${Math.round(listing.cache_age / 60)} min ago` : "";
|
|
setStatus(`Loaded @${listing.profile.username}${age}${listing.stories_note ? " · " + listing.stories_note : ""}`);
|
|
render();
|
|
} catch (err) {
|
|
setStatus(err.message, "error");
|
|
} finally {
|
|
$("loadBtn").disabled = false;
|
|
setFavoritesDisabled(false);
|
|
}
|
|
});
|
|
|
|
// --- Favorites (favorites.txt) ---
|
|
function favoriteLabel(entry) {
|
|
if (/^MS4wLjABAAAA/.test(entry)) return entry.slice(0, 18) + "…"; // secUid
|
|
const user = entry.match(/tiktok\.com\/@([\w.-]+)/i);
|
|
if (user) return "@" + user[1];
|
|
if (/^https?:/i.test(entry)) return entry.replace(/^https?:\/\/(www\.)?/i, "");
|
|
if (/^\d+$/.test(entry)) return entry; // numeric ID
|
|
return "@" + entry.replace(/^@/, "");
|
|
}
|
|
|
|
function renderFavorites(entries) {
|
|
const box = $("favorites");
|
|
box.querySelectorAll("button").forEach((b) => b.remove());
|
|
for (const entry of entries) {
|
|
const button = document.createElement("button");
|
|
button.type = "button";
|
|
button.textContent = favoriteLabel(entry);
|
|
button.title = entry;
|
|
button.dataset.entry = entry;
|
|
button.onclick = () => { $("profile").value = entry; $("form").requestSubmit(); };
|
|
box.append(button);
|
|
}
|
|
box.classList.toggle("hidden", entries.length === 0);
|
|
}
|
|
|
|
function setFavoritesDisabled(disabled) {
|
|
$("favorites").querySelectorAll("button").forEach((b) => { b.disabled = disabled; });
|
|
}
|
|
|
|
function markFavorite(profile) {
|
|
$("favorites").querySelectorAll("button").forEach((b) => b.setAttribute("aria-current", b.dataset.entry === profile));
|
|
}
|
|
|
|
// --- Rendering ---
|
|
function allItems() { return state.listing ? [...state.listing.stories, ...state.listing.posts] : []; }
|
|
function visible(item) {
|
|
const f = state.filter;
|
|
return f === "all" || (f === "new" ? item.status !== "downloaded" : item.type === f);
|
|
}
|
|
function visibleItems() { return allItems().filter(visible); }
|
|
|
|
function formatDuration(seconds) {
|
|
return seconds ? `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}` : "";
|
|
}
|
|
|
|
function card(item) {
|
|
const el = document.createElement("div");
|
|
el.className = "card" + (item.kind === "story" ? " story" : "");
|
|
el.dataset.id = item.id;
|
|
el.tabIndex = 0;
|
|
el.setAttribute("role", "checkbox");
|
|
|
|
const thumb = document.createElement("div");
|
|
thumb.className = "thumb";
|
|
if (item.thumb) {
|
|
const img = document.createElement("img");
|
|
img.loading = "lazy"; img.referrerPolicy = "no-referrer"; img.alt = ""; img.src = item.thumb;
|
|
img.onerror = () => { img.remove(); thumb.insertAdjacentHTML("afterbegin", '<div class="noimg">No preview</div>'); };
|
|
thumb.append(img);
|
|
} else {
|
|
thumb.innerHTML = '<div class="noimg">No preview</div>';
|
|
}
|
|
const type = document.createElement("span");
|
|
type.className = "badge type";
|
|
type.textContent = item.type === "photo" ? `Photos · ${item.images}` : `Video ${formatDuration(item.duration)}`.trim();
|
|
const status = document.createElement("span");
|
|
status.className = "badge state";
|
|
const check = document.createElement("span");
|
|
check.className = "check";
|
|
thumb.append(type, status, check);
|
|
|
|
const info = document.createElement("div");
|
|
info.className = "info";
|
|
const date = document.createElement("div");
|
|
date.className = "date";
|
|
date.textContent = (item.kind === "story" ? "Story · " : "") + item.date;
|
|
const caption = document.createElement("div");
|
|
caption.className = "caption";
|
|
caption.textContent = item.caption || "—";
|
|
caption.title = item.caption;
|
|
info.append(date, caption);
|
|
|
|
el.append(thumb, info);
|
|
el.addEventListener("click", (event) => toggle(item.id, event.shiftKey));
|
|
el.addEventListener("keydown", (event) => { if (event.key === " " || event.key === "Enter") { event.preventDefault(); toggle(item.id, event.shiftKey); } });
|
|
updateCard(el, item);
|
|
return el;
|
|
}
|
|
|
|
function currentStatus(item) {
|
|
const jobItem = state.job && state.job.items.find((i) => i.id === item.id);
|
|
if (jobItem && jobItem.status !== "skipped") return jobItem.status === "done" ? "downloaded" : jobItem.status;
|
|
return item.status;
|
|
}
|
|
|
|
function updateCard(el, item) {
|
|
const status = currentStatus(item);
|
|
const badge = el.querySelector(".badge.state");
|
|
badge.className = "badge state " + status;
|
|
badge.textContent = STATUS_LABEL[status] || "";
|
|
badge.classList.toggle("hidden", !STATUS_LABEL[status]);
|
|
const jobItem = state.job && state.job.items.find((i) => i.id === item.id);
|
|
badge.title = jobItem && jobItem.error ? jobItem.error : "";
|
|
const selected = state.selected.has(item.id);
|
|
el.classList.toggle("selected", selected);
|
|
el.setAttribute("aria-checked", selected);
|
|
}
|
|
|
|
function render() {
|
|
const listing = state.listing;
|
|
$("results").classList.remove("hidden");
|
|
$("avatar").src = listing.profile.avatar || "";
|
|
$("nickname").textContent = listing.profile.nickname || listing.profile.username;
|
|
const items = allItems();
|
|
const done = items.filter((i) => i.status === "downloaded").length;
|
|
$("profileMeta").textContent = `@${listing.profile.username} · ${listing.posts.length} posts · ${listing.stories.length} stories · ${done} downloaded · ${items.length - done} not downloaded`;
|
|
|
|
for (const [list, grid, count, empty] of [[listing.stories, "storyGrid", "storyCount", "storyEmpty"], [listing.posts, "postGrid", "postCount", "postEmpty"]]) {
|
|
const shown = list.filter(visible);
|
|
$(grid).replaceChildren(...shown.map(card));
|
|
$(count).textContent = shown.length === list.length ? list.length : `${shown.length} / ${list.length}`;
|
|
$(empty).classList.toggle("hidden", shown.length > 0);
|
|
}
|
|
$("storyEmpty").textContent = listing.stories.length ? "No stories match this filter." : (listing.stories_note || "No active stories.");
|
|
updateSelection();
|
|
}
|
|
|
|
function refreshCards() {
|
|
const byId = new Map(allItems().map((i) => [i.id, i]));
|
|
document.querySelectorAll(".card").forEach((el) => updateCard(el, byId.get(el.dataset.id)));
|
|
}
|
|
|
|
// --- Selection ---
|
|
function toggle(id, range) {
|
|
const order = visibleItems().map((i) => i.id);
|
|
if (range && state.lastClicked && order.includes(state.lastClicked)) {
|
|
const [a, b] = [order.indexOf(state.lastClicked), order.indexOf(id)].sort((x, y) => x - y);
|
|
const select = !state.selected.has(id);
|
|
order.slice(a, b + 1).forEach((i) => select ? state.selected.add(i) : state.selected.delete(i));
|
|
} else {
|
|
state.selected.has(id) ? state.selected.delete(id) : state.selected.add(id);
|
|
}
|
|
state.lastClicked = id;
|
|
updateSelection();
|
|
}
|
|
|
|
function updateSelection() {
|
|
refreshCards();
|
|
const n = state.selected.size;
|
|
$("selectedCount").textContent = `${n} selected`;
|
|
$("downloadBtn").disabled = n === 0 || isRunning();
|
|
$("downloadBtn").textContent = n ? `Download ${n} selected` : "Download selected";
|
|
}
|
|
|
|
$("selectAll").onclick = () => { visibleItems().forEach((i) => state.selected.add(i.id)); updateSelection(); };
|
|
$("selectNone").onclick = () => { state.selected.clear(); updateSelection(); };
|
|
$("selectNew").onclick = () => {
|
|
state.selected.clear();
|
|
visibleItems().filter((i) => currentStatus(i) !== "downloaded").forEach((i) => state.selected.add(i.id));
|
|
updateSelection();
|
|
};
|
|
document.querySelectorAll(".chips button").forEach((button) => {
|
|
button.onclick = () => {
|
|
state.filter = button.dataset.filter;
|
|
document.querySelectorAll(".chips button").forEach((b) => b.setAttribute("aria-pressed", b === button));
|
|
render();
|
|
};
|
|
});
|
|
|
|
// --- Downloading ---
|
|
function isRunning() { return state.job && ["running", "stopping"].includes(state.job.state); }
|
|
|
|
$("downloadBtn").onclick = async () => {
|
|
const order = allItems().map((i) => i.id).filter((id) => state.selected.has(id));
|
|
try {
|
|
state.job = await api("/api/download", requestBody({ username: state.listing.profile.username, ids: order }));
|
|
showJob();
|
|
poll();
|
|
} catch (err) {
|
|
setStatus(err.message, "error");
|
|
}
|
|
};
|
|
|
|
$("stopBtn").onclick = async () => { state.job = await api("/api/job/stop", {}); showJob(); };
|
|
$("closeBtn").onclick = () => $("progress").classList.add("hidden");
|
|
|
|
function poll() {
|
|
clearInterval(state.polling);
|
|
state.polling = setInterval(async () => {
|
|
try { state.job = await api("/api/job"); } catch { return; }
|
|
showJob();
|
|
if (!isRunning()) {
|
|
clearInterval(state.polling);
|
|
// Fold the results into the listing so badges stay after closing the panel
|
|
for (const jobItem of state.job.items) {
|
|
const item = allItems().find((i) => i.id === jobItem.id);
|
|
if (item && jobItem.status === "done") { item.status = "downloaded"; state.selected.delete(item.id); }
|
|
if (item && jobItem.status === "failed") item.status = "failed";
|
|
}
|
|
render();
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
function showJob() {
|
|
const job = state.job;
|
|
if (!job) return;
|
|
$("progress").classList.remove("hidden");
|
|
const c = job.counts || {};
|
|
const finished = (c.done || 0) + (c.failed || 0) + (c.skipped || 0);
|
|
const current = job.items.find((i) => i.status === "downloading" || i.status === "waiting");
|
|
let text = `${c.done || 0} of ${job.total} downloaded` + (c.failed ? ` · ${c.failed} failed` : "");
|
|
if (current) text += ` · ${current.status === "waiting" ? current.error : "downloading " + (current.kind === "story" ? "story " : "post ") + current.id}`;
|
|
if (job.state === "stopping") text += " · stopping after this post…";
|
|
if (!isRunning()) text = job.message;
|
|
$("progressText").textContent = text;
|
|
$("progressBar").style.width = `${job.total ? (finished / job.total) * 100 : 0}%`;
|
|
$("stopBtn").classList.toggle("hidden", !isRunning());
|
|
$("stopBtn").disabled = job.state === "stopping";
|
|
$("closeBtn").classList.toggle("hidden", isRunning());
|
|
|
|
const failed = job.items.filter((i) => i.status === "failed");
|
|
$("failures").replaceChildren(...failed.map((i) => {
|
|
const li = document.createElement("li");
|
|
li.textContent = `${i.id}: ${i.error}`;
|
|
return li;
|
|
}));
|
|
$("failures").classList.toggle("hidden", failed.length === 0);
|
|
updateSelection();
|
|
}
|
|
|
|
// --- Start-up ---
|
|
(async () => {
|
|
try {
|
|
const config = await api("/api/config");
|
|
$("cookies").placeholder = config.default_cookies ? `Default: ${config.default_cookies}` : "Path to cookies.txt (optional)";
|
|
renderFavorites((await api("/api/favorites")).favorites);
|
|
const job = await api("/api/job");
|
|
if (job) { state.job = job; showJob(); if (isRunning()) poll(); }
|
|
} catch { /* server not ready yet */ }
|
|
$("profile").focus();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|