From 0876a683cdc344b200dbd65aa137969a1528c85d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Feb 2026 22:56:56 +0000 Subject: Revert polling interval back to 1s https://claude.ai/code/session_0187FXrbScDSWfbNEk9SfJaj --- frontend-vanilla/src/main.ts | 2 +- frontend-vanilla/src/polling.test.ts | 6 +- frontend-vanilla/src/regression.test.ts | 4 +- web/dist/v3/assets/index-3ySRh1ZH.js | 189 -------------------------------- web/dist/v3/assets/index-DZsQUXOH.js | 189 ++++++++++++++++++++++++++++++++ web/dist/v3/index.html | 2 +- 6 files changed, 196 insertions(+), 196 deletions(-) delete mode 100644 web/dist/v3/assets/index-3ySRh1ZH.js create mode 100644 web/dist/v3/assets/index-DZsQUXOH.js diff --git a/frontend-vanilla/src/main.ts b/frontend-vanilla/src/main.ts index 75707ac..e3d3a71 100644 --- a/frontend-vanilla/src/main.ts +++ b/frontend-vanilla/src/main.ts @@ -397,7 +397,7 @@ if (typeof window !== 'undefined') { } } - }, 3000); + }, 1000); } // ... (add this variable at module level or inside renderSettings if possible, but module level is safer for persistence across clicks if renderSettings re-runs? No, event flow is synchronous: click button -> click file input. User selects file. Change event fires. diff --git a/frontend-vanilla/src/polling.test.ts b/frontend-vanilla/src/polling.test.ts index 44ad7da..fa4b62f 100644 --- a/frontend-vanilla/src/polling.test.ts +++ b/frontend-vanilla/src/polling.test.ts @@ -44,8 +44,8 @@ describe('Infinite Scroll Polling', () => { json: async () => [] } as Response); - // Wait for interval (3000ms) + buffer - await new Promise(resolve => setTimeout(resolve, 3100)); + // Wait for interval (1000ms) + buffer + await new Promise(resolve => setTimeout(resolve, 1100)); // Check if apiFetch was called expect(apiFetch).toHaveBeenCalledWith(expect.stringContaining('/api/stream')); @@ -58,7 +58,7 @@ describe('Infinite Scroll Polling', () => { Object.defineProperty(scrollRoot, 'clientHeight', { value: 200, configurable: true }); Object.defineProperty(scrollRoot, 'scrollTop', { value: 100, configurable: true }); - await new Promise(resolve => setTimeout(resolve, 3100)); + await new Promise(resolve => setTimeout(resolve, 1100)); expect(apiFetch).not.toHaveBeenCalled(); }); diff --git a/frontend-vanilla/src/regression.test.ts b/frontend-vanilla/src/regression.test.ts index 7f72ed5..972b221 100644 --- a/frontend-vanilla/src/regression.test.ts +++ b/frontend-vanilla/src/regression.test.ts @@ -202,8 +202,8 @@ describe('Scroll-to-Read Regression Tests', () => { // Dispatch scroll on WINDOW, not mainContent window.dispatchEvent(new Event('scroll')); - // Wait for potential debounce/poll (3000ms interval + buffer) - await new Promise(resolve => setTimeout(resolve, 3100)); + // Wait for potential debounce/poll + await new Promise(resolve => setTimeout(resolve, 1100)); // Expect it to handle it expect(apiFetch).toHaveBeenCalledWith(expect.stringContaining('/api/item/12345'), expect.objectContaining({ diff --git a/web/dist/v3/assets/index-3ySRh1ZH.js b/web/dist/v3/assets/index-3ySRh1ZH.js deleted file mode 100644 index 21ef42f..0000000 --- a/web/dist/v3/assets/index-3ySRh1ZH.js +++ /dev/null @@ -1,189 +0,0 @@ -(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&i(l)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function i(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();function A(e){const n=`; ${document.cookie}`.split(`; ${e}=`);if(n.length===2)return n.pop()?.split(";").shift()}async function m(e,t){const n=t?.method?.toUpperCase()||"GET",i=["POST","PUT","DELETE"].includes(n),s=new Headers(t?.headers||{});if(i){const o=A("csrf_token");o&&s.set("X-CSRF-Token",o)}return fetch(e,{...t,headers:s,credentials:"include"})}function C(){const e=document.cookie.split("; ").find(t=>t.startsWith("neko_sidebar="));return e?e.split("=")[1]==="1":null}function B(e){document.cookie=`neko_sidebar=${e?"1":"0"}; path=/; max-age=31536000; SameSite=Lax`}function H(){const e=C();return e!==null?e:window.innerWidth>1024}class P 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";headingFontTheme=localStorage.getItem("neko-heading-font-theme")||"default";styleTheme=localStorage.getItem("neko-style-theme")||"default";sidebarVisible=H();setFeeds(t){this.feeds=t,this.emit("feeds-updated")}setTags(t){this.tags=t,this.emit("tags-updated")}setItems(t,n=!1){n?this.items=[...this.items,...t]:this.items=t,this.emit("items-updated")}setActiveFeed(t){this.activeFeedId=t,this.activeTagName=null,this.emit("active-feed-updated")}setActiveTag(t){this.activeTagName=t,this.activeFeedId=null,this.emit("active-tag-updated")}setFilter(t){this.filter!==t&&(this.filter=t,this.emit("filter-updated"))}setSearchQuery(t){this.searchQuery!==t&&(this.searchQuery=t,this.emit("search-updated"))}setLoading(t){this.loading=t,this.emit("loading-state-changed")}setHasMore(t){this.hasMore=t}setTheme(t){this.theme=t,localStorage.setItem("neko-theme",t),this.emit("theme-updated")}setFontTheme(t){this.fontTheme=t,localStorage.setItem("neko-font-theme",t),this.emit("theme-updated")}setHeadingFontTheme(t){this.headingFontTheme=t,localStorage.setItem("neko-heading-font-theme",t),this.emit("theme-updated")}setStyleTheme(t){this.styleTheme=t,localStorage.setItem("neko-style-theme",t),this.emit("style-theme-updated")}setSidebarVisible(t){this.sidebarVisible=t,B(t),this.emit("sidebar-toggle")}toggleSidebar(){this.setSidebarVisible(!this.sidebarVisible)}emit(t,n){this.dispatchEvent(new CustomEvent(t,{detail:n}))}on(t,n){this.addEventListener(t,n)}}const a=new P;class M extends EventTarget{constructor(){super(),window.addEventListener("popstate",()=>this.handleRouteChange())}handleRouteChange(){this.dispatchEvent(new CustomEvent("route-changed",{detail:this.getCurrentRoute()}))}getCurrentRoute(){const t=new URL(window.location.href),i=t.pathname.replace(/^\/v3\//,"").split("/").filter(Boolean);let s="/";const o={};return i[0]==="feed"&&i[1]?(s="/feed",o.feedId=i[1]):i[0]==="tag"&&i[1]?(s="/tag",o.tagName=decodeURIComponent(i[1])):i[0]==="settings"&&(s="/settings"),{path:s,params:o,query:t.searchParams}}navigate(t,n){let i=`/v3${t}`;if(n){const s=new URLSearchParams(n);i+=`?${s.toString()}`}window.history.pushState({},"",i),this.handleRouteChange()}updateQuery(t){const n=new URL(window.location.href);for(const[i,s]of Object.entries(t))s?n.searchParams.set(i,s):n.searchParams.delete(i);window.history.pushState({},"",n.toString()),this.handleRouteChange()}}const r=new M;function O(e){const t=new Date(e.publish_date).toLocaleDateString();return` -
  • - - - ${e.full_content||e.description?` -
    - ${e.full_content||e.description} -
    - `:""} -
  • - `}const q=["default","refined","terminal","codex","sakura"];function w(e){const t=document.getElementById("style-theme-link");if(t&&t.remove(),e==="default")return;const n=document.createElement("link");n.id="style-theme-link",n.rel="stylesheet",n.href=`/v3/themes/${e}.css`,document.head.appendChild(n)}let u=null,g=null;function D(){g=document.querySelector("#app"),g&&(g.className=`theme-${a.theme} font-${a.fontTheme} heading-font-${a.headingFontTheme}`,g.innerHTML=` -
    - - - -
    -
    -
    -
    - `,x())}function x(){document.getElementById("search-input")?.addEventListener("input",s=>{const o=s.target.value;r.updateQuery({q:o})}),document.getElementById("logo-link")?.addEventListener("click",()=>r.navigate("/")),document.getElementById("logout-button")?.addEventListener("click",s=>{s.preventDefault(),J()}),document.querySelectorAll(".sidebar-theme-btn").forEach(s=>{s.addEventListener("click",()=>{const o=s.getAttribute("data-theme");o&&a.setTheme(o)})}),document.querySelectorAll(".sidebar-style-btn").forEach(s=>{s.addEventListener("click",()=>{const o=s.getAttribute("data-style-theme");o&&a.setStyleTheme(o)})}),document.getElementById("sidebar-toggle-btn")?.addEventListener("click",()=>{a.toggleSidebar()}),document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>{a.setSidebarVisible(!1)}),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,l=o.closest("a");if(!l){o.classList.contains("logo")&&(s.preventDefault(),r.navigate("/",{}));return}const f=l.getAttribute("data-nav"),h=Object.fromEntries(r.getCurrentRoute().query.entries());if(f==="filter"){s.preventDefault();const c=l.getAttribute("data-value");r.getCurrentRoute().path==="/settings"?r.navigate("/",{...h,filter:c}):r.updateQuery({filter:c})}else if(f==="tag"){s.preventDefault();const c=l.getAttribute("data-value");r.navigate(`/tag/${encodeURIComponent(c)}`,h)}else if(f==="feed"){s.preventDefault();const c=l.getAttribute("data-value"),d=r.getCurrentRoute();a.activeFeedId===parseInt(c)&&d.path!=="/settings"?r.navigate("/",h):r.navigate(`/feed/${c}`,h)}else f==="settings"&&(s.preventDefault(),r.getCurrentRoute().path==="/settings"?r.navigate("/",h):r.navigate("/settings",h));window.innerWidth<=768&&a.setSidebarVisible(!1)}),document.getElementById("content-area")?.addEventListener("click",s=>{const o=s.target,l=o.closest('[data-action="toggle-star"]');if(l){const d=l.closest("[data-id]");if(d){const b=parseInt(d.getAttribute("data-id"));U(b)}return}const f=o.closest('[data-action="scrape"]');if(f){const d=f.closest("[data-id]");if(d){const b=parseInt(d.getAttribute("data-id"));V(b)}return}const h=o.closest('[data-action="open"]'),c=o.closest(".feed-item");if(c&&!h){const d=parseInt(c.getAttribute("data-id"));u=d,u=d;const b=a.items.find(_=>_._id===d);b&&!b.read&&p(d,{read:!0})}})}function L(){const{feeds:e,activeFeedId:t}=a,n=document.getElementById("feed-list");n&&(n.innerHTML=e.map(i=>` -
  • - - ${i.title||i.url} - -
  • - `).join(""))}function $(){}function F(){const{filter:e}=a,t=document.getElementById("filter-list");t&&t.querySelectorAll("li").forEach(n=>{n.classList.toggle("active",n.getAttribute("data-filter")===e)})}function S(){const{items:e,loading:t}=a,n=document.getElementById("content-area");if(!n||r.getCurrentRoute().path==="/settings")return;if(t&&e.length===0){n.innerHTML='

    Loading items...

    ';return}if(e.length===0){n.innerHTML='

    No items found.

    ';return}n.innerHTML=` - - ${a.hasMore?'
    Loading more...
    ':""} - `;const i=document.getElementById("main-content");if(i){let s=null;i.onscroll=()=>{!a.loading&&a.hasMore&&i.scrollHeight>i.clientHeight&&i.scrollHeight-i.scrollTop-i.clientHeight<200&&E(),s===null&&(s=window.setTimeout(()=>{R(i),s=null},250))}}}function R(e){const t=e.getBoundingClientRect(),n=e.querySelectorAll(".feed-item");for(const i of n){const s=parseInt(i.getAttribute("data-id")),o=a.items.find(f=>f._id===s);if(!o||o.read)continue;i.getBoundingClientRect().bottom{const e=document.getElementById("main-content");if(a.loading||!a.hasMore)return;if(e&&(R(e),e.scrollHeight>e.clientHeight&&e.scrollHeight-e.scrollTop-e.clientHeight<200)){E();return}const t=document.documentElement.scrollHeight||document.body.scrollHeight,n=window.innerHeight,i=window.scrollY||document.documentElement.scrollTop;t>n&&t-n-i<200&&E()},3e3);function v(){const e=document.getElementById("content-area");if(!e)return;e.innerHTML=` -
    -

    Settings

    - -
    -
    -

    Data

    - -
    -
    - - - -
    - -
    -
    - -
    -

    Theme

    -
    -
    - - -
    -
    -
    - -
    -

    Style

    -
    -
    - ${q.map(i=>``).join(` - `)} -
    -
    -
    - -
    -

    Fonts

    -
    - - - - - -
    -
    -
    - -
    -

    Manage Feeds

    - -
    - - -
    - -
      - ${a.feeds.map(i=>` -
    • -
      -
      ${i.title||i.url}
      -
      ${i.url}
      -
      -
      - - -
      -
    • - `).join("")} -
    -
    -
    - `,document.getElementById("theme-options")?.addEventListener("click",i=>{const s=i.target.closest("button");s&&(a.setTheme(s.getAttribute("data-theme")),v())}),document.getElementById("style-theme-options")?.addEventListener("click",i=>{const s=i.target.closest("button");s&&a.setStyleTheme(s.getAttribute("data-style-theme"))}),document.getElementById("heading-font-selector")?.addEventListener("change",i=>{a.setHeadingFontTheme(i.target.value)}),document.getElementById("font-selector")?.addEventListener("change",i=>{a.setFontTheme(i.target.value)}),document.getElementById("add-feed-btn")?.addEventListener("click",async()=>{const i=document.getElementById("new-feed-url"),s=i.value.trim();s&&(await N(s)?(i.value="",alert("Feed added successfully!"),y()):alert("Failed to add feed."))});let t="opml";const n=document.getElementById("import-file");document.querySelectorAll(".import-btn").forEach(i=>{i.addEventListener("click",s=>{t=s.currentTarget.getAttribute("data-format")||"opml",n.click()})}),n?.addEventListener("change",async i=>{const s=i.target.files?.[0];s&&(await j(s,t)?(alert(`Import (${t}) started! check logs.`),y()):alert("Failed to import.")),n.value=""}),document.querySelectorAll(".delete-feed-btn").forEach(i=>{i.addEventListener("click",async s=>{const o=parseInt(s.target.getAttribute("data-id"));confirm("Delete this feed?")&&(await Q(o),await y(),v())})})}async function N(e){try{return(await m("/api/feed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})})).ok}catch(t){return console.error("Failed to add feed",t),!1}}async function j(e,t){try{const n=new FormData;n.append("file",e),n.append("format",t);const i=document.cookie.split("; ").find(o=>o.startsWith("csrf_token="))?.split("=")[1];return(await fetch("/api/import",{method:"POST",headers:{"X-CSRF-Token":i||""},body:n})).ok}catch(n){return console.error("Failed to import",n),!1}}async function Q(e){try{return(await m(`/api/feed/${e}`,{method:"DELETE"})).ok}catch(t){return console.error("Failed to delete feed",t),!1}}async function U(e){const t=a.items.find(n=>n._id===e);t&&p(e,{starred:!t.starred})}async function V(e){if(a.items.find(n=>n._id===e))try{const n=await m(`/api/item/${e}/content`);if(n.ok){const i=await n.json();i.full_content&&p(e,{full_content:i.full_content})}}catch(n){console.error("Failed to fetch full content",n)}}async function p(e,t){try{if((await m(`/api/item/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok){const i=a.items.find(s=>s._id===e);if(i){Object.assign(i,t);const s=document.querySelector(`.feed-item[data-id="${e}"]`);if(s){if(t.read!==void 0&&s.classList.toggle("read",t.read),t.starred!==void 0){const o=s.querySelector(".star-btn");o&&(o.classList.toggle("is-starred",t.starred),o.classList.toggle("is-unstarred",!t.starred),o.setAttribute("title",t.starred?"Unstar":"Star"))}t.full_content&&S()}}}}catch(n){console.error("Failed to update item",n)}}async function y(){const e=await m("/api/feed/");if(e.ok){const t=await e.json();a.setFeeds(t)}}async function X(){const e=await m("/api/tag");if(e.ok){const t=await e.json();a.setTags(t)}}async function T(e,t,n=!1){a.setLoading(!0);try{const i=new URLSearchParams;e&&i.append("feed_id",e),t&&i.append("tag",t),a.searchQuery&&i.append("q",a.searchQuery),(a.filter==="starred"||a.filter==="all")&&i.append("read_filter","all"),a.filter==="starred"&&i.append("starred","true"),n&&a.items.length>0&&i.append("max_id",String(a.items[a.items.length-1]._id));const s=await m(`/api/stream?${i.toString()}`);if(s.ok){const o=await s.json();a.setHasMore(o.length>0),a.setItems(o,n)}}finally{a.setLoading(!1)}}async function E(){const e=r.getCurrentRoute();T(e.params.feedId,e.params.tagName,!0)}async function J(){await m("/api/logout",{method:"POST"}),window.location.href="/login/"}function I(){const e=r.getCurrentRoute(),t=e.query.get("filter");a.setFilter(t||"unread");const n=e.query.get("q");if(n!==null&&a.setSearchQuery(n),e.path==="/settings"){v();return}if(e.path==="/feed"&&e.params.feedId){const i=parseInt(e.params.feedId);a.setActiveFeed(i),T(e.params.feedId),document.getElementById("section-feeds")?.classList.remove("collapsed")}else e.path==="/tag"&&e.params.tagName?(a.setActiveTag(e.params.tagName),T(void 0,e.params.tagName),document.getElementById("section-tags")?.classList.remove("collapsed")):(a.setActiveFeed(null),a.setActiveTag(null),T())}window.addEventListener("keydown",e=>{if(!["INPUT","TEXTAREA"].includes(e.target.tagName))switch(e.key){case"j":k(1);break;case"k":k(-1);break;case"r":if(u){const t=a.items.find(n=>n._id===u);t&&p(t._id,{read:!t.read})}break;case"s":if(u){const t=a.items.find(n=>n._id===u);t&&p(t._id,{starred:!t.starred})}break;case"/":e.preventDefault(),document.getElementById("search-input")?.focus();break}});function k(e){if(a.items.length===0)return;const t=a.items.findIndex(i=>i._id===u);let n;if(t===-1?n=e>0?0:a.items.length-1:n=t+e,n>=0&&n{const e=document.getElementById("search-input");e&&e.value!==a.searchQuery&&(e.value=a.searchQuery),I()});a.on("theme-updated",()=>{g||(g=document.querySelector("#app")),g&&(g.className=`theme-${a.theme} font-${a.fontTheme} heading-font-${a.headingFontTheme}`),document.querySelectorAll(".sidebar-theme-btn").forEach(e=>{e.classList.toggle("active",e.getAttribute("data-theme")===a.theme)}),r.getCurrentRoute().path==="/settings"&&v()});a.on("sidebar-toggle",()=>{const e=document.querySelector(".layout");e&&(a.sidebarVisible?(e.classList.remove("sidebar-hidden"),e.classList.add("sidebar-visible")):(e.classList.remove("sidebar-visible"),e.classList.add("sidebar-hidden")))});a.on("style-theme-updated",()=>{w(a.styleTheme),document.querySelectorAll(".sidebar-style-btn").forEach(e=>{e.classList.toggle("active",e.getAttribute("data-style-theme")===a.styleTheme)}),r.getCurrentRoute().path==="/settings"&&v()});a.on("items-updated",S);a.on("loading-state-changed",S);r.addEventListener("route-changed",I);window.app={navigate:e=>r.navigate(e)};async function W(){const e=await m("/api/auth");if(!e||e.status===401){window.location.href="/login/";return}D(),w(a.styleTheme),F();try{await Promise.all([y(),X()])}catch(t){console.error("Initial fetch failed",t)}I()}typeof window<"u"&&!window.__VITEST__&&W(); diff --git a/web/dist/v3/assets/index-DZsQUXOH.js b/web/dist/v3/assets/index-DZsQUXOH.js new file mode 100644 index 0000000..95719d5 --- /dev/null +++ b/web/dist/v3/assets/index-DZsQUXOH.js @@ -0,0 +1,189 @@ +(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&i(l)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function i(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();function A(e){const n=`; ${document.cookie}`.split(`; ${e}=`);if(n.length===2)return n.pop()?.split(";").shift()}async function m(e,t){const n=t?.method?.toUpperCase()||"GET",i=["POST","PUT","DELETE"].includes(n),s=new Headers(t?.headers||{});if(i){const o=A("csrf_token");o&&s.set("X-CSRF-Token",o)}return fetch(e,{...t,headers:s,credentials:"include"})}function C(){const e=document.cookie.split("; ").find(t=>t.startsWith("neko_sidebar="));return e?e.split("=")[1]==="1":null}function B(e){document.cookie=`neko_sidebar=${e?"1":"0"}; path=/; max-age=31536000; SameSite=Lax`}function H(){const e=C();return e!==null?e:window.innerWidth>1024}class P 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";headingFontTheme=localStorage.getItem("neko-heading-font-theme")||"default";styleTheme=localStorage.getItem("neko-style-theme")||"default";sidebarVisible=H();setFeeds(t){this.feeds=t,this.emit("feeds-updated")}setTags(t){this.tags=t,this.emit("tags-updated")}setItems(t,n=!1){n?this.items=[...this.items,...t]:this.items=t,this.emit("items-updated")}setActiveFeed(t){this.activeFeedId=t,this.activeTagName=null,this.emit("active-feed-updated")}setActiveTag(t){this.activeTagName=t,this.activeFeedId=null,this.emit("active-tag-updated")}setFilter(t){this.filter!==t&&(this.filter=t,this.emit("filter-updated"))}setSearchQuery(t){this.searchQuery!==t&&(this.searchQuery=t,this.emit("search-updated"))}setLoading(t){this.loading=t,this.emit("loading-state-changed")}setHasMore(t){this.hasMore=t}setTheme(t){this.theme=t,localStorage.setItem("neko-theme",t),this.emit("theme-updated")}setFontTheme(t){this.fontTheme=t,localStorage.setItem("neko-font-theme",t),this.emit("theme-updated")}setHeadingFontTheme(t){this.headingFontTheme=t,localStorage.setItem("neko-heading-font-theme",t),this.emit("theme-updated")}setStyleTheme(t){this.styleTheme=t,localStorage.setItem("neko-style-theme",t),this.emit("style-theme-updated")}setSidebarVisible(t){this.sidebarVisible=t,B(t),this.emit("sidebar-toggle")}toggleSidebar(){this.setSidebarVisible(!this.sidebarVisible)}emit(t,n){this.dispatchEvent(new CustomEvent(t,{detail:n}))}on(t,n){this.addEventListener(t,n)}}const a=new P;class M extends EventTarget{constructor(){super(),window.addEventListener("popstate",()=>this.handleRouteChange())}handleRouteChange(){this.dispatchEvent(new CustomEvent("route-changed",{detail:this.getCurrentRoute()}))}getCurrentRoute(){const t=new URL(window.location.href),i=t.pathname.replace(/^\/v3\//,"").split("/").filter(Boolean);let s="/";const o={};return i[0]==="feed"&&i[1]?(s="/feed",o.feedId=i[1]):i[0]==="tag"&&i[1]?(s="/tag",o.tagName=decodeURIComponent(i[1])):i[0]==="settings"&&(s="/settings"),{path:s,params:o,query:t.searchParams}}navigate(t,n){let i=`/v3${t}`;if(n){const s=new URLSearchParams(n);i+=`?${s.toString()}`}window.history.pushState({},"",i),this.handleRouteChange()}updateQuery(t){const n=new URL(window.location.href);for(const[i,s]of Object.entries(t))s?n.searchParams.set(i,s):n.searchParams.delete(i);window.history.pushState({},"",n.toString()),this.handleRouteChange()}}const r=new M;function O(e){const t=new Date(e.publish_date).toLocaleDateString();return` +
  • + + + ${e.full_content||e.description?` +
    + ${e.full_content||e.description} +
    + `:""} +
  • + `}const q=["default","refined","terminal","codex","sakura"];function w(e){const t=document.getElementById("style-theme-link");if(t&&t.remove(),e==="default")return;const n=document.createElement("link");n.id="style-theme-link",n.rel="stylesheet",n.href=`/v3/themes/${e}.css`,document.head.appendChild(n)}let u=null,g=null;function D(){g=document.querySelector("#app"),g&&(g.className=`theme-${a.theme} font-${a.fontTheme} heading-font-${a.headingFontTheme}`,g.innerHTML=` +
    + + + +
    +
    +
    +
    + `,x())}function x(){document.getElementById("search-input")?.addEventListener("input",s=>{const o=s.target.value;r.updateQuery({q:o})}),document.getElementById("logo-link")?.addEventListener("click",()=>r.navigate("/")),document.getElementById("logout-button")?.addEventListener("click",s=>{s.preventDefault(),J()}),document.querySelectorAll(".sidebar-theme-btn").forEach(s=>{s.addEventListener("click",()=>{const o=s.getAttribute("data-theme");o&&a.setTheme(o)})}),document.querySelectorAll(".sidebar-style-btn").forEach(s=>{s.addEventListener("click",()=>{const o=s.getAttribute("data-style-theme");o&&a.setStyleTheme(o)})}),document.getElementById("sidebar-toggle-btn")?.addEventListener("click",()=>{a.toggleSidebar()}),document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>{a.setSidebarVisible(!1)}),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,l=o.closest("a");if(!l){o.classList.contains("logo")&&(s.preventDefault(),r.navigate("/",{}));return}const f=l.getAttribute("data-nav"),h=Object.fromEntries(r.getCurrentRoute().query.entries());if(f==="filter"){s.preventDefault();const c=l.getAttribute("data-value");r.getCurrentRoute().path==="/settings"?r.navigate("/",{...h,filter:c}):r.updateQuery({filter:c})}else if(f==="tag"){s.preventDefault();const c=l.getAttribute("data-value");r.navigate(`/tag/${encodeURIComponent(c)}`,h)}else if(f==="feed"){s.preventDefault();const c=l.getAttribute("data-value"),d=r.getCurrentRoute();a.activeFeedId===parseInt(c)&&d.path!=="/settings"?r.navigate("/",h):r.navigate(`/feed/${c}`,h)}else f==="settings"&&(s.preventDefault(),r.getCurrentRoute().path==="/settings"?r.navigate("/",h):r.navigate("/settings",h));window.innerWidth<=768&&a.setSidebarVisible(!1)}),document.getElementById("content-area")?.addEventListener("click",s=>{const o=s.target,l=o.closest('[data-action="toggle-star"]');if(l){const d=l.closest("[data-id]");if(d){const b=parseInt(d.getAttribute("data-id"));U(b)}return}const f=o.closest('[data-action="scrape"]');if(f){const d=f.closest("[data-id]");if(d){const b=parseInt(d.getAttribute("data-id"));V(b)}return}const h=o.closest('[data-action="open"]'),c=o.closest(".feed-item");if(c&&!h){const d=parseInt(c.getAttribute("data-id"));u=d,u=d;const b=a.items.find(_=>_._id===d);b&&!b.read&&p(d,{read:!0})}})}function L(){const{feeds:e,activeFeedId:t}=a,n=document.getElementById("feed-list");n&&(n.innerHTML=e.map(i=>` +
  • + + ${i.title||i.url} + +
  • + `).join(""))}function $(){}function F(){const{filter:e}=a,t=document.getElementById("filter-list");t&&t.querySelectorAll("li").forEach(n=>{n.classList.toggle("active",n.getAttribute("data-filter")===e)})}function S(){const{items:e,loading:t}=a,n=document.getElementById("content-area");if(!n||r.getCurrentRoute().path==="/settings")return;if(t&&e.length===0){n.innerHTML='

    Loading items...

    ';return}if(e.length===0){n.innerHTML='

    No items found.

    ';return}n.innerHTML=` +
      + ${e.map(s=>O(s)).join("")} +
    + ${a.hasMore?'
    Loading more...
    ':""} + `;const i=document.getElementById("main-content");if(i){let s=null;i.onscroll=()=>{!a.loading&&a.hasMore&&i.scrollHeight>i.clientHeight&&i.scrollHeight-i.scrollTop-i.clientHeight<200&&E(),s===null&&(s=window.setTimeout(()=>{R(i),s=null},250))}}}function R(e){const t=e.getBoundingClientRect(),n=e.querySelectorAll(".feed-item");for(const i of n){const s=parseInt(i.getAttribute("data-id")),o=a.items.find(f=>f._id===s);if(!o||o.read)continue;i.getBoundingClientRect().bottom{const e=document.getElementById("main-content");if(a.loading||!a.hasMore)return;if(e&&(R(e),e.scrollHeight>e.clientHeight&&e.scrollHeight-e.scrollTop-e.clientHeight<200)){E();return}const t=document.documentElement.scrollHeight||document.body.scrollHeight,n=window.innerHeight,i=window.scrollY||document.documentElement.scrollTop;t>n&&t-n-i<200&&E()},1e3);function v(){const e=document.getElementById("content-area");if(!e)return;e.innerHTML=` +
    +

    Settings

    + +
    +
    +

    Data

    + +
    +
    + + + +
    + +
    +
    + +
    +

    Theme

    +
    +
    + + +
    +
    +
    + +
    +

    Style

    +
    +
    + ${q.map(i=>``).join(` + `)} +
    +
    +
    + +
    +

    Fonts

    +
    + + + + + +
    +
    +
    + +
    +

    Manage Feeds

    + +
    + + +
    + +
      + ${a.feeds.map(i=>` +
    • +
      +
      ${i.title||i.url}
      +
      ${i.url}
      +
      +
      + + +
      +
    • + `).join("")} +
    +
    +
    + `,document.getElementById("theme-options")?.addEventListener("click",i=>{const s=i.target.closest("button");s&&(a.setTheme(s.getAttribute("data-theme")),v())}),document.getElementById("style-theme-options")?.addEventListener("click",i=>{const s=i.target.closest("button");s&&a.setStyleTheme(s.getAttribute("data-style-theme"))}),document.getElementById("heading-font-selector")?.addEventListener("change",i=>{a.setHeadingFontTheme(i.target.value)}),document.getElementById("font-selector")?.addEventListener("change",i=>{a.setFontTheme(i.target.value)}),document.getElementById("add-feed-btn")?.addEventListener("click",async()=>{const i=document.getElementById("new-feed-url"),s=i.value.trim();s&&(await N(s)?(i.value="",alert("Feed added successfully!"),y()):alert("Failed to add feed."))});let t="opml";const n=document.getElementById("import-file");document.querySelectorAll(".import-btn").forEach(i=>{i.addEventListener("click",s=>{t=s.currentTarget.getAttribute("data-format")||"opml",n.click()})}),n?.addEventListener("change",async i=>{const s=i.target.files?.[0];s&&(await j(s,t)?(alert(`Import (${t}) started! check logs.`),y()):alert("Failed to import.")),n.value=""}),document.querySelectorAll(".delete-feed-btn").forEach(i=>{i.addEventListener("click",async s=>{const o=parseInt(s.target.getAttribute("data-id"));confirm("Delete this feed?")&&(await Q(o),await y(),v())})})}async function N(e){try{return(await m("/api/feed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})})).ok}catch(t){return console.error("Failed to add feed",t),!1}}async function j(e,t){try{const n=new FormData;n.append("file",e),n.append("format",t);const i=document.cookie.split("; ").find(o=>o.startsWith("csrf_token="))?.split("=")[1];return(await fetch("/api/import",{method:"POST",headers:{"X-CSRF-Token":i||""},body:n})).ok}catch(n){return console.error("Failed to import",n),!1}}async function Q(e){try{return(await m(`/api/feed/${e}`,{method:"DELETE"})).ok}catch(t){return console.error("Failed to delete feed",t),!1}}async function U(e){const t=a.items.find(n=>n._id===e);t&&p(e,{starred:!t.starred})}async function V(e){if(a.items.find(n=>n._id===e))try{const n=await m(`/api/item/${e}/content`);if(n.ok){const i=await n.json();i.full_content&&p(e,{full_content:i.full_content})}}catch(n){console.error("Failed to fetch full content",n)}}async function p(e,t){try{if((await m(`/api/item/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok){const i=a.items.find(s=>s._id===e);if(i){Object.assign(i,t);const s=document.querySelector(`.feed-item[data-id="${e}"]`);if(s){if(t.read!==void 0&&s.classList.toggle("read",t.read),t.starred!==void 0){const o=s.querySelector(".star-btn");o&&(o.classList.toggle("is-starred",t.starred),o.classList.toggle("is-unstarred",!t.starred),o.setAttribute("title",t.starred?"Unstar":"Star"))}t.full_content&&S()}}}}catch(n){console.error("Failed to update item",n)}}async function y(){const e=await m("/api/feed/");if(e.ok){const t=await e.json();a.setFeeds(t)}}async function X(){const e=await m("/api/tag");if(e.ok){const t=await e.json();a.setTags(t)}}async function T(e,t,n=!1){a.setLoading(!0);try{const i=new URLSearchParams;e&&i.append("feed_id",e),t&&i.append("tag",t),a.searchQuery&&i.append("q",a.searchQuery),(a.filter==="starred"||a.filter==="all")&&i.append("read_filter","all"),a.filter==="starred"&&i.append("starred","true"),n&&a.items.length>0&&i.append("max_id",String(a.items[a.items.length-1]._id));const s=await m(`/api/stream?${i.toString()}`);if(s.ok){const o=await s.json();a.setHasMore(o.length>0),a.setItems(o,n)}}finally{a.setLoading(!1)}}async function E(){const e=r.getCurrentRoute();T(e.params.feedId,e.params.tagName,!0)}async function J(){await m("/api/logout",{method:"POST"}),window.location.href="/login/"}function I(){const e=r.getCurrentRoute(),t=e.query.get("filter");a.setFilter(t||"unread");const n=e.query.get("q");if(n!==null&&a.setSearchQuery(n),e.path==="/settings"){v();return}if(e.path==="/feed"&&e.params.feedId){const i=parseInt(e.params.feedId);a.setActiveFeed(i),T(e.params.feedId),document.getElementById("section-feeds")?.classList.remove("collapsed")}else e.path==="/tag"&&e.params.tagName?(a.setActiveTag(e.params.tagName),T(void 0,e.params.tagName),document.getElementById("section-tags")?.classList.remove("collapsed")):(a.setActiveFeed(null),a.setActiveTag(null),T())}window.addEventListener("keydown",e=>{if(!["INPUT","TEXTAREA"].includes(e.target.tagName))switch(e.key){case"j":k(1);break;case"k":k(-1);break;case"r":if(u){const t=a.items.find(n=>n._id===u);t&&p(t._id,{read:!t.read})}break;case"s":if(u){const t=a.items.find(n=>n._id===u);t&&p(t._id,{starred:!t.starred})}break;case"/":e.preventDefault(),document.getElementById("search-input")?.focus();break}});function k(e){if(a.items.length===0)return;const t=a.items.findIndex(i=>i._id===u);let n;if(t===-1?n=e>0?0:a.items.length-1:n=t+e,n>=0&&n{const e=document.getElementById("search-input");e&&e.value!==a.searchQuery&&(e.value=a.searchQuery),I()});a.on("theme-updated",()=>{g||(g=document.querySelector("#app")),g&&(g.className=`theme-${a.theme} font-${a.fontTheme} heading-font-${a.headingFontTheme}`),document.querySelectorAll(".sidebar-theme-btn").forEach(e=>{e.classList.toggle("active",e.getAttribute("data-theme")===a.theme)}),r.getCurrentRoute().path==="/settings"&&v()});a.on("sidebar-toggle",()=>{const e=document.querySelector(".layout");e&&(a.sidebarVisible?(e.classList.remove("sidebar-hidden"),e.classList.add("sidebar-visible")):(e.classList.remove("sidebar-visible"),e.classList.add("sidebar-hidden")))});a.on("style-theme-updated",()=>{w(a.styleTheme),document.querySelectorAll(".sidebar-style-btn").forEach(e=>{e.classList.toggle("active",e.getAttribute("data-style-theme")===a.styleTheme)}),r.getCurrentRoute().path==="/settings"&&v()});a.on("items-updated",S);a.on("loading-state-changed",S);r.addEventListener("route-changed",I);window.app={navigate:e=>r.navigate(e)};async function W(){const e=await m("/api/auth");if(!e||e.status===401){window.location.href="/login/";return}D(),w(a.styleTheme),F();try{await Promise.all([y(),X()])}catch(t){console.error("Initial fetch failed",t)}I()}typeof window<"u"&&!window.__VITEST__&&W(); diff --git a/web/dist/v3/index.html b/web/dist/v3/index.html index 25a0b86..8c1f6a6 100644 --- a/web/dist/v3/index.html +++ b/web/dist/v3/index.html @@ -5,7 +5,7 @@ neko - + -- cgit v1.2.3