fictioneer/js/ajax-bookshelf.min.js

1 line
2.1 KiB
JavaScript
Raw Permalink Normal View History

2024-12-06 17:38:32 +01:00
const fcn_bookshelfTarget=_$$$("ajax-bookshelf-target");function fcn_getBookshelfContent(){return FcnUtils.parseJSON(localStorage.getItem("fcnBookshelfContent"))??{html:{},count:{}}}function fcn_updateBookshelfView(e=null,t=null,o=null,n=!1){let a=fcn_getBookshelfContent();const s=(e=e??fcn_bookshelfTarget.dataset.action)+(t=t??fcn_bookshelfTarget.dataset.page)+(o=o??fcn_bookshelfTarget.dataset.order);if(!a.timestamp||a.timestamp+6e4<Date.now())return localStorage.removeItem("fcnBookshelfContent"),a={html:{},count:{}},void fcn_fetchBookshelfPart(e,t,o,n);a.html&&a.html[s]?(fcn_bookshelfTarget.innerHTML=a.html[s],fcn_bookshelfTarget.classList.remove("ajax-in-progress"),fcn_bookshelfTarget.dataset.page=t,_$(".item-number").innerHTML=`(${a.count[e]})`,n&&_$$$("main").scrollIntoView({behavior:"smooth"})):fcn_fetchBookshelfPart(e,t,o,n)}function fcn_browseBookshelfPage(e){fcn_bookshelfTarget.classList.add("ajax-in-progress"),fcn_updateBookshelfView(null,e,null,!0),history.pushState({},"",FcnUtils.buildUrl({tab:fcn_bookshelfTarget.dataset.tab,pg:e,order:fcn_bookshelfTarget.dataset.order}).href)}function fcn_fetchBookshelfPart(e,t,o,n=!1){const a=e+t+o,s=fcn_getBookshelfContent();FcnUtils.aGet({action:e,fcn_fast_ajax:1,page:t,order:o}).then((o=>{o.success?(s.timestamp=Date.now(),s.html[a]=o.data.html,s.count[e]=o.data.count,localStorage.setItem("fcnBookshelfContent",JSON.stringify(s)),fcn_bookshelfTarget.innerHTML=o.data.html,fcn_bookshelfTarget.dataset.page=t,_$(".item-number").innerHTML=`(${o.data.count})`):(fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(FcnUtils.buildErrorNotice(o.data.error)))})).catch((e=>{_$(".item-number").innerHTML="",fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(FcnUtils.buildErrorNotice(`${e.status}: ${e.statusText}`))})).then((()=>{fcn_bookshelfTarget.classList.remove("ajax-in-progress"),n&&_$$$("main").scrollIntoView({behavior:"smooth"})}))}fcn_bookshelfTarget&&document.addEventListener("fcnUserDataReady",(()=>{fcn_updateBookshelfView()})),_$(".bookshelf__list")?.addEventListener("click",(e=>{const t=e.target.closest(".page-numbers[data-page]");t&&fcn_browseBookshelfPage(t.dataset.page)}));