Profile downloader: favorites list in the web UI; mark story filenames
- 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
This commit is contained in:
1 parent
d12483d53c
commit
3dc4b0757f
5 files changed
+99
-9
No files matched your search
@@ -38,6 +38,10 @@
|
||||
.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; }
|
||||
@@ -107,6 +111,7 @@
|
||||
<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>
|
||||
|
||||
@@ -185,8 +190,10 @@ function requestBody(extra) {
|
||||
$("form").addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const profile = $("profile").value.trim();
|
||||
if (!profile) return;
|
||||
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 }));
|
||||
@@ -207,9 +214,43 @@ $("form").addEventListener("submit", async (event) => {
|
||||
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) {
|
||||
@@ -413,6 +454,7 @@ function showJob() {
|
||||
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 */ }
|
||||
|
||||
Reference in new issue
Block a user