From 3bd52a03323a9983aa7896af4d3fc3668e4c1252 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Tue, 17 Feb 2026 11:41:50 -0800 Subject: Fix regression: mark-as-read not triggering on window scroll --- web/dist/v3/assets/index-B6bjNxMB.js | 148 +++++++++++++++++++++++++++++++++++ web/dist/v3/assets/index-BX4-fuJu.js | 148 ----------------------------------- web/dist/v3/index.html | 2 +- 3 files changed, 149 insertions(+), 149 deletions(-) create mode 100644 web/dist/v3/assets/index-B6bjNxMB.js delete mode 100644 web/dist/v3/assets/index-BX4-fuJu.js (limited to 'web') diff --git a/web/dist/v3/assets/index-B6bjNxMB.js b/web/dist/v3/assets/index-B6bjNxMB.js new file mode 100644 index 0000000..95b79f8 --- /dev/null +++ b/web/dist/v3/assets/index-B6bjNxMB.js @@ -0,0 +1,148 @@ +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))a(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const d of o.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&a(d)}).observe(document,{childList:!0,subtree:!0});function i(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function a(n){if(n.ep)return;n.ep=!0;const o=i(n);fetch(n.href,o)}})();function C(t){const i=`; ${document.cookie}`.split(`; ${t}=`);if(i.length===2)return i.pop()?.split(";").shift()}async function f(t,e){const i=e?.method?.toUpperCase()||"GET",a=["POST","PUT","DELETE"].includes(i),n=new Headers(e?.headers||{});if(a){const o=C("csrf_token");o&&n.set("X-CSRF-Token",o)}return fetch(t,{...e,headers:n,credentials:"include"})}function B(){const t=document.cookie.split("; ").find(e=>e.startsWith("neko_sidebar="));return t?t.split("=")[1]==="1":null}function P(t){document.cookie=`neko_sidebar=${t?"1":"0"}; path=/; max-age=31536000; SameSite=Lax`}function x(){const t=B();return t!==null?t:window.innerWidth>1024}class M 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=x();setFeeds(e){this.feeds=e,this.emit("feeds-updated")}setTags(e){this.tags=e,this.emit("tags-updated")}setItems(e,i=!1){i?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,P(e),this.emit("sidebar-toggle")}toggleSidebar(){this.setSidebarVisible(!this.sidebarVisible)}emit(e,i){this.dispatchEvent(new CustomEvent(e,{detail:i}))}on(e,i){this.addEventListener(e,i)}}const s=new M;class H 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),a=e.pathname.replace(/^\/v3\//,"").split("/").filter(Boolean);let n="/";const o={};return a[0]==="feed"&&a[1]?(n="/feed",o.feedId=a[1]):a[0]==="tag"&&a[1]?(n="/tag",o.tagName=decodeURIComponent(a[1])):a[0]==="settings"&&(n="/settings"),{path:n,params:o,query:e.searchParams}}navigate(e,i){let a=`/v3${e}`;if(i){const n=new URLSearchParams(i);a+=`?${n.toString()}`}window.history.pushState({},"",a),this.handleRouteChange()}updateQuery(e){const i=new URL(window.location.href);for(const[a,n]of Object.entries(e))n?i.searchParams.set(a,n):i.searchParams.delete(a);window.history.pushState({},"",i.toString()),this.handleRouteChange()}}const r=new H;function q(t,e=!1){const i=new Date(t.publish_date).toLocaleDateString();return` +
  • + + + ${t.full_content||t.description?` +
    + ${t.full_content||t.description} +
    + `:""} +
  • + `}let c=null,g=null;function O(){g=document.querySelector("#app"),g&&(g.className=`theme-${s.theme} font-${s.fontTheme}`,g.innerHTML=` +
    + + + +
    +
    +
    +
    + `,N())}function N(){document.getElementById("search-input")?.addEventListener("input",n=>{const o=n.target.value;r.updateQuery({q:o})}),document.getElementById("logo-link")?.addEventListener("click",()=>r.navigate("/")),document.getElementById("logout-button")?.addEventListener("click",n=>{n.preventDefault(),J()}),document.getElementById("sidebar-toggle-btn")?.addEventListener("click",()=>{s.toggleSidebar()}),document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>{s.setSidebarVisible(!1)}),document.querySelectorAll(".sidebar-section.collapsible h3").forEach(n=>{n.addEventListener("click",()=>{n.parentElement?.classList.toggle("collapsed")})}),document.getElementById("sidebar")?.addEventListener("click",n=>{const o=n.target,d=o.closest("a");if(!d){o.classList.contains("logo")&&(n.preventDefault(),r.navigate("/",{}));return}const p=d.getAttribute("data-nav"),m=Object.fromEntries(r.getCurrentRoute().query.entries());if(p==="filter"){n.preventDefault();const u=d.getAttribute("data-value");r.getCurrentRoute().path==="/settings"?r.navigate("/",{...m,filter:u}):r.updateQuery({filter:u})}else if(p==="tag"){n.preventDefault();const u=d.getAttribute("data-value");r.navigate(`/tag/${encodeURIComponent(u)}`,m)}else if(p==="feed"){n.preventDefault();const u=d.getAttribute("data-value"),l=r.getCurrentRoute();s.activeFeedId===parseInt(u)&&l.path!=="/settings"?r.navigate("/",m):r.navigate(`/feed/${u}`,m)}else p==="settings"&&(n.preventDefault(),r.getCurrentRoute().path==="/settings"?r.navigate("/",m):r.navigate("/settings",m));window.innerWidth<=768&&s.setSidebarVisible(!1)}),document.getElementById("content-area")?.addEventListener("click",n=>{const o=n.target,d=o.closest('[data-action="toggle-star"]');if(d){const l=d.closest("[data-id]");if(l){const v=parseInt(l.getAttribute("data-id"));V(v)}return}const p=o.closest('[data-action="scrape"]');if(p){const l=p.closest("[data-id]");if(l){const v=parseInt(l.getAttribute("data-id"));W(v)}return}const m=o.closest('[data-action="open"]'),u=o.closest(".feed-item");if(u&&!m){const l=parseInt(u.getAttribute("data-id"));c=l,document.querySelectorAll(".feed-item").forEach(y=>{const A=parseInt(y.getAttribute("data-id")||"0");y.classList.toggle("selected",A===c)});const v=s.items.find(y=>y._id===l);v&&!v.read&&h(l,{read:!0})}})}function k(){const{feeds:t,activeFeedId:e}=s,i=document.getElementById("feed-list");i&&(i.innerHTML=t.map(a=>` +
  • + + ${a.title||a.url} + +
  • + `).join(""))}function $(){const{tags:t,activeTagName:e}=s,i=document.getElementById("tag-list");i&&(i.innerHTML=t.map(a=>` +
  • + + ${a.title} + +
  • + `).join(""))}function _(){const{filter:t}=s,e=document.getElementById("filter-list");e&&e.querySelectorAll("li").forEach(i=>{i.classList.toggle("active",i.getAttribute("data-filter")===t)})}function L(){const{items:t,loading:e}=s,i=document.getElementById("content-area");if(!i||r.getCurrentRoute().path==="/settings")return;if(e&&t.length===0){i.innerHTML='

    Loading items...

    ';return}if(t.length===0){i.innerHTML='

    No items found.

    ';return}i.innerHTML=` + + ${s.hasMore?'
    Loading more...
    ':""} + `;const a=document.getElementById("main-content");if(a){let n=null;a.onscroll=()=>{!s.loading&&s.hasMore&&a.scrollHeight>a.clientHeight&&a.scrollHeight-a.scrollTop-a.clientHeight<200&&E(),n===null&&(n=window.setTimeout(()=>{F(a),n=null},250))}}}function F(t){const e=t.getBoundingClientRect();s.items.forEach(i=>{if(i.read)return;const a=document.querySelector(`.feed-item[data-id="${i._id}"]`);a&&a.getBoundingClientRect().bottom{const t=document.getElementById("main-content");if(s.loading||!s.hasMore)return;if(t&&(F(t),t.scrollHeight>t.clientHeight&&t.scrollHeight-t.scrollTop-t.clientHeight<200)){E();return}const e=document.documentElement.scrollHeight||document.body.scrollHeight,i=window.innerHeight,a=window.scrollY||document.documentElement.scrollTop;e>i&&e-i-a<200&&E()},1e3);function w(){const t=document.getElementById("content-area");t&&(t.innerHTML=` +
    +

    Settings

    + +
    +

    Add Feed

    +
    + + +
    +
    + +
    +

    Appearance

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

    Manage Feeds

    +
      + ${s.feeds.map(e=>` +
    • +
      +
      ${e.title||e.url}
      +
      ${e.url}
      +
      +
      + + + +
      +
    • + `).join("")} +
    +
    + +
    +

    Data Management

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

    Loading items...

    ';return}if(t.length===0){i.innerHTML='

    No items found.

    ';return}i.innerHTML=` -
      - ${t.map(n=>H(n,n._id===c)).join("")} -
    - ${a.hasMore?'
    Loading more...
    ':""} - `;const s=document.getElementById("main-content");if(s){let n=null;s.onscroll=()=>{!a.loading&&a.hasMore&&s.scrollHeight>s.clientHeight&&s.scrollHeight-s.scrollTop-s.clientHeight<200&&I(),n===null&&(n=window.setTimeout(()=>{const o=s.getBoundingClientRect();a.items.forEach(d=>{if(d.read)return;const f=document.querySelector(`.feed-item[data-id="${d._id}"]`);f&&f.getBoundingClientRect().bottom{const t=document.getElementById("main-content");if(a.loading||!a.hasMore)return;if(t&&t.scrollHeight>t.clientHeight&&t.scrollHeight-t.scrollTop-t.clientHeight<200){I();return}const e=document.documentElement.scrollHeight||document.body.scrollHeight,i=window.innerHeight,s=window.scrollY||document.documentElement.scrollTop;e>i&&e-i-s<200&&I()},1e3);function w(){const t=document.getElementById("content-area");t&&(t.innerHTML=` -
    -

    Settings

    - -
    -

    Add Feed

    -
    - - -
    -
    - -
    -

    Appearance

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

    Manage Feeds

    -
      - ${a.feeds.map(e=>` -
    • -
      -
      ${e.title||e.url}
      -
      ${e.url}
      -
      -
      - - - -
      -
    • - `).join("")} -
    -
    - -
    -

    Data Management

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