diff options
| author | Adam Mathes <adam@adammathes.com> | 2026-02-15 21:48:57 -0800 |
|---|---|---|
| committer | Adam Mathes <adam@adammathes.com> | 2026-02-15 21:48:57 -0800 |
| commit | 657faf3acd7755d6b84a87e0e363729d95930258 (patch) | |
| tree | 0691a677c3b6e8827d52a9a536f9ee9a6cbdcf80 | |
| parent | 371e474217b5ade280e2d9b3893b1893be507eb1 (diff) | |
| download | neko-657faf3acd7755d6b84a87e0e363729d95930258.tar.gz neko-657faf3acd7755d6b84a87e0e363729d95930258.tar.bz2 neko-657faf3acd7755d6b84a87e0e363729d95930258.zip | |
Vanilla JS (v3): Fix mobile horizontal scroll, simplify logo to 🐱 emoji, implement feed deselect, and complete Settings (Add Feed, Export/Import OPML)
| -rw-r--r-- | frontend-vanilla/src/main.ts | 132 | ||||
| -rw-r--r-- | frontend-vanilla/src/style.css | 64 | ||||
| -rw-r--r-- | web/dist/v3/assets/index-BmLjwl8J.js | 128 | ||||
| -rw-r--r-- | web/dist/v3/assets/index-CJ8IAAIK.css | 1 | ||||
| -rw-r--r-- | web/dist/v3/assets/index-Cqbn4jqh.css | 1 | ||||
| -rw-r--r-- | web/dist/v3/assets/index-IyL2W0f_.js | 105 | ||||
| -rw-r--r-- | web/dist/v3/index.html | 4 |
7 files changed, 302 insertions, 133 deletions
diff --git a/frontend-vanilla/src/main.ts b/frontend-vanilla/src/main.ts index 3553ea7..f545285 100644 --- a/frontend-vanilla/src/main.ts +++ b/frontend-vanilla/src/main.ts @@ -30,7 +30,7 @@ export function renderLayout() { <div class="sidebar-backdrop" id="sidebar-backdrop"></div> <aside class="sidebar" id="sidebar"> <div class="sidebar-header"> - <h2 id="logo-link">Neko v3</h2> + <div id="logo-link" class="sidebar-logo">🐱</div> </div> <div class="sidebar-search"> <input type="search" id="search-input" placeholder="Search..." value="${store.searchQuery}"> @@ -124,7 +124,11 @@ export function attachLayoutListeners() { } else if (navType === 'feed') { e.preventDefault(); const feedId = link.getAttribute('data-value')!; - router.navigate(`/feed/${feedId}`, currentQuery); + if (store.activeFeedId === parseInt(feedId)) { + router.navigate('/', currentQuery); + } else { + router.navigate(`/feed/${feedId}`, currentQuery); + } } else if (navType === 'settings') { e.preventDefault(); router.navigate('/settings', currentQuery); @@ -253,40 +257,130 @@ export function renderSettings() { contentArea.innerHTML = ` <div class="settings-view"> <h2>Settings</h2> + + <section class="settings-section"> + <h3>Add Feed</h3> + <div class="add-feed-form"> + <input type="url" id="new-feed-url" placeholder="https://example.com/rss.xml"> + <button id="add-feed-btn">Add Feed</button> + </div> + </section> + <section class="settings-section"> - <h3>Theme</h3> - <div class="theme-options" id="theme-options"> - <button class="${store.theme === 'light' ? 'active' : ''}" data-theme="light">Light</button> - <button class="${store.theme === 'dark' ? 'active' : ''}" data-theme="dark">Dark</button> + <h3>Appearance</h3> + <div class="settings-group"> + <label>Theme</label> + <div class="theme-options" id="theme-options"> + <button class="${store.theme === 'light' ? 'active' : ''}" data-theme="light">Light</button> + <button class="${store.theme === 'dark' ? 'active' : ''}" data-theme="dark">Dark</button> + </div> + </div> + <div class="settings-group" style="margin-top: 1rem;"> + <label>Font</label> + <select id="font-selector"> + <option value="default" ${store.fontTheme === 'default' ? 'selected' : ''}>Default (Palatino)</option> + <option value="serif" ${store.fontTheme === 'serif' ? 'selected' : ''}>Serif (Georgia)</option> + <option value="sans" ${store.fontTheme === 'sans' ? 'selected' : ''}>Sans-Serif (Helvetica)</option> + <option value="mono" ${store.fontTheme === 'mono' ? 'selected' : ''}>Monospace</option> + </select> </div> </section> + <section class="settings-section"> - <h3>Font</h3> - <select id="font-selector"> - <option value="default" ${store.fontTheme === 'default' ? 'selected' : ''}>Default (Palatino)</option> - <option value="serif" ${store.fontTheme === 'serif' ? 'selected' : ''}>Serif (Georgia)</option> - <option value="sans" ${store.fontTheme === 'sans' ? 'selected' : ''}>Sans-Serif (Helvetica)</option> - <option value="mono" ${store.fontTheme === 'mono' ? 'selected' : ''}>Monospace</option> - </select> + <h3>Data Management</h3> + <div class="data-actions"> + <button id="export-opml-btn">Export OPML</button> + <div class="import-section" style="margin-top: 1rem;"> + <label for="import-opml-file" class="button">Import OPML</label> + <input type="file" id="import-opml-file" accept=".opml,.xml" style="display: none;"> + </div> + </div> </section> </div> `; // Attach settings listeners - const themeOptions = document.getElementById('theme-options'); - themeOptions?.addEventListener('click', (e) => { + document.getElementById('theme-options')?.addEventListener('click', (e) => { const btn = (e.target as HTMLElement).closest('button'); if (btn) { const theme = btn.getAttribute('data-theme')!; store.setTheme(theme); - renderSettings(); // Re-render to show active + renderSettings(); } }); - const fontSelector = document.getElementById('font-selector') as HTMLSelectElement; - fontSelector?.addEventListener('change', () => { - store.setFontTheme(fontSelector.value); + document.getElementById('font-selector')?.addEventListener('change', (e) => { + store.setFontTheme((e.target as HTMLSelectElement).value); }); + + document.getElementById('add-feed-btn')?.addEventListener('click', async () => { + const input = document.getElementById('new-feed-url') as HTMLInputElement; + const url = input.value.trim(); + if (url) { + const success = await addFeed(url); + if (success) { + input.value = ''; + alert('Feed added successfully!'); + fetchFeeds(); + } else { + alert('Failed to add feed.'); + } + } + }); + + document.getElementById('export-opml-btn')?.addEventListener('click', () => { + window.location.href = '/api/export/opml'; + }); + + document.getElementById('import-opml-file')?.addEventListener('change', async (e) => { + const file = (e.target as HTMLInputElement).files?.[0]; + if (file) { + const success = await importOPML(file); + if (success) { + alert('OPML imported successfully! Crawling started.'); + fetchFeeds(); + } else { + alert('Failed to import OPML.'); + } + } + }); +} + +async function addFeed(url: string): Promise<boolean> { + try { + const res = await apiFetch('/api/feed', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ url }) + }); + return res.ok; + } catch (err) { + console.error('Failed to add feed', err); + return false; + } +} + +async function importOPML(file: File): Promise<boolean> { + try { + const formData = new FormData(); + formData.append('file', file); + formData.append('format', 'opml'); + + // We need to handle CSRF manually since apiFetch expects JSON or simple body + const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrf_token='))?.split('=')[1]; + + const res = await fetch('/api/import', { + method: 'POST', + headers: { + 'X-CSRF-Token': csrfToken || '' + }, + body: formData + }); + return res.ok; + } catch (err) { + console.error('Failed to import OPML', err); + return false; + } } // --- Data Actions --- diff --git a/frontend-vanilla/src/style.css b/frontend-vanilla/src/style.css index 6e048aa..a97f443 100644 --- a/frontend-vanilla/src/style.css +++ b/frontend-vanilla/src/style.css @@ -19,23 +19,31 @@ color-scheme: light dark; } +* { + box-sizing: border-box; +} + body { margin: 0; font-family: var(--font-body); background-color: var(--bg-color); color: var(--text-color); height: 100vh; + width: 100%; overflow: hidden; } #app { height: 100%; + width: 100%; } .layout { display: flex; height: 100%; width: 100%; + overflow-x: hidden; + position: relative; } /* Sidebar - matching v2 glass variant */ @@ -58,12 +66,16 @@ body { border-right-color: rgba(255, 255, 255, 0.05); } -.sidebar-header h2 { - font-family: var(--font-heading); - font-size: 1.5rem; - margin: 0 0 2rem 0; - opacity: 0.8; +.sidebar-header { + margin-bottom: 2rem; + display: flex; + justify-content: center; +} + +.sidebar-logo { + font-size: 3rem; cursor: pointer; + user-select: none; } .sidebar-search { @@ -470,4 +482,44 @@ button.active { .theme-dark button.active { background-color: #224; border-color: var(--accent-color); -}
\ No newline at end of file +} +.add-feed-form { + display: flex; + gap: 0.5rem; +} + +.add-feed-form input { + flex: 1; + padding: 0.6rem 1rem; + border-radius: 8px; + border: 1px solid var(--border-color); + background: var(--bg-color); + color: var(--text-color); +} + +.settings-group label { + display: block; + font-size: 0.85rem; + font-weight: 600; + margin-bottom: 0.5rem; + opacity: 0.7; +} + +#font-selector { + width: 100%; + padding: 0.6rem; + border-radius: 8px; + border: 1px solid var(--border-color); + background: var(--bg-color); + color: var(--text-color); +} + +.data-actions button, .data-actions .button { + display: inline-block; + text-align: center; + width: 100%; +} + +label.button { + cursor: pointer; +} diff --git a/web/dist/v3/assets/index-BmLjwl8J.js b/web/dist/v3/assets/index-BmLjwl8J.js new file mode 100644 index 0000000..b4ea614 --- /dev/null +++ b/web/dist/v3/assets/index-BmLjwl8J.js @@ -0,0 +1,128 @@ +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const d of r.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&n(d)}).observe(document,{childList:!0,subtree:!0});function a(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(s){if(s.ep)return;s.ep=!0;const r=a(s);fetch(s.href,r)}})();function F(t){const a=`; ${document.cookie}`.split(`; ${t}=`);if(a.length===2)return a.pop()?.split(";").shift()}async function m(t,e){const a=e?.method?.toUpperCase()||"GET",n=["POST","PUT","DELETE"].includes(a),s=new Headers(e?.headers||{});if(n){const r=F("csrf_token");r&&s.set("X-CSRF-Token",r)}return fetch(t,{...e,headers:s,credentials:"include"})}class _ extends EventTarget{feeds=[];tags=[];items=[];activeFeedId=null;activeTagName=null;filter="unread";searchQuery="";loading=!1;hasMore=!0;theme=localStorage.getItem("neko-theme")||"light";fontTheme=localStorage.getItem("neko-font-theme")||"default";sidebarVisible=window.innerWidth>768;setFeeds(e){this.feeds=e,this.emit("feeds-updated")}setTags(e){this.tags=e,this.emit("tags-updated")}setItems(e,a=!1){a?this.items=[...this.items,...e]:this.items=e,this.emit("items-updated")}setActiveFeed(e){this.activeFeedId=e,this.activeTagName=null,this.emit("active-feed-updated")}setActiveTag(e){this.activeTagName=e,this.activeFeedId=null,this.emit("active-tag-updated")}setFilter(e){this.filter!==e&&(this.filter=e,this.emit("filter-updated"))}setSearchQuery(e){this.searchQuery!==e&&(this.searchQuery=e,this.emit("search-updated"))}setLoading(e){this.loading=e,this.emit("loading-state-changed")}setHasMore(e){this.hasMore=e}setTheme(e){this.theme=e,localStorage.setItem("neko-theme",e),this.emit("theme-updated")}setFontTheme(e){this.fontTheme=e,localStorage.setItem("neko-font-theme",e),this.emit("theme-updated")}setSidebarVisible(e){this.sidebarVisible=e,this.emit("sidebar-toggle")}toggleSidebar(){this.setSidebarVisible(!this.sidebarVisible)}emit(e,a){this.dispatchEvent(new CustomEvent(e,{detail:a}))}on(e,a){this.addEventListener(e,a)}}const i=new _;class A extends EventTarget{constructor(){super(),window.addEventListener("popstate",()=>this.handleRouteChange())}handleRouteChange(){this.dispatchEvent(new CustomEvent("route-changed",{detail:this.getCurrentRoute()}))}getCurrentRoute(){const e=new URL(window.location.href),n=e.pathname.replace(/^\/v3\//,"").split("/").filter(Boolean);let s="/";const r={};return n[0]==="feed"&&n[1]?(s="/feed",r.feedId=n[1]):n[0]==="tag"&&n[1]?(s="/tag",r.tagName=decodeURIComponent(n[1])):n[0]==="settings"&&(s="/settings"),{path:s,params:r,query:e.searchParams}}navigate(e,a){let n=`/v3${e}`;if(a){const s=new URLSearchParams(a);n+=`?${s.toString()}`}window.history.pushState({},"",n),this.handleRouteChange()}updateQuery(e){const a=new URL(window.location.href);for(const[n,s]of Object.entries(e))s?a.searchParams.set(n,s):a.searchParams.delete(n);window.history.pushState({},"",a.toString()),this.handleRouteChange()}}const o=new A;function B(t){const e=new Date(t.publish_date).toLocaleDateString();return` + <li class="feed-item ${t.read?"read":"unread"}" data-id="${t._id}"> + <div class="item-header"> + <a href="${t.url}" target="_blank" rel="noopener noreferrer" class="item-title" data-action="open"> + ${t.title||"(No Title)"} + </a> + <button class="star-btn ${t.starred?"is-starred":"is-unstarred"}" title="${t.starred?"Unstar":"Star"}" data-action="toggle-star"> + ★ + </button> + </div> + <div class="dateline"> + <a href="${t.url}" target="_blank" rel="noopener noreferrer"> + ${e} + ${t.feed_title?` - ${t.feed_title}`:""} + </a> + <div class="item-actions" style="display: inline-block; float: right;"> + ${t.full_content?"":` + <button class="scrape-btn" title="Load Full Content" data-action="scrape"> + text + </button> + `} + </div> + </div> + ${t.full_content||t.description?` + <div class="item-description"> + ${t.full_content||t.description} + </div> + `:""} + </li> + `}let l=null,f=null;function R(){f=document.querySelector("#app"),f&&(f.className=`theme-${i.theme} font-${i.fontTheme}`,f.innerHTML=` + <div class="layout ${i.sidebarVisible?"sidebar-visible":"sidebar-hidden"}"> + <button class="sidebar-toggle" id="sidebar-toggle-btn" title="Toggle Sidebar">🐱</button> + <div class="sidebar-backdrop" id="sidebar-backdrop"></div> + <aside class="sidebar" id="sidebar"> + <div class="sidebar-header"> + <div id="logo-link" class="sidebar-logo">🐱</div> + </div> + <div class="sidebar-search"> + <input type="search" id="search-input" placeholder="Search..." value="${i.searchQuery}"> + </div> + <div class="sidebar-scroll"> + <section class="sidebar-section"> + <h3>Filters</h3> + <ul id="filter-list"> + <li class="filter-item" data-filter="unread"><a href="/v3/?filter=unread" data-nav="filter" data-value="unread">Unread</a></li> + <li class="filter-item" data-filter="all"><a href="/v3/?filter=all" data-nav="filter" data-value="all">All</a></li> + <li class="filter-item" data-filter="starred"><a href="/v3/?filter=starred" data-nav="filter" data-value="starred">Starred</a></li> + </ul> + </section> + <section class="sidebar-section collapsible collapsed" id="section-tags"> + <h3>Tags <span class="caret">▶</span></h3> + <ul id="tag-list"></ul> + </section> + <section class="sidebar-section collapsible collapsed" id="section-feeds"> + <h3>Feeds <span class="caret">▶</span></h3> + <ul id="feed-list"></ul> + </section> + </div> + <div class="sidebar-footer"> + <a href="/v3/settings" data-nav="settings">Settings</a> + <a href="#" id="logout-button">Logout</a> + </div> + </aside> + <main class="main-content" id="main-content"> + <div id="content-area"></div> + </main> + </div> + `,P())}function P(){document.getElementById("search-input")?.addEventListener("input",s=>{const r=s.target.value;o.updateQuery({q:r})}),document.getElementById("logo-link")?.addEventListener("click",()=>o.navigate("/")),document.getElementById("logout-button")?.addEventListener("click",s=>{s.preventDefault(),D()}),document.getElementById("sidebar-toggle-btn")?.addEventListener("click",()=>{i.toggleSidebar()}),document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>{i.setSidebarVisible(!1)}),window.addEventListener("resize",()=>{window.innerWidth>768&&!i.sidebarVisible&&i.setSidebarVisible(!0)}),document.querySelectorAll(".sidebar-section.collapsible h3").forEach(s=>{s.addEventListener("click",()=>{s.parentElement?.classList.toggle("collapsed")})}),document.getElementById("sidebar")?.addEventListener("click",s=>{const d=s.target.closest("a");if(!d)return;const g=d.getAttribute("data-nav"),h=Object.fromEntries(o.getCurrentRoute().query.entries());if(g==="filter"){s.preventDefault();const c=d.getAttribute("data-value");o.updateQuery({filter:c})}else if(g==="tag"){s.preventDefault();const c=d.getAttribute("data-value");o.navigate(`/tag/${encodeURIComponent(c)}`,h)}else if(g==="feed"){s.preventDefault();const c=d.getAttribute("data-value");i.activeFeedId===parseInt(c)?o.navigate("/",h):o.navigate(`/feed/${c}`,h)}else g==="settings"&&(s.preventDefault(),o.navigate("/settings",h));window.innerWidth<=768&&i.setSidebarVisible(!1)}),document.getElementById("content-area")?.addEventListener("click",s=>{const r=s.target,d=r.closest('[data-action="toggle-star"]');if(d){const u=d.closest("[data-id]");if(u){const p=parseInt(u.getAttribute("data-id"));O(p)}return}const g=r.closest('[data-action="scrape"]');if(g){const u=g.closest("[data-id]");if(u){const p=parseInt(u.getAttribute("data-id"));N(p)}return}const h=r.closest('[data-action="open"]'),c=r.closest(".feed-item");if(c&&!h){const u=parseInt(c.getAttribute("data-id")),p=i.items.find($=>$._id===u);p&&!p.read&&v(u,{read:!0})}})}function E(){const{feeds:t,activeFeedId:e}=i,a=document.getElementById("feed-list");a&&(a.innerHTML=t.map(n=>` + <li class="${n._id===e?"active":""}"> + <a href="/v3/feed/${n._id}" data-nav="feed" data-value="${n._id}"> + ${n.title||n.url} + </a> + </li> + `).join(""))}function S(){const{tags:t,activeTagName:e}=i,a=document.getElementById("tag-list");a&&(a.innerHTML=t.map(n=>` + <li class="${n.title===e?"active":""}"> + <a href="/v3/tag/${encodeURIComponent(n.title)}" data-nav="tag" data-value="${n.title}"> + ${n.title} + </a> + </li> + `).join(""))}function T(){const{filter:t}=i,e=document.getElementById("filter-list");e&&e.querySelectorAll("li").forEach(a=>{a.classList.toggle("active",a.getAttribute("data-filter")===t)})}function w(){const{items:t,loading:e}=i,a=document.getElementById("content-area");if(!a||o.getCurrentRoute().path==="/settings")return;if(e&&t.length===0){a.innerHTML='<p class="loading">Loading items...</p>';return}if(t.length===0){a.innerHTML='<p class="empty">No items found.</p>';return}a.innerHTML=` + <ul class="item-list"> + ${t.map(s=>B(s)).join("")} + </ul> + ${i.hasMore?'<div id="load-more-sentinel" class="loading-more">Loading more...</div>':""} + `;const n=document.getElementById("load-more-sentinel");n&&new IntersectionObserver(r=>{r[0].isIntersecting&&!i.loading&&i.hasMore&&Q()},{threshold:.1}).observe(n)}function k(){const t=document.getElementById("content-area");t&&(t.innerHTML=` + <div class="settings-view"> + <h2>Settings</h2> + + <section class="settings-section"> + <h3>Add Feed</h3> + <div class="add-feed-form"> + <input type="url" id="new-feed-url" placeholder="https://example.com/rss.xml"> + <button id="add-feed-btn">Add Feed</button> + </div> + </section> + + <section class="settings-section"> + <h3>Appearance</h3> + <div class="settings-group"> + <label>Theme</label> + <div class="theme-options" id="theme-options"> + <button class="${i.theme==="light"?"active":""}" data-theme="light">Light</button> + <button class="${i.theme==="dark"?"active":""}" data-theme="dark">Dark</button> + </div> + </div> + <div class="settings-group" style="margin-top: 1rem;"> + <label>Font</label> + <select id="font-selector"> + <option value="default" ${i.fontTheme==="default"?"selected":""}>Default (Palatino)</option> + <option value="serif" ${i.fontTheme==="serif"?"selected":""}>Serif (Georgia)</option> + <option value="sans" ${i.fontTheme==="sans"?"selected":""}>Sans-Serif (Helvetica)</option> + <option value="mono" ${i.fontTheme==="mono"?"selected":""}>Monospace</option> + </select> + </div> + </section> + + <section class="settings-section"> + <h3>Data Management</h3> + <div class="data-actions"> + <button id="export-opml-btn">Export OPML</button> + <div class="import-section" style="margin-top: 1rem;"> + <label for="import-opml-file" class="button">Import OPML</label> + <input type="file" id="import-opml-file" accept=".opml,.xml" style="display: none;"> + </div> + </div> + </section> + </div> + `,document.getElementById("theme-options")?.addEventListener("click",e=>{const a=e.target.closest("button");if(a){const n=a.getAttribute("data-theme");i.setTheme(n),k()}}),document.getElementById("font-selector")?.addEventListener("change",e=>{i.setFontTheme(e.target.value)}),document.getElementById("add-feed-btn")?.addEventListener("click",async()=>{const e=document.getElementById("new-feed-url"),a=e.value.trim();a&&(await C(a)?(e.value="",alert("Feed added successfully!"),y()):alert("Failed to add feed."))}),document.getElementById("export-opml-btn")?.addEventListener("click",()=>{window.location.href="/api/export/opml"}),document.getElementById("import-opml-file")?.addEventListener("change",async e=>{const a=e.target.files?.[0];a&&(await M(a)?(alert("OPML imported successfully! Crawling started."),y()):alert("Failed to import OPML."))}))}async function C(t){try{return(await m("/api/feed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t})})).ok}catch(e){return console.error("Failed to add feed",e),!1}}async function M(t){try{const e=new FormData;e.append("file",t),e.append("format","opml");const a=document.cookie.split("; ").find(s=>s.startsWith("csrf_token="))?.split("=")[1];return(await fetch("/api/import",{method:"POST",headers:{"X-CSRF-Token":a||""},body:e})).ok}catch(e){return console.error("Failed to import OPML",e),!1}}async function O(t){const e=i.items.find(a=>a._id===t);e&&v(t,{starred:!e.starred})}async function N(t){if(i.items.find(a=>a._id===t))try{const a=await m(`/api/item/${t}/content`);if(a.ok){const n=await a.json();n.full_content&&v(t,{full_content:n.full_content})}}catch(a){console.error("Failed to fetch full content",a)}}async function v(t,e){try{if((await m(`/api/item/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok){const n=i.items.find(s=>s._id===t);if(n){Object.assign(n,e);const s=document.querySelector(`.feed-item[data-id="${t}"]`);if(s){if(e.read!==void 0&&s.classList.toggle("read",e.read),e.starred!==void 0){const r=s.querySelector(".star-btn");r&&(r.classList.toggle("is-starred",e.starred),r.classList.toggle("is-unstarred",!e.starred),r.setAttribute("title",e.starred?"Unstar":"Star"))}e.full_content&&w()}}}}catch(a){console.error("Failed to update item",a)}}async function y(){const t=await m("/api/feed/");if(t.ok){const e=await t.json();i.setFeeds(e)}}async function q(){const t=await m("/api/tag");if(t.ok){const e=await t.json();i.setTags(e)}}async function b(t,e,a=!1){i.setLoading(!0);try{const n=new URLSearchParams;t&&n.append("feed_id",t),e&&n.append("tag",e),i.searchQuery&&n.append("q",i.searchQuery),(i.filter==="starred"||i.filter==="all")&&n.append("read_filter","all"),i.filter==="starred"&&n.append("starred","true"),a&&i.items.length>0&&n.append("max_id",String(i.items[i.items.length-1]._id));const s=await m(`/api/stream?${n.toString()}`);if(s.ok){const r=await s.json();i.setHasMore(r.length>=50),i.setItems(r,a)}}finally{i.setLoading(!1)}}async function Q(){const t=o.getCurrentRoute();b(t.params.feedId,t.params.tagName,!0)}async function D(){await m("/api/logout",{method:"POST"}),window.location.href="/login/"}function L(){const t=o.getCurrentRoute(),e=t.query.get("filter");i.setFilter(e||"unread");const a=t.query.get("q");if(a!==null&&i.setSearchQuery(a),t.path==="/settings"){k();return}if(t.path==="/feed"&&t.params.feedId){const n=parseInt(t.params.feedId);i.setActiveFeed(n),b(t.params.feedId),document.getElementById("section-feeds")?.classList.remove("collapsed")}else t.path==="/tag"&&t.params.tagName?(i.setActiveTag(t.params.tagName),b(void 0,t.params.tagName),document.getElementById("section-tags")?.classList.remove("collapsed")):(i.setActiveFeed(null),i.setActiveTag(null),b())}window.addEventListener("keydown",t=>{if(!["INPUT","TEXTAREA"].includes(t.target.tagName))switch(t.key){case"j":I(1);break;case"k":I(-1);break;case"r":if(l){const e=i.items.find(a=>a._id===l);e&&v(e._id,{read:!e.read})}break;case"s":if(l){const e=i.items.find(a=>a._id===l);e&&v(e._id,{starred:!e.starred})}break;case"/":t.preventDefault(),document.getElementById("search-input")?.focus();break}});function I(t){if(i.items.length===0)return;let e=i.items.findIndex(a=>a._id===l);if(e+=t,e>=0&&e<i.items.length){l=i.items[e]._id;const a=document.querySelector(`.feed-item[data-id="${l}"]`);a&&a.scrollIntoView({block:"nearest"}),i.items[e].read||v(l,{read:!0})}else if(e===-1){l=i.items[0]._id;const a=document.querySelector(`.feed-item[data-id="${l}"]`);a&&a.scrollIntoView({block:"nearest"})}}i.on("feeds-updated",E);i.on("tags-updated",S);i.on("active-feed-updated",E);i.on("active-tag-updated",S);i.on("filter-updated",T);i.on("search-updated",()=>{const t=document.getElementById("search-input");t&&t.value!==i.searchQuery&&(t.value=i.searchQuery),L()});i.on("theme-updated",()=>{f||(f=document.querySelector("#app")),f&&(f.className=`theme-${i.theme} font-${i.fontTheme}`)});i.on("sidebar-toggle",()=>{const t=document.querySelector(".layout");t&&(i.sidebarVisible?(t.classList.remove("sidebar-hidden"),t.classList.add("sidebar-visible")):(t.classList.remove("sidebar-visible"),t.classList.add("sidebar-hidden")))});i.on("items-updated",w);i.on("loading-state-changed",w);o.addEventListener("route-changed",L);window.app={navigate:t=>o.navigate(t)};async function U(){const t=await m("/api/auth");if(!t||t.status===401){window.location.href="/login/";return}R(),T();try{await Promise.all([y(),q()])}catch(e){console.error("Initial fetch failed",e)}L()}typeof window<"u"&&!window.__VITEST__&&U(); diff --git a/web/dist/v3/assets/index-CJ8IAAIK.css b/web/dist/v3/assets/index-CJ8IAAIK.css new file mode 100644 index 0000000..9538d1a --- /dev/null +++ b/web/dist/v3/assets/index-CJ8IAAIK.css @@ -0,0 +1 @@ +:root{--font-body: Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;--font-heading: "Helvetica Neue", Helvetica, Arial, sans-serif;--font-sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;line-height:1.5;font-size:18px;--bg-color: #ffffff;--text-color: rgba(0, 0, 0, .87);--sidebar-bg: #f5f5f5;--link-color: #0000ee;--border-color: #e5e5e5;--accent-color: #007bff;color-scheme:light dark}*{box-sizing:border-box}body{margin:0;font-family:var(--font-body);background-color:var(--bg-color);color:var(--text-color);height:100vh;width:100%;overflow:hidden}#app{height:100%;width:100%}.layout{display:flex;height:100%;width:100%;overflow-x:hidden;position:relative}.sidebar{width:11rem;background:#ffffff0d;backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-right:1px solid rgba(255,255,255,.1);display:flex;flex-direction:column;height:100%;overflow:hidden;z-index:100;padding:1.5rem}.theme-dark .sidebar{background:#0003;border-right-color:#ffffff0d}.sidebar-header{margin-bottom:2rem;display:flex;justify-content:center}.sidebar-logo{font-size:3rem;cursor:pointer;-webkit-user-select:none;user-select:none}.sidebar-search{margin-bottom:2rem}.sidebar-search input{width:100%;border-radius:20px;background:#0000000d;border:1px solid rgba(255,255,255,.1);color:var(--text-color);padding:.5rem 1rem;font-size:.9rem}.sidebar-scroll{flex:1;overflow-y:auto;margin:0 -1.5rem;padding:0 1.5rem}.sidebar-section h3{font-family:var(--font-sans);font-size:.7rem;text-transform:uppercase;letter-spacing:.1em;opacity:.5;margin-top:2rem;margin-bottom:.5rem;font-weight:700;display:flex;align-items:center;justify-content:space-between;cursor:pointer;-webkit-user-select:none;user-select:none}.sidebar-section h3:hover{opacity:.8}.sidebar-section .caret{font-size:.6rem;transition:transform .2s ease;transform:rotate(90deg)}.sidebar-section.collapsed .caret{transform:rotate(0)}.sidebar-section.collapsed ul{display:none}.sidebar-section ul{list-style:none;padding:0;margin:0}.sidebar-section li a{display:block;padding:.3rem .8rem;margin:.1rem 0;border-radius:8px;transition:all .2s ease;font-weight:500;font-size:.85rem;text-decoration:none;color:var(--text-color);opacity:.8;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--font-sans)}.sidebar-section li a:hover{background:#ffffff1a;opacity:1;transform:translate(4px)}.sidebar-section li.active a{background:#ffffff40;opacity:1;font-weight:700;box-shadow:0 4px 12px #0000001a;border:1px solid rgba(255,255,255,.2)}.sidebar-footer{margin-top:auto;padding-top:1.5rem;border-top:1px solid rgba(255,255,255,.1);display:flex;flex-direction:column;gap:.5rem}.sidebar-footer a{opacity:.6;padding:.5rem .8rem;border-radius:8px;text-decoration:none;color:var(--text-color);font-size:.9rem;font-family:var(--font-sans)}.sidebar-footer a:hover{background:#ffffff0d;opacity:1}.main-content{flex:1;min-width:0;overflow-y:auto;background-color:var(--bg-color);padding:1.5rem 2rem;transition:padding .3s ease}@media(max-width:768px){.main-content{padding:4rem 1rem 1rem}}.main-content>*{max-width:35em;margin-left:auto;margin-right:auto}.sidebar-toggle{position:fixed;top:1rem;left:1rem;z-index:1001;background:var(--sidebar-bg);border:1px solid var(--border-color);border-radius:50%;width:3rem;height:3rem;font-size:1.5rem;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px #0000001a;transition:transform .2s cubic-bezier(.175,.885,.32,1.275);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)}.sidebar-toggle:hover{transform:scale(1.1)}.sidebar-toggle:active{transform:scale(.95)}.sidebar-backdrop{display:none;position:fixed;inset:0;background:#0000004d;backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);z-index:999}@media(max-width:768px){.sidebar-visible .sidebar-backdrop{display:block}.sidebar{position:fixed;top:0;left:0;bottom:0;z-index:1000;transform:translate(-100%);transition:transform .3s cubic-bezier(.4,0,.2,1);box-shadow:none}.sidebar-visible .sidebar{transform:translate(0);box-shadow:10px 0 20px #0000001a}.sidebar-visible .sidebar-toggle{left:12rem}}@media(min-width:769px){.sidebar-visible .sidebar-toggle{left:12rem}}.sidebar-hidden .sidebar{display:none}@media(min-width:769px){.sidebar-hidden .sidebar{display:none}.sidebar-visible .sidebar{display:flex}}.item-list{list-style:none;padding:0;margin:0}.feed-item{padding:1rem 0;margin-top:5rem;border-bottom:none}.item-header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:.5rem}.item-title{font-family:var(--font-heading);font-size:1.8rem;font-weight:700;text-decoration:none;color:var(--link-color);display:block;flex:1;cursor:pointer}.item-title:hover{text-decoration:underline}.star-btn{background:none;border:none;cursor:pointer;font-size:1.25rem;padding:0 0 0 .5rem;vertical-align:middle;transition:color .2s;line-height:1}.star-btn.is-starred{color:#00f}.star-btn.is-unstarred{color:var(--text-color);opacity:.3}.dateline{margin-top:0;font-weight:400;font-size:.75em;color:#ccc;margin-bottom:1rem}.dateline a{color:#ccc;text-decoration:none}.item-description{color:var(--text-color);line-height:1.5;font-size:1rem;margin-top:1rem;overflow-wrap:break-word;word-break:break-word}.item-description img{max-width:100%;height:auto;display:block;margin:1rem 0}.scrape-btn{background:var(--bg-color);border:1px solid var(--border-color, #ccc);color:#00f;cursor:pointer;font-family:var(--font-heading);font-weight:700;font-size:.8rem;padding:2px 6px;margin-left:.5rem}.theme-dark{--bg-color: #000000;--text-color: #ffffff;--sidebar-bg: #111111;--link-color: rgb(90, 200, 250);--border-color: #333}.font-serif{--font-body: Georgia, "Times New Roman", Times, serif;font-family:var(--font-body)}.font-sans{--font-body: var(--font-heading);font-family:var(--font-body)}.font-mono{--font-body: Menlo, Monaco, Consolas, "Courier New", monospace;font-family:var(--font-body)}.settings-view{padding-top:2rem}.settings-section{margin-bottom:2.5rem}.settings-section h3{font-family:var(--font-heading);border-bottom:1px solid var(--border-color);padding-bottom:.5rem;margin-bottom:1rem}.theme-options{display:flex;gap:1rem}button{border-radius:8px;border:1px solid var(--border-color);padding:.6em 1.2em;font-size:1em;font-weight:700;font-family:inherit;background-color:#f9f9f9;cursor:pointer;transition:all .2s}.theme-dark button{background-color:#1a1a1a;color:#fff;border-color:#333}button.active{border-color:var(--accent-color);background-color:#eef}.theme-dark button.active{background-color:#224;border-color:var(--accent-color)}.add-feed-form{display:flex;gap:.5rem}.add-feed-form input{flex:1;padding:.6rem 1rem;border-radius:8px;border:1px solid var(--border-color);background:var(--bg-color);color:var(--text-color)}.settings-group label{display:block;font-size:.85rem;font-weight:600;margin-bottom:.5rem;opacity:.7}#font-selector{width:100%;padding:.6rem;border-radius:8px;border:1px solid var(--border-color);background:var(--bg-color);color:var(--text-color)}.data-actions button,.data-actions .button{display:inline-block;text-align:center;width:100%}label.button{cursor:pointer} diff --git a/web/dist/v3/assets/index-Cqbn4jqh.css b/web/dist/v3/assets/index-Cqbn4jqh.css deleted file mode 100644 index 017e4fa..0000000 --- a/web/dist/v3/assets/index-Cqbn4jqh.css +++ /dev/null @@ -1 +0,0 @@ -:root{--font-body: Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;--font-heading: "Helvetica Neue", Helvetica, Arial, sans-serif;--font-sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;line-height:1.5;font-size:18px;--bg-color: #ffffff;--text-color: rgba(0, 0, 0, .87);--sidebar-bg: #f5f5f5;--link-color: #0000ee;--border-color: #e5e5e5;--accent-color: #007bff;color-scheme:light dark}body{margin:0;font-family:var(--font-body);background-color:var(--bg-color);color:var(--text-color);height:100vh;overflow:hidden}#app{height:100%}.layout{display:flex;height:100%;width:100%}.sidebar{width:11rem;background:#ffffff0d;backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-right:1px solid rgba(255,255,255,.1);display:flex;flex-direction:column;height:100%;overflow:hidden;z-index:100;padding:1.5rem}.theme-dark .sidebar{background:#0003;border-right-color:#ffffff0d}.sidebar-header h2{font-family:var(--font-heading);font-size:1.5rem;margin:0 0 2rem;opacity:.8;cursor:pointer}.sidebar-search{margin-bottom:2rem}.sidebar-search input{width:100%;border-radius:20px;background:#0000000d;border:1px solid rgba(255,255,255,.1);color:var(--text-color);padding:.5rem 1rem;font-size:.9rem}.sidebar-scroll{flex:1;overflow-y:auto;margin:0 -1.5rem;padding:0 1.5rem}.sidebar-section h3{font-family:var(--font-sans);font-size:.7rem;text-transform:uppercase;letter-spacing:.1em;opacity:.5;margin-top:2rem;margin-bottom:.5rem;font-weight:700;display:flex;align-items:center;justify-content:space-between;cursor:pointer;-webkit-user-select:none;user-select:none}.sidebar-section h3:hover{opacity:.8}.sidebar-section .caret{font-size:.6rem;transition:transform .2s ease;transform:rotate(90deg)}.sidebar-section.collapsed .caret{transform:rotate(0)}.sidebar-section.collapsed ul{display:none}.sidebar-section ul{list-style:none;padding:0;margin:0}.sidebar-section li a{display:block;padding:.3rem .8rem;margin:.1rem 0;border-radius:8px;transition:all .2s ease;font-weight:500;font-size:.85rem;text-decoration:none;color:var(--text-color);opacity:.8;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--font-sans)}.sidebar-section li a:hover{background:#ffffff1a;opacity:1;transform:translate(4px)}.sidebar-section li.active a{background:#ffffff40;opacity:1;font-weight:700;box-shadow:0 4px 12px #0000001a;border:1px solid rgba(255,255,255,.2)}.sidebar-footer{margin-top:auto;padding-top:1.5rem;border-top:1px solid rgba(255,255,255,.1);display:flex;flex-direction:column;gap:.5rem}.sidebar-footer a{opacity:.6;padding:.5rem .8rem;border-radius:8px;text-decoration:none;color:var(--text-color);font-size:.9rem;font-family:var(--font-sans)}.sidebar-footer a:hover{background:#ffffff0d;opacity:1}.main-content{flex:1;min-width:0;overflow-y:auto;background-color:var(--bg-color);padding:1.5rem 2rem;transition:padding .3s ease}@media(max-width:768px){.main-content{padding:4rem 1rem 1rem}}.main-content>*{max-width:35em;margin-left:auto;margin-right:auto}.sidebar-toggle{position:fixed;top:1rem;left:1rem;z-index:1001;background:var(--sidebar-bg);border:1px solid var(--border-color);border-radius:50%;width:3rem;height:3rem;font-size:1.5rem;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px #0000001a;transition:transform .2s cubic-bezier(.175,.885,.32,1.275);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)}.sidebar-toggle:hover{transform:scale(1.1)}.sidebar-toggle:active{transform:scale(.95)}.sidebar-backdrop{display:none;position:fixed;inset:0;background:#0000004d;backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);z-index:999}@media(max-width:768px){.sidebar-visible .sidebar-backdrop{display:block}.sidebar{position:fixed;top:0;left:0;bottom:0;z-index:1000;transform:translate(-100%);transition:transform .3s cubic-bezier(.4,0,.2,1);box-shadow:none}.sidebar-visible .sidebar{transform:translate(0);box-shadow:10px 0 20px #0000001a}.sidebar-visible .sidebar-toggle{left:12rem}}@media(min-width:769px){.sidebar-visible .sidebar-toggle{left:12rem}}.sidebar-hidden .sidebar{display:none}@media(min-width:769px){.sidebar-hidden .sidebar{display:none}.sidebar-visible .sidebar{display:flex}}.item-list{list-style:none;padding:0;margin:0}.feed-item{padding:1rem 0;margin-top:5rem;border-bottom:none}.item-header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:.5rem}.item-title{font-family:var(--font-heading);font-size:1.8rem;font-weight:700;text-decoration:none;color:var(--link-color);display:block;flex:1;cursor:pointer}.item-title:hover{text-decoration:underline}.star-btn{background:none;border:none;cursor:pointer;font-size:1.25rem;padding:0 0 0 .5rem;vertical-align:middle;transition:color .2s;line-height:1}.star-btn.is-starred{color:#00f}.star-btn.is-unstarred{color:var(--text-color);opacity:.3}.dateline{margin-top:0;font-weight:400;font-size:.75em;color:#ccc;margin-bottom:1rem}.dateline a{color:#ccc;text-decoration:none}.item-description{color:var(--text-color);line-height:1.5;font-size:1rem;margin-top:1rem;overflow-wrap:break-word;word-break:break-word}.item-description img{max-width:100%;height:auto;display:block;margin:1rem 0}.scrape-btn{background:var(--bg-color);border:1px solid var(--border-color, #ccc);color:#00f;cursor:pointer;font-family:var(--font-heading);font-weight:700;font-size:.8rem;padding:2px 6px;margin-left:.5rem}.theme-dark{--bg-color: #000000;--text-color: #ffffff;--sidebar-bg: #111111;--link-color: rgb(90, 200, 250);--border-color: #333}.font-serif{--font-body: Georgia, "Times New Roman", Times, serif;font-family:var(--font-body)}.font-sans{--font-body: var(--font-heading);font-family:var(--font-body)}.font-mono{--font-body: Menlo, Monaco, Consolas, "Courier New", monospace;font-family:var(--font-body)}.settings-view{padding-top:2rem}.settings-section{margin-bottom:2.5rem}.settings-section h3{font-family:var(--font-heading);border-bottom:1px solid var(--border-color);padding-bottom:.5rem;margin-bottom:1rem}.theme-options{display:flex;gap:1rem}button{border-radius:8px;border:1px solid var(--border-color);padding:.6em 1.2em;font-size:1em;font-weight:700;font-family:inherit;background-color:#f9f9f9;cursor:pointer;transition:all .2s}.theme-dark button{background-color:#1a1a1a;color:#fff;border-color:#333}button.active{border-color:var(--accent-color);background-color:#eef}.theme-dark button.active{background-color:#224;border-color:var(--accent-color)} diff --git a/web/dist/v3/assets/index-IyL2W0f_.js b/web/dist/v3/assets/index-IyL2W0f_.js deleted file mode 100644 index aa03b2d..0000000 --- a/web/dist/v3/assets/index-IyL2W0f_.js +++ /dev/null @@ -1,105 +0,0 @@ -(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&n(o)}).observe(document,{childList:!0,subtree:!0});function a(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(s){if(s.ep)return;s.ep=!0;const r=a(s);fetch(s.href,r)}})();function k(t){const a=`; ${document.cookie}`.split(`; ${t}=`);if(a.length===2)return a.pop()?.split(";").shift()}async function h(t,e){const a=e?.method?.toUpperCase()||"GET",n=["POST","PUT","DELETE"].includes(a),s=new Headers(e?.headers||{});if(n){const r=k("csrf_token");r&&s.set("X-CSRF-Token",r)}return fetch(t,{...e,headers:s,credentials:"include"})}class _ extends EventTarget{feeds=[];tags=[];items=[];activeFeedId=null;activeTagName=null;filter="unread";searchQuery="";loading=!1;hasMore=!0;theme=localStorage.getItem("neko-theme")||"light";fontTheme=localStorage.getItem("neko-font-theme")||"default";sidebarVisible=window.innerWidth>768;setFeeds(e){this.feeds=e,this.emit("feeds-updated")}setTags(e){this.tags=e,this.emit("tags-updated")}setItems(e,a=!1){a?this.items=[...this.items,...e]:this.items=e,this.emit("items-updated")}setActiveFeed(e){this.activeFeedId=e,this.activeTagName=null,this.emit("active-feed-updated")}setActiveTag(e){this.activeTagName=e,this.activeFeedId=null,this.emit("active-tag-updated")}setFilter(e){this.filter!==e&&(this.filter=e,this.emit("filter-updated"))}setSearchQuery(e){this.searchQuery!==e&&(this.searchQuery=e,this.emit("search-updated"))}setLoading(e){this.loading=e,this.emit("loading-state-changed")}setHasMore(e){this.hasMore=e}setTheme(e){this.theme=e,localStorage.setItem("neko-theme",e),this.emit("theme-updated")}setFontTheme(e){this.fontTheme=e,localStorage.setItem("neko-font-theme",e),this.emit("theme-updated")}setSidebarVisible(e){this.sidebarVisible=e,this.emit("sidebar-toggle")}toggleSidebar(){this.setSidebarVisible(!this.sidebarVisible)}emit(e,a){this.dispatchEvent(new CustomEvent(e,{detail:a}))}on(e,a){this.addEventListener(e,a)}}const i=new _;class F extends EventTarget{constructor(){super(),window.addEventListener("popstate",()=>this.handleRouteChange())}handleRouteChange(){this.dispatchEvent(new CustomEvent("route-changed",{detail:this.getCurrentRoute()}))}getCurrentRoute(){const e=new URL(window.location.href),n=e.pathname.replace(/^\/v3\//,"").split("/").filter(Boolean);let s="/";const r={};return n[0]==="feed"&&n[1]?(s="/feed",r.feedId=n[1]):n[0]==="tag"&&n[1]?(s="/tag",r.tagName=decodeURIComponent(n[1])):n[0]==="settings"&&(s="/settings"),{path:s,params:r,query:e.searchParams}}navigate(e,a){let n=`/v3${e}`;if(a){const s=new URLSearchParams(a);n+=`?${s.toString()}`}window.history.pushState({},"",n),this.handleRouteChange()}updateQuery(e){const a=new URL(window.location.href);for(const[n,s]of Object.entries(e))s?a.searchParams.set(n,s):a.searchParams.delete(n);window.history.pushState({},"",a.toString()),this.handleRouteChange()}}const d=new F;function A(t){const e=new Date(t.publish_date).toLocaleDateString();return` - <li class="feed-item ${t.read?"read":"unread"}" data-id="${t._id}"> - <div class="item-header"> - <a href="${t.url}" target="_blank" rel="noopener noreferrer" class="item-title" data-action="open"> - ${t.title||"(No Title)"} - </a> - <button class="star-btn ${t.starred?"is-starred":"is-unstarred"}" title="${t.starred?"Unstar":"Star"}" data-action="toggle-star"> - ★ - </button> - </div> - <div class="dateline"> - <a href="${t.url}" target="_blank" rel="noopener noreferrer"> - ${e} - ${t.feed_title?` - ${t.feed_title}`:""} - </a> - <div class="item-actions" style="display: inline-block; float: right;"> - ${t.full_content?"":` - <button class="scrape-btn" title="Load Full Content" data-action="scrape"> - text - </button> - `} - </div> - </div> - ${t.full_content||t.description?` - <div class="item-description"> - ${t.full_content||t.description} - </div> - `:""} - </li> - `}let l=null,f=null;function R(){f=document.querySelector("#app"),f&&(f.className=`theme-${i.theme} font-${i.fontTheme}`,f.innerHTML=` - <div class="layout ${i.sidebarVisible?"sidebar-visible":"sidebar-hidden"}"> - <button class="sidebar-toggle" id="sidebar-toggle-btn" title="Toggle Sidebar">🐱</button> - <div class="sidebar-backdrop" id="sidebar-backdrop"></div> - <aside class="sidebar" id="sidebar"> - <div class="sidebar-header"> - <h2 id="logo-link">Neko v3</h2> - </div> - <div class="sidebar-search"> - <input type="search" id="search-input" placeholder="Search..." value="${i.searchQuery}"> - </div> - <div class="sidebar-scroll"> - <section class="sidebar-section"> - <h3>Filters</h3> - <ul id="filter-list"> - <li class="filter-item" data-filter="unread"><a href="/v3/?filter=unread" data-nav="filter" data-value="unread">Unread</a></li> - <li class="filter-item" data-filter="all"><a href="/v3/?filter=all" data-nav="filter" data-value="all">All</a></li> - <li class="filter-item" data-filter="starred"><a href="/v3/?filter=starred" data-nav="filter" data-value="starred">Starred</a></li> - </ul> - </section> - <section class="sidebar-section collapsible collapsed" id="section-tags"> - <h3>Tags <span class="caret">▶</span></h3> - <ul id="tag-list"></ul> - </section> - <section class="sidebar-section collapsible collapsed" id="section-feeds"> - <h3>Feeds <span class="caret">▶</span></h3> - <ul id="feed-list"></ul> - </section> - </div> - <div class="sidebar-footer"> - <a href="/v3/settings" data-nav="settings">Settings</a> - <a href="#" id="logout-button">Logout</a> - </div> - </aside> - <main class="main-content" id="main-content"> - <div id="content-area"></div> - </main> - </div> - `,B())}function B(){document.getElementById("search-input")?.addEventListener("input",s=>{const r=s.target.value;d.updateQuery({q:r})}),document.getElementById("logo-link")?.addEventListener("click",()=>d.navigate("/")),document.getElementById("logout-button")?.addEventListener("click",s=>{s.preventDefault(),Q()}),document.getElementById("sidebar-toggle-btn")?.addEventListener("click",()=>{i.toggleSidebar()}),document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>{i.setSidebarVisible(!1)}),window.addEventListener("resize",()=>{window.innerWidth>768&&!i.sidebarVisible&&i.setSidebarVisible(!0)}),document.querySelectorAll(".sidebar-section.collapsible h3").forEach(s=>{s.addEventListener("click",()=>{s.parentElement?.classList.toggle("collapsed")})}),document.getElementById("sidebar")?.addEventListener("click",s=>{const o=s.target.closest("a");if(!o)return;const m=o.getAttribute("data-nav"),v=Object.fromEntries(d.getCurrentRoute().query.entries());if(m==="filter"){s.preventDefault();const c=o.getAttribute("data-value");d.updateQuery({filter:c})}else if(m==="tag"){s.preventDefault();const c=o.getAttribute("data-value");d.navigate(`/tag/${encodeURIComponent(c)}`,v)}else if(m==="feed"){s.preventDefault();const c=o.getAttribute("data-value");d.navigate(`/feed/${c}`,v)}else m==="settings"&&(s.preventDefault(),d.navigate("/settings",v));window.innerWidth<=768&&i.setSidebarVisible(!1)}),document.getElementById("content-area")?.addEventListener("click",s=>{const r=s.target,o=r.closest('[data-action="toggle-star"]');if(o){const u=o.closest("[data-id]");if(u){const g=parseInt(u.getAttribute("data-id"));C(g)}return}const m=r.closest('[data-action="scrape"]');if(m){const u=m.closest("[data-id]");if(u){const g=parseInt(u.getAttribute("data-id"));N(g)}return}const v=r.closest('[data-action="open"]'),c=r.closest(".feed-item");if(c&&!v){const u=parseInt(c.getAttribute("data-id")),g=i.items.find($=>$._id===u);g&&!g.read&&p(u,{read:!0})}})}function L(){const{feeds:t,activeFeedId:e}=i,a=document.getElementById("feed-list");a&&(a.innerHTML=t.map(n=>` - <li class="${n._id===e?"active":""}"> - <a href="/v3/feed/${n._id}" data-nav="feed" data-value="${n._id}"> - ${n.title||n.url} - </a> - </li> - `).join(""))}function E(){const{tags:t,activeTagName:e}=i,a=document.getElementById("tag-list");a&&(a.innerHTML=t.map(n=>` - <li class="${n.title===e?"active":""}"> - <a href="/v3/tag/${encodeURIComponent(n.title)}" data-nav="tag" data-value="${n.title}"> - ${n.title} - </a> - </li> - `).join(""))}function S(){const{filter:t}=i,e=document.getElementById("filter-list");e&&e.querySelectorAll("li").forEach(a=>{a.classList.toggle("active",a.getAttribute("data-filter")===t)})}function y(){const{items:t,loading:e}=i,a=document.getElementById("content-area");if(!a||d.getCurrentRoute().path==="/settings")return;if(e&&t.length===0){a.innerHTML='<p class="loading">Loading items...</p>';return}if(t.length===0){a.innerHTML='<p class="empty">No items found.</p>';return}a.innerHTML=` - <ul class="item-list"> - ${t.map(s=>A(s)).join("")} - </ul> - ${i.hasMore?'<div id="load-more-sentinel" class="loading-more">Loading more...</div>':""} - `;const n=document.getElementById("load-more-sentinel");n&&new IntersectionObserver(r=>{r[0].isIntersecting&&!i.loading&&i.hasMore&&M()},{threshold:.1}).observe(n)}function T(){const t=document.getElementById("content-area");if(!t)return;t.innerHTML=` - <div class="settings-view"> - <h2>Settings</h2> - <section class="settings-section"> - <h3>Theme</h3> - <div class="theme-options" id="theme-options"> - <button class="${i.theme==="light"?"active":""}" data-theme="light">Light</button> - <button class="${i.theme==="dark"?"active":""}" data-theme="dark">Dark</button> - </div> - </section> - <section class="settings-section"> - <h3>Font</h3> - <select id="font-selector"> - <option value="default" ${i.fontTheme==="default"?"selected":""}>Default (Palatino)</option> - <option value="serif" ${i.fontTheme==="serif"?"selected":""}>Serif (Georgia)</option> - <option value="sans" ${i.fontTheme==="sans"?"selected":""}>Sans-Serif (Helvetica)</option> - <option value="mono" ${i.fontTheme==="mono"?"selected":""}>Monospace</option> - </select> - </section> - </div> - `,document.getElementById("theme-options")?.addEventListener("click",n=>{const s=n.target.closest("button");if(s){const r=s.getAttribute("data-theme");i.setTheme(r),T()}});const a=document.getElementById("font-selector");a?.addEventListener("change",()=>{i.setFontTheme(a.value)})}async function C(t){const e=i.items.find(a=>a._id===t);e&&p(t,{starred:!e.starred})}async function N(t){if(i.items.find(a=>a._id===t))try{const a=await h(`/api/item/${t}/content`);if(a.ok){const n=await a.json();n.full_content&&p(t,{full_content:n.full_content})}}catch(a){console.error("Failed to fetch full content",a)}}async function p(t,e){try{if((await h(`/api/item/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok){const n=i.items.find(s=>s._id===t);if(n){Object.assign(n,e);const s=document.querySelector(`.feed-item[data-id="${t}"]`);if(s){if(e.read!==void 0&&s.classList.toggle("read",e.read),e.starred!==void 0){const r=s.querySelector(".star-btn");r&&(r.classList.toggle("is-starred",e.starred),r.classList.toggle("is-unstarred",!e.starred),r.setAttribute("title",e.starred?"Unstar":"Star"))}e.full_content&&y()}}}}catch(a){console.error("Failed to update item",a)}}async function q(){const t=await h("/api/feed/");if(t.ok){const e=await t.json();i.setFeeds(e)}}async function P(){const t=await h("/api/tag");if(t.ok){const e=await t.json();i.setTags(e)}}async function b(t,e,a=!1){i.setLoading(!0);try{const n=new URLSearchParams;t&&n.append("feed_id",t),e&&n.append("tag",e),i.searchQuery&&n.append("q",i.searchQuery),(i.filter==="starred"||i.filter==="all")&&n.append("read_filter","all"),i.filter==="starred"&&n.append("starred","true"),a&&i.items.length>0&&n.append("max_id",String(i.items[i.items.length-1]._id));const s=await h(`/api/stream?${n.toString()}`);if(s.ok){const r=await s.json();i.setHasMore(r.length>=50),i.setItems(r,a)}}finally{i.setLoading(!1)}}async function M(){const t=d.getCurrentRoute();b(t.params.feedId,t.params.tagName,!0)}async function Q(){await h("/api/logout",{method:"POST"}),window.location.href="/login/"}function w(){const t=d.getCurrentRoute(),e=t.query.get("filter");i.setFilter(e||"unread");const a=t.query.get("q");if(a!==null&&i.setSearchQuery(a),t.path==="/settings"){T();return}if(t.path==="/feed"&&t.params.feedId){const n=parseInt(t.params.feedId);i.setActiveFeed(n),b(t.params.feedId),document.getElementById("section-feeds")?.classList.remove("collapsed")}else t.path==="/tag"&&t.params.tagName?(i.setActiveTag(t.params.tagName),b(void 0,t.params.tagName),document.getElementById("section-tags")?.classList.remove("collapsed")):(i.setActiveFeed(null),i.setActiveTag(null),b())}window.addEventListener("keydown",t=>{if(!["INPUT","TEXTAREA"].includes(t.target.tagName))switch(t.key){case"j":I(1);break;case"k":I(-1);break;case"r":if(l){const e=i.items.find(a=>a._id===l);e&&p(e._id,{read:!e.read})}break;case"s":if(l){const e=i.items.find(a=>a._id===l);e&&p(e._id,{starred:!e.starred})}break;case"/":t.preventDefault(),document.getElementById("search-input")?.focus();break}});function I(t){if(i.items.length===0)return;let e=i.items.findIndex(a=>a._id===l);if(e+=t,e>=0&&e<i.items.length){l=i.items[e]._id;const a=document.querySelector(`.feed-item[data-id="${l}"]`);a&&a.scrollIntoView({block:"nearest"}),i.items[e].read||p(l,{read:!0})}else if(e===-1){l=i.items[0]._id;const a=document.querySelector(`.feed-item[data-id="${l}"]`);a&&a.scrollIntoView({block:"nearest"})}}i.on("feeds-updated",L);i.on("tags-updated",E);i.on("active-feed-updated",L);i.on("active-tag-updated",E);i.on("filter-updated",S);i.on("search-updated",()=>{const t=document.getElementById("search-input");t&&t.value!==i.searchQuery&&(t.value=i.searchQuery),w()});i.on("theme-updated",()=>{f||(f=document.querySelector("#app")),f&&(f.className=`theme-${i.theme} font-${i.fontTheme}`)});i.on("sidebar-toggle",()=>{const t=document.querySelector(".layout");t&&(i.sidebarVisible?(t.classList.remove("sidebar-hidden"),t.classList.add("sidebar-visible")):(t.classList.remove("sidebar-visible"),t.classList.add("sidebar-hidden")))});i.on("items-updated",y);i.on("loading-state-changed",y);d.addEventListener("route-changed",w);window.app={navigate:t=>d.navigate(t)};async function O(){const t=await h("/api/auth");if(!t||t.status===401){window.location.href="/login/";return}R(),S();try{await Promise.all([q(),P()])}catch(e){console.error("Initial fetch failed",e)}w()}typeof window<"u"&&!window.__VITEST__&&O(); diff --git a/web/dist/v3/index.html b/web/dist/v3/index.html index 82bd711..7a6d422 100644 --- a/web/dist/v3/index.html +++ b/web/dist/v3/index.html @@ -5,8 +5,8 @@ <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>frontend-vanilla</title> - <script type="module" crossorigin src="/v3/assets/index-IyL2W0f_.js"></script> - <link rel="stylesheet" crossorigin href="/v3/assets/index-Cqbn4jqh.css"> + <script type="module" crossorigin src="/v3/assets/index-BmLjwl8J.js"></script> + <link rel="stylesheet" crossorigin href="/v3/assets/index-CJ8IAAIK.css"> </head> <body> <div id="app"></div> |
