(()=>{window.addComment=function(m){var u,p,f,c=m.document,o={commentReplyClass:"comment-reply-link",commentReplyTitleId:"reply-title",cancelReplyId:"cancel-comment-reply-link",commentFormId:"commentform",temporaryFormId:"wp-temp-form-div",parentIdFieldId:"comment_parent",postIdFieldId:"comment_post_ID"},k=m.MutationObserver||m.WebKitMutationObserver||m.MozMutationObserver,N="querySelector"in c&&"addEventListener"in m,D=!!c.documentElement.dataset;function x(){F(),k&&new k(O).observe(c.body,{childList:!0,subtree:!0})}function F(r){if(N&&(u=i(o.cancelReplyId),p=i(o.commentFormId),u)){let d=function(n){if((n.metaKey||n.ctrlKey)&&n.keyCode===13)return p.removeEventListener("keydown",d),n.preventDefault(),p.submit.click(),!1};var l=d;u.addEventListener("touchstart",L),u.addEventListener("click",L),p&&p.addEventListener("keydown",d);for(var t,a=function(n){var I=o.commentReplyClass;return n&&n.childNodes||(n=c),n=c.getElementsByClassName?n.getElementsByClassName(I):n.querySelectorAll("."+I),n}(r),e=0,y=a.length;e{var l=class{getCookie(e){if(0${e}`;document.querySelector("body").insertAdjacentHTML("beforeend",s),document.querySelector(".notice--wrapper").classList.add("is-active"),setTimeout(()=>{document.querySelector(".notice--wrapper").remove()},3e3)}};var u=class{selector;timeFormat={second:"second ago",seconds:"seconds ago",minute:"minute ago",minutes:"minutes ago",hour:"hour ago",hours:"hours ago",day:"day ago",days:"days ago",week:"week ago",weeks:"weeks ago",month:"month ago",months:"months ago",year:"year ago",years:"years ago"};doms=[];constructor(e){this.selector=e.selector,e.timeFormat&&(this.timeFormat=e.timeFormat),this.init(),setTimeout(()=>{this.refresh()},1e3*5)}init(){this.doms=Array.from(document.querySelectorAll(this.selector)),this.doms.forEach(e=>{e.innerText=this.humanize_time_ago(e.attributes.datetime.value)})}humanize_time_ago(e){let t=new Date(e),s=Date.now()/1e3-Number(t.getTime()/1e3);return s<3600?`${Math.ceil(s/60)} ${Math.ceil(s/60)==1?this.timeFormat.second:this.timeFormat.seconds}`:s<86400?`${Math.ceil(s/3600)} ${Math.ceil(s/3660)==1?this.timeFormat.hour:this.timeFormat.hours}`:s<86400*30?`${Math.ceil(s/86400)} ${Math.ceil(s/86400)==1?this.timeFormat.day:this.timeFormat.days}`:s<86400*30*12?`${Math.ceil(s/(86400*30))} ${Math.ceil(s/(86400*30))==1?this.timeFormat.month:this.timeFormat.months}`:t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate()}refresh(){this.doms.forEach(e=>{e.innerText=this.humanize_time_ago(e.attributes.datetime.value)})}},b=u;var p=class extends l{singleSelector=".post--single";likeButtonSelctor=".like-btn";articleSelector=".post--item";viewSelector=".article--views";actionDomain;text="";likeButton=null;post_id;is_single=!1;constructor(e){if(super(),this.singleSelector=e.singleSelector??this.singleSelector,this.likeButtonSelctor=e.likeButtonSelctor??this.likeButtonSelctor,this.articleSelector=e.articleSelector??this.articleSelector,this.viewSelector=e.viewSelector??this.viewSelector,this.actionDomain=e.actionDomain,this.text=e.text??this.text,this.is_single=!!document.querySelector(this.singleSelector),this.is_single){let t=document.querySelector(this.singleSelector);this.post_id=t.dataset.id??"",this.initArticleLike(),this.initArticleView()}else this.initArticlesView()}initArticleView(){fetch(this.actionDomain+"post/"+this.post_id+"/view",{method:"post"}).then(e=>{e.json().then(t=>{document.querySelector(this.viewSelector).innerText=t.views+this.text})})}initArticlesView(){let e=Array.from(document.querySelectorAll(this.articleSelector));if(e.length===0)return;let t=[];e.forEach(n=>t.push(n.dataset.id));let s=t.join(",");fetch(this.actionDomain+"post/views?post_ids="+s).then(n=>{n.json().then(i=>{let a=i.results;e.forEach(o=>{o.querySelector(this.viewSelector)&&(o.querySelector(this.viewSelector).innerText=(a.find(r=>r.post_id==o.dataset.id)?a.find(r=>r.post_id==o.dataset.id).views:0)+this.text)})})})}initArticleLike(){this.likeButton=document.querySelector(this.likeButtonSelctor),this.likeButton&&(fetch(this.actionDomain+"post/"+this.post_id+"/like").then(e=>{e.json().then(t=>{this.likeButton.querySelector(".count").innerText=t.likes})}),this.likeButton.addEventListener("click",()=>{this.handleLike()}),this.getCookie("like_"+this.post_id)&&this.likeButton.classList.add("is-active"))}handleLike(){if(this.getCookie("like_"+this.post_id))return this.showNotice("You have already liked this post");if(this.likeButton){let e=this.actionDomain+"post/"+this.post_id+"/like";fetch(e,{method:"post"}).then(t=>t.json()).then(t=>{this.showNotice("Thanks for your like");let s=this.likeButton?.querySelector(".count");s&&(s.innerText=t.likes),this.setCookie("like_"+this.post_id,"1",1)}),this.likeButton?.classList.add("is-active")}}},_=p;var m=class{loading=!1;post_id;total=0;total_paged=1;paged=1;constructor(){document.querySelector(".post--ingle__comments")&&(this.post_id=document.querySelector(".post--ingle__comments").dataset.id,this.fetchComments(),this.init())}fetchComments(){fetch(window.commentDomain+"/post/"+this.post_id+"/comments?paged="+this.paged).then(e=>{e.json().then(t=>{let s=t.payload.comments;this.total=t.payload.total,this.total_paged=t.payload.total_paged,this.total_paged>1&&this.randerNav(),document.querySelector(".comments--title .count").innerHTML=this.total;let n=s.map(i=>{let a="";return i.children&&(a=`
    ${i.children.map(o=>`
  1. ${o.avatar}
    ${o.comment_text}
  2. `).join("")}
`),`
  • ${i.avatar}
    ${i.comment_text}
    ${a}
  • `}).join("");document.querySelector(".commentlist ").innerHTML=n})})}randerNav(){let e=this.paged==1?"disabled":"",s=` Older CommentsNewer Comments `;document.querySelector(".commentnav").innerHTML=s,document.querySelectorAll(".cnav-item").forEach(n=>{n.addEventListener("click",i=>{if(n.classList.contains("disabled"))return;console.log(n);let a=n.attributes["data-action"].value;console.log(a),a=="pre"?this.paged+=1:this.paged-=1,this.fetchComments()})})}init(){document.querySelector(".comment-form")&&document.querySelector(".comment-form")?.addEventListener("submit",e=>{if(e.preventDefault(),this.loading)return;let t=document.querySelector(".comment-form"),s=new FormData(t),n={};s.forEach((i,a)=>n[a]=i),this.loading=!0,fetch(window.commentDomain+"/post/"+this.post_id+"/comment",{method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json"}}).then(i=>i.json()).then(i=>{if(this.loading=!1,i.status!=200)return;let a=document.getElementById("cancel-comment-reply-link"),o=document.getElementById("respond"),r=document.getElementById("wp-temp-form-div"),c=i.data,y=`
  • ${c.avatar}
    ${c.comment_author}
    ${c.comment_text}
  • `,h=document.querySelector("#comment_parent")?.value;a.style.display="none",a.onclick=null,document.getElementById("comment_parent").value="0",r&&o&&r.parentNode&&r.parentNode.removeChild(r),document.querySelector(".comment-body__fresh")&&document.querySelector(".comment-body__fresh")?.classList.remove("comment-body__fresh"),document.getElementById("comment").value="",h!="0"?(document.querySelector("#comment-"+h)?.insertAdjacentHTML("beforeend",'
      '+y+"
    "),console.log(h)):(document.querySelector(".no--comment")&&document.querySelector(".no--comment")?.remove(),document.querySelector(".commentlist")?.insertAdjacentHTML("beforeend",y));let f=document.querySelector(`#comment-${c.comment_ID}`);f&&f.scrollIntoView({behavior:"smooth"})})})}};var v=class{ver;type;finished;paged;genre_list;subjects;status;baseAPI;types;container;constructor(e){this.container=e.container,this.types=e.types??["movie","book","music","game","drama"],this.baseAPI=e.baseAPI,this.ver="1.0.6",this.type="movie",this.status="done",this.finished=!1,this.paged=1,this.genre_list=[{name:"\u5DF2\u770B",value:"done"},{name:"\u5728\u770B",value:"doing"},{name:"\u60F3\u770B",value:"mark"}],this.subjects=[],this._create()}on(e,t,s){document.querySelectorAll(t).forEach(i=>{i.addEventListener(e,s)})}_handleGenreClick(){this.on("click",".db--genreItem",e=>{let t=e.currentTarget;t.classList.contains("is-active")||(document.querySelector(".db--list").innerHTML="",document.querySelector(".lds-ripple").classList.remove("u-hide"),this.status=t.dataset.status||"",this._renderGenre(),this.paged=1,this.finished=!1,this.subjects=[],this._fetchData())})}_reanderTypes(){document.querySelector(".db--nav").innerHTML=this.types.map(e=>`${e}`).join(""),this._handleNavClick()}_renderGenre(){document.querySelector(".db--genres").innerHTML=this.genre_list.map(e=>`${e.name}`).join(""),this._handleGenreClick()}_fetchData(){let e=new URLSearchParams({paged:this.paged.toString(),type:this.type,status:this.status});fetch(this.baseAPI+"list?"+e.toString()).then(t=>t.json()).then(t=>{console.log(t.results),t.results.length?(document.querySelector(".db--list").classList.contains("db--list__card")?(this.subjects=[...this.subjects,...t.results],this._randerDateTemplate()):(this.subjects=[...this.subjects,...t.results],this._randerListTemplate()),document.querySelector(".lds-ripple").classList.add("u-hide")):(this.finished=!0,document.querySelector(".lds-ripple").classList.add("u-hide"))})}_randerDateTemplate(){let e=this.subjects.reduce((s,n)=>{let i=new Date(n.create_time),a=i.getFullYear(),o=i.getMonth()+1,r=`${a}-${o.toString().padStart(2,"0")}`;return Object.prototype.hasOwnProperty.call(s,r)?s[r].push(n):s[r]=[n],s},{}),t="";for(let s in e){let n=s.split("-");t+=`
    ${n[1]}
    ${n[0]}
    `,t+=e[s].map(i=>`
    ${i.douban_score>0?''+i.douban_score:""}${i.year>0?" \xB7 "+i.year:""}
    `).join(""),t+="
    "}document.querySelector(".db--list").innerHTML=t}_randerListTemplate(){document.querySelector(".db--list").innerHTML=this.subjects.map(e=>`
    ${e.create_time}
    ${e.douban_score?''+e.douban_score:""}${e.year?" \xB7 "+e.year:""}
    `).join("")}_handleScroll(){window.addEventListener("scroll",()=>{var e=window.scrollY||window.pageYOffset;document.querySelector(".block-more").offsetTop+-window.innerHeight{let t=e.currentTarget;t.classList.contains("current")||(this.status="done",this.type=t.dataset.type,this._renderGenre(),document.querySelector(".db--list").innerHTML="",document.querySelector(".lds-ripple").classList.remove("u-hide"),document.querySelector(".db--navItem.current").classList.remove("current"),t.classList.add("current"),this.paged=1,this.finished=!1,this.subjects=[],this._fetchData())})}_create(){if(document.querySelector(".db--container")){let e=document.querySelector(this.container);if(!e)return;e.innerHTML=`
    `,this._renderGenre(),this._reanderTypes(),this._fetchData(),this._handleScroll()}document.querySelector(".js-db")&&document.querySelectorAll(".js-db").forEach(e=>{let t=e,s=t.dataset.id,n=t.dataset.type,i=t.parentNode;fetch(this.baseAPI+`${n}/${s}`).then(a=>{a.json().then(o=>{if(o.data){let r=o.data,c=document.createElement("div");c.classList.add("doulist-item"),c.innerHTML=`
    ${r.douban_score}
    ${r.card_subtitle}
    `,i.replaceWith(c)}})})}),document.querySelector(".db--collection")&&document.querySelectorAll(".db--collection").forEach(e=>{this._fetchCollection(e)})}_fetchCollection(e){let t=e.dataset.style?e.dataset.style:"card";fetch(this.baseAPI+"/list?type="+e.dataset.type+"&paged=1&start_time="+e.dataset.start+"&end_time="+e.dataset.end).then(s=>s.json()).then(s=>{if(s.length)if(t=="card")e.innerHTML+=s.map(n=>`
    Marked ${n.create_time}
    ${n.douban_score}
    ${n.card_subtitle}
    `).join("");else{let n=s.reduce((a,o)=>(Object.prototype.hasOwnProperty.call(a,o.create_time)?a[o.create_time].push(o):a[o.create_time]=[o],a),{}),i="";for(let a in n)i+=`
    ${a}
    `,i+=n[a].map(o=>`
    ${o.douban_score}
    ${o.remark||o.card_subtitle}
    `).join(""),i+="
    ";e.innerHTML=i}})}},S=v;var g=class extends l{is_single=!1;post_id=0;is_archive=!1;VERSION="0.4.3";like_btn;selctor=".like-btn";actionDomain=window.actionDomain;constructor(){super(),this.initCopyright(),this.initThemeSwitch(),this.initBack2Top(),this.initSearch()}initSearch(){document.querySelector('[data-action="show-search"]').addEventListener("click",()=>{document.querySelector(".site--header__center .inner").classList.toggle("search--active")})}initBack2Top(){if(document.querySelector(".backToTop")){let e=document.querySelector(".backToTop");window.addEventListener("scroll",()=>{(window.scrollY||window.pageYOffset)>200?e.classList.add("is-active"):e.classList.remove("is-active")}),e.addEventListener("click",()=>{window.scrollTo({top:0,behavior:"smooth"})})}}initCopyright(){let e=``;document.querySelector(".site--footer__content").insertAdjacentHTML("afterend",e),document.querySelector(".icon--copryrights").addEventListener("click",()=>{document.querySelector(".site--footer__info").classList.toggle("active")})}initThemeSwitch(){let e=localStorage.getItem("theme")?localStorage.getItem("theme"):"auto",t=`
    `;document.querySelector("body").insertAdjacentHTML("beforeend",t),document.querySelectorAll(".fixed--theme span").forEach(s=>{s.addEventListener("click",()=>{s.classList.contains("is-active")||(document.querySelectorAll(".fixed--theme span").forEach(n=>{n.classList.remove("is-active")}),s.dataset.actionValue=="dark"?(localStorage.setItem("theme","dark"),document.querySelector("body").classList.remove("auto"),document.querySelector("body").classList.add("dark"),s.classList.add("is-active")):s.dataset.actionValue=="light"?(localStorage.setItem("theme","light"),document.querySelector("body").classList.remove("auto"),document.querySelector("body").classList.remove("dark"),s.classList.add("is-active")):s.dataset.actionValue=="auto"&&(localStorage.setItem("theme","auto"),document.querySelector("body").classList.remove("dark"),document.querySelector("body").classList.add("auto"),s.classList.add("is-active")))})})}};new _({singleSelector:".post--single",articleSelector:".post--item",likeButtonSelctor:".like-btn",actionDomain:window.actionDomain});new g;new b({selector:".humane--time",timeFormat:window.timeFormat});new m;new S({baseAPI:window.dbAPIBase,container:".db--container"});})();