From fdab283909ccc4947aed36f871645b2db3e948df Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed, 24 Apr 2024 00:58:48 +0200 Subject: [PATCH] Add custom order param to comments query --- comments.php | 10 +++++++--- includes/functions/comments/_comments_ajax.php | 7 +++++-- includes/functions/comments/_comments_threads.php | 6 ++++-- js/ajax-comments.min.js | 2 +- js/complete.min.js | 2 +- src/js/ajax-comments.js | 9 ++++++--- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/comments.php b/comments.php index 77ba110e..ca06d81f 100644 --- a/comments.php +++ b/comments.php @@ -21,12 +21,14 @@ if ( post_password_required() ) { $post_id = get_the_ID(); $user = wp_get_current_user(); $comments_count = get_comments_number(); +$order = array_intersect( [ strtolower( $_GET['comments-order'] ?? 0 ) ], ['desc', 'asc'] ); +$order = reset( $order ) ?: get_option( 'comment_order' ); // Sanitized $logout_url = fictioneer_get_logout_url( get_permalink() ); $is_ajax_comments = get_option( 'fictioneer_enable_ajax_comments' ); ?> -
> +
> $post_id ); + $query_args = array( + 'post_id' => $post_id, + 'order' => $order + ); if ( ! get_option( 'fictioneer_disable_comment_query' ) ) { $query_args['type'] = ['comment', 'private']; - $query_args['order'] = get_option( 'comment_order' ); } else { $query_args['type'] = ['comment']; } diff --git a/includes/functions/comments/_comments_ajax.php b/includes/functions/comments/_comments_ajax.php index c64152f7..2472c732 100644 --- a/includes/functions/comments/_comments_ajax.php +++ b/includes/functions/comments/_comments_ajax.php @@ -98,6 +98,8 @@ function fictioneer_ajax_get_comment_section() { $post_id = absint( $_GET['post_id'] ); $post = get_post( $post_id ); // Called later anyway; no performance loss $page = absint( $_GET['page'] ?? 1 ) ?: 1; + $order = array_intersect( [ strtolower( $_GET['order'] ?? 0 ) ], ['desc', 'asc'] ); + $order = reset( $order ) ?: get_option( 'comment_order' ); // Sanitized $commentcode = ( $_GET['commentcode'] ?? 0 ) ?: false; $must_login = get_option( 'comment_registration' ) && ! is_user_logged_in(); @@ -121,7 +123,7 @@ function fictioneer_ajax_get_comment_section() { if ( ! get_option( 'fictioneer_disable_comment_query' ) ) { $query_args['type'] = ['comment', 'private']; - $query_args['order'] = get_option( 'comment_order' ); + $query_args['order'] = $order; } else { // Still hide private comments but do not limit the types preemptively $query_args = array( 'type__not_in' => 'private' ); @@ -166,7 +168,8 @@ function fictioneer_ajax_get_comment_section() { array( 'commentcode' => $commentcode, 'post_author_id' => $post->post_author, - 'post_id' => $post_id + 'post_id' => $post_id, + 'order' => $order ) ); diff --git a/includes/functions/comments/_comments_threads.php b/includes/functions/comments/_comments_threads.php index c3afeec0..b19ad496 100644 --- a/includes/functions/comments/_comments_threads.php +++ b/includes/functions/comments/_comments_threads.php @@ -209,7 +209,7 @@ if ( ! function_exists( 'fictioneer_ajax_list_comments' ) ) { if ( ! get_option( 'fictioneer_disable_comment_query' ) ) { $list_args['page'] = $page; $list_args['reverse_top_level'] = false; - $list_args['reverse_children'] = true; + $list_args['reverse_children'] = ( $args['order'] ?? 0 ) === 'desc'; } if ( ! get_option( 'fictioneer_disable_comment_callback' ) ) { @@ -240,6 +240,8 @@ if ( ! function_exists( 'fictioneer_ajax_list_comments' ) ) { function fictioneer_comment_list_args( $parsed_args ) { // Setup $page = get_query_var( 'cpage', 1 ); + $order = array_intersect( [ strtolower( $_GET['comments-order'] ?? 0 ) ], ['desc', 'asc'] ); + $order = reset( $order ) ?: get_option( 'comment_order' ); // Sanitized // Build arguments $list_args = array( @@ -255,7 +257,7 @@ function fictioneer_comment_list_args( $parsed_args ) { if ( ! get_option( 'fictioneer_disable_comment_query' ) ) { $list_args['page'] = $page; $list_args['reverse_top_level'] = false; - $list_args['reverse_children'] = true; + $list_args['reverse_children'] = $order === 'desc'; } if ( ! get_option( 'fictioneer_disable_comment_callback' ) ) { diff --git a/js/ajax-comments.min.js b/js/ajax-comments.min.js index 6c8dd26f..bca96235 100644 --- a/js/ajax-comments.min.js +++ b/js/ajax-comments.min.js @@ -1 +1 @@ -const fcn_commentSection=_$("#comments[data-ajax-comments]");function fcn_getCommentSection(e=null,n=null,t=!1){if(!fcn_commentSection)return;let o,c="",m=_$$$("comment");if(m&&(c=m.value),fcn_commentSection.classList.contains("ajax-in-progress"))return;if(fcn_commentSection.classList.add("ajax-in-progress"),n||(n=fcn_urlParams.pg??1),!fcn_commentSection)return;const a={action:"fictioneer_ajax_get_comment_section",post_id:e??fcn_commentSection.dataset.postId,page:parseInt(n)};fcn_urlParams.commentcode&&(a.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(a).then((e=>{if(e.success){n=e.data.page;const o=document.createElement("div");if(o.innerHTML=e.data.html,o.querySelector("#comment_post_ID")){o.querySelector("#comment_post_ID").value=e.data.postId,o.querySelector("#cancel-comment-reply-link").href="#respond";const n=o.querySelector(".logout-link");n&&(n.href=fcn_commentSection.dataset.logoutUrl)}fcn_commentSection.innerHTML=o.innerHTML,o.remove(),e.data.disabled||(m=_$$$("comment"),m.value=c,fcn_applyCommentStack(m)),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const a=location.hash.includes("#comment")?location.hash:".respond",r=document.querySelector(a)??_$$$("respond");t&&r.scrollIntoView({behavior:"smooth"});const i=window.location.protocol+"//"+window.location.host+window.location.pathname;let s="";fcn_urlParams.commentcode&&(s+=`?commentcode=${fcn_urlParams.commentcode}`),n>1&&(s+=s.length>1?`&pg=${n}`:`?pg=${n}`),window.history.pushState({path:i},"",i+s+location.hash)}else o=fcn_buildErrorNotice(e.data.error)})).catch((e=>{o=fcn_buildErrorNotice(e)})).then((()=>{fcn_commentSection.classList.remove("ajax-in-progress"),o&&(fcn_commentSection.innerHTML="",fcn_commentSection.appendChild(o))}))}function fcn_reloadCommentsPage(e=null){fcn_getCommentSection(null,e,!0)}function fcn_jumpToCommentPage(){const e=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));e>0&&fcn_reloadCommentsPage(e)}var fct_commentSectionObserver;function fcn_setupCommentSectionObserver(){fct_commentSectionObserver=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentSection(),fct_commentSectionObserver.disconnect())}),{rootMargin:"450px",threshold:1}),fcn_commentSection&&fct_commentSectionObserver.observe(fcn_commentSection)}function fcn_loadCommentEarly(){fcn_commentSection&&location.hash.includes("#comment")&&(_$$$("comment")||(fct_commentSectionObserver.disconnect(),fcn_reloadCommentsPage()))}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentSectionObserver()})):fcn_setupCommentSectionObserver(),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(e=>{if(e.target.closest("[data-page-jump]"))return void fcn_jumpToCommentPage();const n=e.target.closest("[data-page]");n&&fcn_reloadCommentsPage(n.dataset.page)})); \ No newline at end of file +const fcn_commentSection=_$("#comments[data-ajax-comments]");function fcn_getCommentSection(e=null,n=null,t=null,o=!1){if(!fcn_commentSection)return;let c,m="",a=_$$$("comment");if(a&&(m=a.value),fcn_commentSection.classList.contains("ajax-in-progress"))return;if(fcn_commentSection.classList.add("ajax-in-progress"),n||(n=fcn_urlParams.pg??1),!fcn_commentSection)return;const r={action:"fictioneer_ajax_get_comment_section",post_id:e??fcn_commentSection.dataset.postId,page:parseInt(n),order:t??fcn_commentSection.dataset.order??0};fcn_urlParams.commentcode&&(r.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(r).then((e=>{if(e.success){n=e.data.page;const t=document.createElement("div");if(t.innerHTML=e.data.html,t.querySelector("#comment_post_ID")){t.querySelector("#comment_post_ID").value=e.data.postId,t.querySelector("#cancel-comment-reply-link").href="#respond";const n=t.querySelector(".logout-link");n&&(n.href=fcn_commentSection.dataset.logoutUrl)}fcn_commentSection.innerHTML=t.innerHTML,t.remove(),e.data.disabled||(a=_$$$("comment"),a.value=m,fcn_applyCommentStack(a)),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const c=location.hash.includes("#comment")?location.hash:".respond",r=document.querySelector(c)??_$$$("respond");o&&r.scrollIntoView({behavior:"smooth"});const i=window.location.protocol+"//"+window.location.host+window.location.pathname;let s="";fcn_urlParams.commentcode&&(s+=`?commentcode=${fcn_urlParams.commentcode}`),n>1&&(s+=s.length>1?`&pg=${n}`:`?pg=${n}`),window.history.pushState({path:i},"",i+s+location.hash)}else c=fcn_buildErrorNotice(e.data.error)})).catch((e=>{c=fcn_buildErrorNotice(e)})).then((()=>{fcn_commentSection.classList.remove("ajax-in-progress"),c&&(fcn_commentSection.innerHTML="",fcn_commentSection.appendChild(c))}))}function fcn_reloadCommentsPage(e=null){fcn_getCommentSection(null,e,null,!0)}function fcn_jumpToCommentPage(){const e=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));e>0&&fcn_reloadCommentsPage(e)}var fct_commentSectionObserver;function fcn_setupCommentSectionObserver(){fct_commentSectionObserver=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentSection(),fct_commentSectionObserver.disconnect())}),{rootMargin:"450px",threshold:1}),fcn_commentSection&&fct_commentSectionObserver.observe(fcn_commentSection)}function fcn_loadCommentEarly(){fcn_commentSection&&location.hash.includes("#comment")&&(_$$$("comment")||(fct_commentSectionObserver.disconnect(),fcn_reloadCommentsPage()))}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentSectionObserver()})):fcn_setupCommentSectionObserver(),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(e=>{if(e.target.closest("[data-page-jump]"))return void fcn_jumpToCommentPage();const n=e.target.closest("[data-page]");n&&fcn_reloadCommentsPage(n.dataset.page)})); \ No newline at end of file diff --git a/js/complete.min.js b/js/complete.min.js index 7b5de930..e0da9058 100644 --- a/js/complete.min.js +++ b/js/complete.min.js @@ -3,4 +3,4 @@ const _$=document.querySelector.bind(document),_$$=document.querySelectorAll.bin for(var n=1;n=l&&(l=f,s=a,i=o,r=c)}t[n-1][1]!=s&&(s?t[n-1][1]=s:(t.splice(n-1,1),n--),t[n][1]=i,r?t[n+1][1]=r:(t.splice(n+1,1),n--))}n++}},diff_match_patch.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,diff_match_patch.whitespaceRegex_=/\s/,diff_match_patch.linebreakRegex_=/[\r\n]/,diff_match_patch.blanklineEndRegex_=/\n\r?\n$/,diff_match_patch.blanklineStartRegex_=/^\r?\n\r?\n/,diff_match_patch.prototype.diff_cleanupEfficiency=function(t){for(var e=!1,n=[],a=0,o=null,c=0,s=!1,i=!1,r=!1,l=!1;ce));n++)c=a,s=o;return t.length!=n&&t[n][0]===DIFF_DELETE?s:s+(e-c)},diff_match_patch.prototype.diff_prettyHtml=function(t){for(var e=[],n=/&/g,a=//g,c=/\n/g,s=0;s");switch(i){case DIFF_INSERT:e[s]=''+r+"";break;case DIFF_DELETE:e[s]=''+r+"";break;case DIFF_EQUAL:e[s]=""+r+""}}return e.join("")},diff_match_patch.prototype.diff_text1=function(t){for(var e=[],n=0;nthis.Match_MaxBits)throw Error("Pattern too long for this browser.");var o=this.match_alphabet_(e),c=this,s=this.Match_Threshold,i=t.indexOf(e,n);-1!=i&&(s=Math.min(a(0,i),s),-1!=(i=t.lastIndexOf(e,n+e.length))&&(s=Math.min(a(0,i),s)));var r=1<=l;u--){var g=o[t.charAt(u-1)];if(f[u]=0===h?(f[u+1]<<1|1)&g:(f[u+1]<<1|1)&g|(d[u+1]|d[u])<<1|1|d[u+1],f[u]&r&&(g=a(h,u-1))<=s){if(s=g,!((i=u-1)>n))break;l=Math.max(1,2*n-i)}}if(a(h+1,n)>s)break;d=f}return i},diff_match_patch.prototype.match_alphabet_=function(t){for(var e={},n=0;n=2*this.Patch_Margin&&o&&(this.patch_addContext_(t,i),n.push(t),t=new diff_match_patch.patch_obj,o=0,i=a,c=s)}l!==DIFF_INSERT&&(c+=f.length),l!==DIFF_DELETE&&(s+=f.length)}return o&&(this.patch_addContext_(t,i),n.push(t)),n},diff_match_patch.prototype.patch_deepCopy=function(t){for(var e=[],n=0;nthis.Match_MaxBits){var l=this.match_main(e,i.substring(0,this.Match_MaxBits),s);-1!=l&&(-1==(r=this.match_main(e,i.substring(i.length-this.Match_MaxBits),s+i.length-this.Match_MaxBits))||l>=r)&&(l=-1)}else l=this.match_main(e,i,s);if(-1==l)o[c]=!1,a-=t[c].length2-t[c].length1;else if(o[c]=!0,a=l-s,i==(s=-1==r?e.substring(l,l+i.length):e.substring(l,r+this.Match_MaxBits)))e=e.substring(0,l)+this.diff_text2(t[c].diffs)+e.substring(l+i.length);else if(s=this.diff_main(i,s,!1),i.length>this.Match_MaxBits&&this.diff_levenshtein(s)/i.length>this.Patch_DeleteThreshold)o[c]=!1;else{var f;for(this.diff_cleanupSemanticLossless(s),i=0,r=0;ro[0][1].length){var c=e-o[0][1].length;o[0][1]=n.substring(o[0][1].length)+o[0][1],a.start1-=c,a.start2-=c,a.length1+=c,a.length2+=c}return 0==(o=(a=t[t.length-1]).diffs).length||o[o.length-1][0]!=DIFF_EQUAL?(o.push(new diff_match_patch.Diff(DIFF_EQUAL,n)),a.length1+=e,a.length2+=e):e>o[o.length-1][1].length&&(c=e-o[o.length-1][1].length,o[o.length-1][1]+=n.substring(0,c),a.length1+=c,a.length2+=c),n},diff_match_patch.prototype.patch_splitMax=function(t){for(var e=this.Match_MaxBits,n=0;n2*e?(i.length1+=l.length,o+=l.length,r=!1,i.diffs.push(new diff_match_patch.Diff(s,l)),a.diffs.shift()):(l=l.substring(0,e-i.length1-this.Patch_Margin),i.length1+=l.length,o+=l.length,s===DIFF_EQUAL?(i.length2+=l.length,c+=l.length):r=!1,i.diffs.push(new diff_match_patch.Diff(s,l)),l==a.diffs[0][1]?a.diffs.shift():a.diffs[0][1]=a.diffs[0][1].substring(l.length))}s=(s=this.diff_text2(i.diffs)).substring(s.length-this.Patch_Margin),""!==(l=this.diff_text1(a.diffs).substring(0,this.Patch_Margin))&&(i.length1+=l.length,i.length2+=l.length,0!==i.diffs.length&&i.diffs[i.diffs.length-1][0]===DIFF_EQUAL?i.diffs[i.diffs.length-1][1]+=l:i.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,l))),r||t.splice(++n,0,i)}}},diff_match_patch.prototype.patch_toText=function(t){for(var e=[],n=0;n/g,c=/\n/g,s=0;s");switch(i){case 1:e[s]=`${r}`;break;case-1:e[s]=`${r}`;break;case 0:e[s]=`${r}`}}return e.join("")};class FCN_Suggestion{constructor(){this.toggle=_$$$("suggestions-modal-toggle"),this.tools=_$$$("selection-tools"),this.button=_$$$("button-add-suggestion"),this.toolsButton=_$$$("button-tools-add-suggestion"),this.reset=_$$$("button-suggestion-reset"),this.submit=_$$$("button-suggestion-submit"),this.current=_$$$("suggestions-modal-original"),this.input=_$$$("suggestions-modal-input"),this.output=_$$$("suggestions-modal-diff"),this.chapter=_$(".chapter__article"),this.text="",this.original="",this.latest="",this.dmp=new diff_match_patch,this.bindEvents()}getCaretCoordinates(){let t=0,e=0;if(void 0!==window.getSelection){const n=window.getSelection();if(0!==n.rangeCount){let a=n.getRangeAt(0).cloneRange().getClientRects();a=a[a.length-1],a&&(t=a.right+window.scrollX,e=a.bottom+window.scrollY)}}return{x:t,y:e}}showTools(t,e){const n=document.documentElement.offsetWidth/2+this.tools.offsetWidth,a=_$$$("wpadminbar")?_$$$("wpadminbar").offsetHeight:0;this.tools.style.transform=e>n?"translate(-100%)":"translate(0)",this.tools.style.top=t+4-a+"px",this.tools.style.left=`${e}px`,this.tools.classList.remove("invisible")}hideTools(){this.tools.style.top="0",this.tools.style.left="-1000px",this.tools.classList.add("invisible")}textSelection(){return fcn_cleanTextSelectionFromButtons(window.getSelection().toString())}clearSelection(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.selection&&document.selection.empty()}getDiff(t,e){const n=this.dmp.diff_main(t,e);return this.dmp.diff_cleanupEfficiency(n),this.dmp.fcn_prettyHtml(n)}toggleTools(t){fcn_theSite.classList.contains("transformed-site")||window.getSelection().rangeCount<1||!window.getSelection().getRangeAt(0).startContainer.parentNode.closest(".content-section")||setTimeout((()=>{if(t.text=t.textSelection().replace("Add Suggestion","").replaceAll("\n\n","\n"),""!==t.text){const e=t.getCaretCoordinates();t.showTools(e.y,e.x)}else t.hideTools()}),10)}toggleViaParagraphTools(t){fcn_theSite.classList.contains("transformed-site")||(t.text=_$(".selected-paragraph").querySelector(".paragraph-inner").innerText,t.showModal(t))}resizeInput(){this.input.style.height="auto",this.input.style.height=`${fcn_clamp(32,108,this.input.scrollHeight+4)}px`}showModal(t){fcn_lastSelectedParagraphId&&fcn_toggleParagraphTools(!1),t.original=t.text,t.current.innerHTML=t.text.replaceAll("\n","
"),t.input.value=t.text,t.output.innerHTML=t.getDiff(t.original,t.text),t.toggle.click(),t.toggle.checked=!0,t.clearSelection(),t.hideTools(),t.resizeInput(),t.input.focus()}editSuggestion(t){t.resizeInput(),t.output.innerHTML=t.getDiff(t.original,t.input.value)}resetSuggestion(t){t.input.value=t.original,t.resizeInput(),t.output.innerHTML=t.getDiff(t.original,t.original)}submitSuggestion(t){const e=_$$$("comment");let n=t.output.innerHTML;[["¶","¶\n"],["
","\n"],["","[ins]"],["","[/ins]"],["","[del]"],["","[/del]"]].forEach((([t,e])=>{n=n.replaceAll(t,e)})),t.latest=`\n[quote]${n}[/quote]\n`,e?(e.value+=t.latest,fcn_textareaAdjust(_$("textarea#comment"))):fcn_commentStack?.push(t.latest),t.toggle.click(),t.toggle.checked=!1,fcn_showNotification(fictioneer_tl.notification.suggestionAppendedToComment)}bindEvents(){this.chapter?.addEventListener("mouseup",this.toggleTools.bind(null,this)),this.button?.addEventListener("click",this.showModal.bind(null,this)),this.toolsButton?.addEventListener("click",this.toggleViaParagraphTools.bind(null,this)),this.input?.addEventListener("input",this.editSuggestion.bind(null,this)),this.reset?.addEventListener("click",this.resetSuggestion.bind(null,this)),this.submit?.addEventListener("click",this.submitSuggestion.bind(null,this))}}const fcn_suggestions=_$(".chapter__article")&&_$(".comment-section")&&_$$$("selection-tools")?new FCN_Suggestion:null;fcn_suggestions&&document.addEventListener("click",(function(t){t.target.closest(".content-section")||fcn_suggestions.hideTools()}));const fcn_ttsInterface=_$$$("tts-interface");var fcn_utter,fcn_synth,fcn_ttsStack=[],fcn_currentReadingId=-1,fcn_ttsPauseTimestamp=-1,fcn_ttsCurrentText="",fcn_ttsSettings=fcn_getTTSsettings(),fcn_voices=[];if("undefined"!=typeof speechSynthesis&&fcn_ttsInterface){fcn_synth=window.speechSynthesis,(fcn_utter=new SpeechSynthesisUtterance).lang=fcn_theRoot.lang;const t=setTimeout((()=>{fcn_setupTTS()}),2e3);"onvoiceschanged"in speechSynthesis&&fcn_synth.addEventListener("voiceschanged",(()=>{fcn_setupTTS(),clearTimeout(t)}),{once:!0})}function fcn_setupTTS(){fcn_voices.length>0||(fcn_setUpVoices(),fcn_updateVolume(fcn_ttsSettings.volume),fcn_updatePitch(fcn_ttsSettings.pitch),fcn_updateRate(fcn_ttsSettings.rate))}function fcn_setTTSsettings(t){fcn_ttsSettings=t,localStorage.setItem("ttsSettings",JSON.stringify(t))}function fcn_getTTSsettings(){const t=fcn_parseJSON(localStorage.getItem("ttsSettings"))??{};return fcn_setTTSsettings(t),t}function fcn_setUpVoices(){const t=fcn_synth.getVoices(),e=_$$$("tts-voice-select");if(!e)return;let n=0;for(let a=0;a{fcn_updateVoice(t.currentTarget.value)})),fcn_updateVoice(fcn_ttsSettings.voice))}function fcn_updateVoice(t){if(isNaN(t)||void 0===fcn_voices[t]){let e=fcn_voices.findIndex((t=>"Samantha"===t.name&&("en-US"===t.lang||"en_US"===t.lang)));e<0&&(e=fcn_voices.findIndex((t=>"en-US"===t.lang||"en_US"===t.lang))),t=e>-1?e:0}fcn_utter.voice=fcn_voices[t],_$$$("tts-voice-select").value=t,fcn_ttsSettings.voice=t,fcn_setTTSsettings(fcn_ttsSettings)}function fcn_updateVolume(t){t=fcn_clamp(0,100,t=isNaN(t)?100:parseInt(t)),_$$$("tts-volume-range").value=t,_$$$("tts-volume-text").value=t,_$$$("tts-volume-reset").classList.toggle("_modified",100!=t),fcn_ttsSettings.volume=t,fcn_setTTSsettings(fcn_ttsSettings),fcn_utter.volume=t/100}function fcn_updatePitch(t){t=fcn_clamp(.2,1.8,t=isNaN(t)?1:parseFloat(t)),_$$$("tts-pitch-range").value=t,_$$$("tts-pitch-text").value=t,_$$$("tts-pitch-reset").classList.toggle("_modified",1!=t),fcn_ttsSettings.pitch=t,fcn_setTTSsettings(fcn_ttsSettings),fcn_utter.pitch=t}function fcn_updateRate(t){t=fcn_clamp(.2,1.8,t=isNaN(t)?1:parseFloat(t)),_$$$("tts-rate-range").value=t,_$$$("tts-rate-text").value=t,_$$$("tts-rate-reset").classList.toggle("_modified",1!=t),fcn_ttsSettings.rate=t,fcn_setTTSsettings(fcn_ttsSettings),fcn_utter.rate=t}function fcn_readTextStack(){const t=_$(".current-reading");if(0===fcn_ttsStack.length)return fcn_ttsInterface.classList.add("ended"),t&&t.classList.remove("current-reading"),fcn_currentReadingId=-1,void(fcn_ttsCurrentText="");const e=fcn_ttsStack.shift();fcn_ttsCurrentText=e[1],fcn_currentReadingId!=e[0]&&(fcn_currentReadingId=e[0],t&&t.classList.remove("current-reading"),_$$$(fcn_currentReadingId).classList.add("current-reading")),fcn_utter.text=fcn_ttsCurrentText,fcn_utter.addEventListener("end",fcn_readTextStack,{once:!0}),fcn_synth.speak(fcn_utter)}"undefined"!=typeof speechSynthesis&&fcn_ttsInterface&&(_$$$("button-tts-set").addEventListener("click",(t=>{fcn_ttsStack=[],fcn_currentReadingId=-1;const e=_$(".chapter-formatting")?.classList.contains("hide-sensitive")??!1?"sensitive-content":"sensitive-alternative",n=_$$$("button-tts-play"),a=new RegExp(fcn_ttsInterface.dataset.regex,"gm");fcn_synth.speaking&&fcn_utter.removeEventListener("end",fcn_readTextStack),fcn_synth.cancel();const o=new Set(["P","H1","H2","H3","H4","H5","H6"]),c=["skip-tts","inside-epub",e];let s=t.target.closest("p[data-paragraph-id]");for(fcn_ttsStack.push(s);s=s.nextElementSibling;)o.has(s.tagName)&&!c.some((t=>s.classList.contains(t)))&&fcn_ttsStack.push(s);fcn_ttsStack=fcn_ttsStack.flatMap((t=>{const e=[],n=t.querySelector(".paragraph-inner");return(n?n.textContent:t.textContent).replace(a,"$1|").split("|").forEach((n=>{const a=n.trim();a.length>0&&e.push([t.id,a])})),e})),fcn_readTextStack(),fcn_theBody.classList.add("tts-open"),fcn_ttsInterface.classList.remove("hidden","ended","paused"),fcn_ttsInterface.classList.add("playing"),n.focus(),n.blur()})),_$$$("button-tts-stop")?.addEventListener("click",(()=>{const t=_$(".current-reading");fcn_ttsInterface.classList.add("hidden","ended"),fcn_ttsInterface.classList.remove("playing","paused"),fcn_theBody.classList.remove("tts-open"),t&&t.classList.remove("current-reading"),fcn_ttsStack=[],fcn_currentReadingId=-1,fcn_utter.removeEventListener("end",fcn_readTextStack),fcn_synth.cancel()})),_$$$("button-tts-play")?.addEventListener("click",(()=>{fcn_synth.resume(),-1!==fcn_ttsPauseTimestamp&&Date.now()-fcn_ttsPauseTimestamp>1e4&&(fcn_ttsStack.unshift([fcn_currentReadingId,fcn_ttsCurrentText]),fcn_synth.cancel(),fcn_readTextStack(),fcn_ttsPauseTimestamp=-1),fcn_ttsInterface.classList.add("playing"),fcn_ttsInterface.classList.remove("paused")})),_$$$("button-tts-pause")?.addEventListener("click",(()=>{fcn_synth.pause(),fcn_ttsPauseTimestamp=Date.now(),fcn_ttsInterface.classList.remove("playing"),fcn_ttsInterface.classList.add("paused")})),_$$$("button-tts-skip")?.addEventListener("click",(()=>{fcn_utter.removeEventListener("end",fcn_readTextStack),fcn_synth.cancel(),fcn_readTextStack(),fcn_ttsInterface.classList.remove("paused"),fcn_ttsInterface.classList.add("playing")})),_$$$("button-tts-scroll")?.addEventListener("click",(()=>{fcn_scrollTo(_$(`p[id="${fcn_currentReadingId}"]`),128)})),_$$("#tts-volume-range, #tts-volume-text").forEach((t=>{t.addEventListener("input",(t=>{fcn_updateVolume(t.target.value)}))})),_$$$("tts-volume-reset")?.addEventListener("click",(()=>{fcn_updateVolume(100)})),_$$("#tts-pitch-range, #tts-pitch-text").forEach((t=>{t.addEventListener("input",(t=>{fcn_updatePitch(t.target.value)}))})),_$$$("tts-pitch-reset")?.addEventListener("click",(()=>{fcn_updatePitch(1)})),_$$("#tts-rate-range, #tts-rate-text").forEach((t=>{t.addEventListener("input",(t=>{fcn_updateRate(t.target.value)}))})),_$$$("tts-rate-reset")?.addEventListener("click",(()=>{fcn_updateRate(1)})),window.addEventListener("beforeunload",(()=>{fcn_synth.cancel()})));var fcn_storyCommentPage=1,fcn_storySettings=fcn_getStorySettings();function fcn_getStorySettings(){let t=fcn_parseJSON(localStorage.getItem("fcnStorySettings"))??fcn_defaultStorySettings();return(!t.hasOwnProperty("timestamp")||t.timestamp<1674770712849)&&(t=fcn_defaultStorySettings(),t.timestamp=Date.now()),fcn_setStorySettings(t),t}function fcn_defaultStorySettings(){return{view:"list",order:"asc",timestamp:1674770712849}}function fcn_setStorySettings(t){"object"==typeof t&&(fcn_storySettings=t,localStorage.setItem("fcnStorySettings",JSON.stringify(t)))}function fcn_applyStorySettings(){"object"==typeof fcn_storySettings&&(_$$("[data-view]").forEach((t=>{t.dataset.view="grid"==fcn_storySettings.view?"grid":"list"})),_$$("[data-order]").forEach((t=>{t.dataset.order="desc"==fcn_storySettings.order?"desc":"asc"})))}function fcn_toggleStoryTab(t){const e=t.closest(".story");e.querySelectorAll(".story__tab-target._current, .story__tabs ._current").forEach((t=>{t.classList.remove("_current")})),e.querySelectorAll(`[data-finder="${t.dataset.target}"]`).forEach((t=>{t.classList.add("_current")})),e.querySelector(".story__tabs").dataset.current=t.dataset.target,t.classList.add("_current")}function fcn_loadStoryComments(t){let e;_$(".load-more-list-item").remove(),_$(".comments-loading-placeholder").classList.remove("hidden"),fcn_ajaxGet({post_id:t.dataset.storyId??fcn_inlineStorage.postId,page:fcn_storyCommentPage},"get_story_comments").then((t=>{t.success?(_$(".fictioneer-comments__list > ul").innerHTML+=t.data.html,fcn_storyCommentPage++):t.data?.error&&(e=fcn_buildErrorNotice(t.data.error))})).catch((t=>{e=fcn_buildErrorNotice(t)})).then((()=>{_$(".comments-loading-placeholder").remove(),e&&_$(".fictioneer-comments__list > ul").appendChild(e)}))}function fcn_startEpubDownload(t,e=0){e>3?t.classList.remove("ajax-in-progress"):fcn_ajaxGet({action:"fictioneer_ajax_download_epub",story_id:t.dataset.storyId}).then((n=>{n.success?(window.location.href=t.href,setTimeout((()=>{t.classList.remove("ajax-in-progress")}),2e3)):setTimeout((()=>{fcn_startEpubDownload(t,e+1)}),2e3)})).catch((e=>{t.classList.remove("ajax-in-progress"),e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")}))}function fcn_replaceProfileImage(t,e){const n=t.querySelector(".user-icon");if(n){const a=document.createElement("img");a.classList.add("user-profile-image"),a.src=e,n.remove(),t.appendChild(a)}}function fcn_setProfileImage(t,e=!0){t&&fcn_isValidUrl(t)&&(e&&localStorage.setItem("fcnProfileAvatar",t),_$$("a.subscriber-profile")?.forEach((e=>{fcn_replaceProfileImage(e,t)})),!1===fcn_getUserData().loggedIn&&fcn_prepareLogin())}function fcn_getProfileImage(){let t=localStorage.getItem("fcnProfileAvatar");fcn_isLoggedIn?(fcn_isValidUrl(t)||(t=!1),t?fcn_setProfileImage(t):fcn_getUserAvatar()):localStorage.removeItem("fcnProfileAvatar")}function fcn_getUserAvatar(){fcn_ajaxGet({action:"fictioneer_ajax_get_avatar",fcn_fast_ajax:1}).then((t=>{t.success&&fcn_setProfileImage(t.data.url)})).catch((()=>{fcn_theRoot.dataset.defaultAvatar&&fcn_setProfileImage(fcn_theRoot.dataset.defaultAvatar,!1)}))}function fcn_getUserData(){return fcn_parseJSON(localStorage.getItem("fcnUserData"))??{lastLoaded:0,timestamp:0,loggedIn:"pending",follows:!1,reminders:!1,checkmarks:!1,bookmarks:{},fingerprint:!1}}function fcn_setUserData(t){localStorage.setItem("fcnUserData",JSON.stringify(t))}function fcn_fetchUserData(){let t=fcn_getUserData();if(fcn_isLoggedIn&&!1===t.loggedIn&&(fcn_prepareLogin(),t=fcn_getUserData()),fcn_ajaxLimitThreshold{if(t.success){let e=fcn_getUserData();e=t.data,e.lastLoaded=Date.now(),fcn_setUserData(e);const n=new CustomEvent("fcnUserDataReady",{detail:{data:t.data,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(n)}else{const e=fcn_getUserData();e.lastLoaded=Date.now(),e.loggedIn=!1,fcn_setUserData(e);const n=new CustomEvent("fcnUserDataFailed",{detail:{response:t,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(n)}})).catch((t=>{localStorage.removeItem("fcnUserData");const e=new CustomEvent("fcnUserDataError",{detail:{error:t,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(e)}))}function fcn_unsetOauth(t){const e=prompt(t.dataset.warning);if(!e||e.toLowerCase()!=t.dataset.confirm.toLowerCase())return;const n=_$$$(`oauth-${t.dataset.channel}`);n.classList.add("ajax-in-progress"),fcn_ajaxPost(payload={action:"fictioneer_ajax_unset_my_oauth",nonce:t.dataset.nonce,channel:t.dataset.channel,id:t.dataset.id}).then((t=>{t.success?(n.classList.remove("_connected"),n.classList.add("_disconnected"),n.querySelector("button").remove(),fcn_showNotification(n.dataset.unset)):(n.style.background="var(--notice-warning-background)",fcn_showNotification(t.data.error,5,"warning"))})).catch((t=>{t.status&&t.statusText&&(n.style.background="var(--notice-warning-background)",fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"))})).then((()=>{n.classList.remove("ajax-in-progress")}))}function fcn_deleteMyAccount(t){if(_$$$("button-delete-my-account").hasAttribute("disabled"))return;const e=prompt(t.dataset.warning);e&&e.toLowerCase()==t.dataset.confirm.toLowerCase()&&(_$$$("button-delete-my-account").setAttribute("disabled",!0),fcn_ajaxPost({action:"fictioneer_ajax_delete_my_account",nonce:t.dataset.nonce,id:t.dataset.id}).then((t=>{t.success?location.reload():(fcn_showNotification(t.data.error,5,"warning"),_$$$("button-delete-my-account").innerHTML=t.data.button)})).catch((t=>{t.status&&t.statusText&&(fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),_$$$("button-delete-my-account").innerHTML=response.data.button)})))}fcn_applyStorySettings(),_$$('[data-click-action*="toggle-chapter-order"]').forEach((t=>{t.addEventListener("click",(t=>{fcn_storySettings.order="asc"===t.currentTarget.dataset.order?"desc":"asc",fcn_setStorySettings(fcn_storySettings),fcn_applyStorySettings()}))})),_$$('[data-click-action*="toggle-chapter-view"]').forEach((t=>{t.addEventListener("click",(t=>{fcn_storySettings.view="list"===t.currentTarget.dataset.view?"grid":"list",fcn_setStorySettings(fcn_storySettings),fcn_applyStorySettings()}))})),_$$(".chapter-group__folding-toggle").forEach((t=>{t.addEventListener("click",(t=>{const e=t.currentTarget.closest(".chapter-group[data-folded]");e&&(e.dataset.folded="true"==e.dataset.folded?"false":"true")}))})),_$$(".tabs__item").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleStoryTab(t.currentTarget)}))})),_$(".comment-section")?.addEventListener("click",(t=>{t.target?.classList.contains("load-more-comments-button")&&fcn_loadStoryComments(t.target)})),_$$('[data-action="download-epub"]').forEach((t=>{t.addEventListener("click",(t=>{t.preventDefault(),t.currentTarget.classList.contains("ajax-in-progress")||(t.currentTarget.classList.add("ajax-in-progress"),fcn_startEpubDownload(t.currentTarget))}))})),document.addEventListener("DOMContentLoaded",(()=>{fcn_isLoggedIn&&!fcn_theRoot.dataset.ajaxAuth&&fcn_getProfileImage()})),fcn_theRoot.dataset.ajaxAuth&&document.addEventListener("fcnAuthReady",(()=>{fcn_getProfileImage()})),document.addEventListener("DOMContentLoaded",(()=>{fcn_isLoggedIn&&!fcn_theRoot.dataset.ajaxAuth&&fcn_fetchUserData()})),_$$(".button-unset-oauth").forEach((t=>{t.addEventListener("click",(t=>{fcn_unsetOauth(t.currentTarget)}))})),_$$$("button-delete-my-account")?.addEventListener("click",(t=>{ fcn_deleteMyAccount(t.currentTarget)}));const fcn_profileDataTranslations=_$$$("profile-data-translations")?.dataset;function fcn_dataDeletionPrompt(t){const e=prompt(t.dataset.warning);return!(!e||e.toLowerCase()!=t.dataset.confirm.toLowerCase())}function fcn_clearData(t,e){const n=t.closest(".card");localStorage.removeItem("fcnBookshelfContent"),n.classList.add("ajax-in-progress"),t.remove(),fcn_ajaxPost({action:e,fcn_fast_ajax:1,nonce:t.dataset.nonce}).then((t=>{t.success?n.querySelector(".card__content").innerHTML=t.data.success:fcn_showNotification(t.data.error,10,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,10,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")}))}_$(".button-clear-comments")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_comments")})),_$(".button-clear-comment-subscriptions")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_comment_subscriptions")})),_$(".button-clear-checkmarks")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.checkmarks={data:{},updated:Date.now()},fcn_setUserData(e),fcn_updateCheckmarksView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_checkmarks",!0)})),_$(".button-clear-reminders")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.reminders={data:{}},fcn_setUserData(e),fcn_updateRemindersView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_reminders",!0)})),_$(".button-clear-follows")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.follows={data:{}},fcn_setUserData(e),fcn_updateFollowsView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_follows",!0)})),_$(".button-clear-bookmarks")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.bookmarks="{}",fcn_setUserData(e),fcn_bookmarks.data={},t.currentTarget.closest(".card").querySelector(".card__content").innerHTML=fcn_profileDataTranslations.clearedSuccess,fcn_setBookmarks(fcn_bookmarks)}));const fcn_jumpToBookmarkButtons=_$$(".button--bookmark"),fcn_mobileBookmarkJump=_$$$("mobile-menu-bookmark-jump"),fcn_mobileBookmarkList=_$(".mobile-menu__bookmark-list"),fcn_bookmarksSmallCardBlock=_$(".bookmarks-block"),fcn_bookmarksSmallCardTemplate=_$(".bookmark-small-card-template");var fcn_bookmarks,fcn_userBookmarksTimeout;function fcn_initializeLocalBookmarks(){fcn_setBookmarks(fcn_bookmarks=fcn_getBookmarks(),!0),fcn_updateBookmarksView()}function fcn_initializeUserBookmarks(t){fcn_setBookmarks(JSON.parse(t.detail.data.bookmarks),!0),fcn_updateBookmarksView()}function fcn_getBookmarks(){let t=fcn_parseJSON(localStorage.getItem("fcnChapterBookmarks"))??{data:{}};return Array.isArray(t.data)&&0===t.data.length&&(t.data={}),t=fcn_fixBookmarks(t),!t||Object.keys(t).length<1?{data:{}}:t}function fcn_fixBookmarks(t){const e={};for(const n in t.data)if(n.startsWith("ch-")){const a=fcn_fixBookmarksNode(t.data[n]);a&&(e[n]=a)}return{data:e}}function fcn_fixBookmarksNode(t){const e={},n={"paragraph-id":"",progress:0,date:"",color:"",chapter:"",link:"",thumb:"",image:"",story:"",content:""};for(const a in n){if(typeof t[a]!=typeof n[a])return null;e[a]=t[a]}const a=new Date(e.date);return a&&"[object Date]"===Object.prototype.toString.call(a)&&!isNaN(a)||(e.date=(new Date).toISOString()),("number"!=typeof e.progress||e.progress<0)&&(e.progress=0),e}function fcn_setBookmarks(t,e=!1){if("object"==typeof t){if(fcn_bookmarks=t,localStorage.setItem("fcnChapterBookmarks",JSON.stringify(t)),fcn_isLoggedIn){const e=fcn_getUserData();e&&(e.bookmarks=JSON.stringify(t),fcn_setUserData(e))}e||fcn_saveUserBookmarks(t)}}function fcn_updateBookmarksView(){if(!fcn_bookmarks||!fcn_bookmarks.data)return;const t=_$(".profile-bookmarks-stats"),e=Object.keys(fcn_bookmarks.data).length;t&&(t.innerHTML=t.innerHTML.replace("%s",e)),e>0&&_$$(".icon-menu-bookmarks").forEach((t=>{t.classList.remove("hidden")})),fcn_showBookmarkCards(),fcn_showChapterBookmark()}function fcn_saveUserBookmarks(t){fcn_isLoggedIn&&(clearTimeout(fcn_userBookmarksTimeout),t=fcn_fixBookmarks(t),fcn_userBookmarksTimeout=setTimeout((()=>{fcn_ajaxPost({action:"fictioneer_ajax_save_bookmarks",fcn_fast_ajax:1,bookmarks:JSON.stringify(t)}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,3,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,3,"warning")}))}),fictioneer_ajax.post_debounce_rate))}function fcn_toggleBookmark(t,e="none"){fcn_bookmarks=fcn_getBookmarks();const n=_$(".chapter__article"),a=_$(".current-bookmark");if(!n)return;const o=fcn_bookmarks.data[n.id];if(o&&o["paragraph-id"]==t&&a)"none"!=e&&e!=o.color?(_$(".current-bookmark").dataset.bookmarkColor=e,o.color=e):fcn_removeBookmark(n.id);else{Object.keys(fcn_bookmarks.data).length>=50&&fcn_removeBookmark(Object.keys(fcn_bookmarks.data)[0]);const o=_$(`[data-paragraph-id="${t}"]`),c=_$$$("chapter-bookmark-data").dataset;fcn_bookmarks.data[n.id]={"paragraph-id":t,progress:100*(fcn_offset(o).top-fcn_offset(o.parentElement).top)/o.parentElement.clientHeight,date:(new Date).toISOString(),color:e,chapter:c.title.trim(),link:c.link,thumb:c.thumb,image:c.image,story:c.storyTitle.trim(),content:o.querySelector("span").innerHTML.substring(0,128)+"…"},fcn_jumpToBookmarkButtons.forEach((t=>{t.classList.remove("hidden")})),fcn_mobileBookmarkJump?.removeAttribute("hidden"),a?.classList.remove("current-bookmark"),o.classList.add("current-bookmark"),o.setAttribute("data-bookmark-color",e)}fcn_setMobileMenuBookmarks(),fcn_setBookmarks(fcn_bookmarks)}function fcn_showChapterBookmark(){_$(".current-bookmark")?.classList.remove("current-bookmark");const t=_$(".chapter__article");if(!t||!fcn_bookmarks.data[t.id])return;const e=fcn_bookmarks.data[t.id]["paragraph-id"],n=_$(`[data-paragraph-id="${e}"]`),a=fcn_bookmarks.data[t.id].color??"none";e&&n&&(fcn_jumpToBookmarkButtons.forEach((t=>{t.classList.remove("hidden")})),fcn_mobileBookmarkJump?.removeAttribute("hidden"),n.classList.add("current-bookmark"),n.setAttribute("data-bookmark-color",a))}function fcn_setMobileMenuBookmarks(){fcn_mobileBookmarkList.innerHTML="";const t=Object.entries(fcn_bookmarks.data),e=_$("#mobile-bookmark-template");if(t.length>0){const n=document.createDocumentFragment();t.forEach((([t,{color:a,progress:o,link:c,chapter:s,"paragraph-id":i}])=>{const r=e.content.cloneNode(!0),l=r.querySelector(".mobile-menu__bookmark");l.classList.add(`bookmark-${t}`),l.dataset.color=a,r.querySelector(".mobile-menu__bookmark-progress > div > div").style.width=`${o.toFixed(1)}%`,r.querySelector(".mobile-menu__bookmark a").href=`${c}#paragraph-${i}`,r.querySelector(".mobile-menu__bookmark a span").innerText=s,r.querySelector(".mobile-menu-bookmark-delete-button").setAttribute("data-bookmark-id",t),n.appendChild(r)})),fcn_mobileBookmarkList.appendChild(n),fcn_bookmarkDeleteHandler(_$$(".mobile-menu-bookmark-delete-button"))}else{const t=document.createElement("li");t.classList.add("no-bookmarks"),t.textContent=fcn_mobileBookmarkList.dataset.empty,fcn_mobileBookmarkList.appendChild(t)}}function fcn_showBookmarkCards(){if(!fcn_bookmarks||!fcn_bookmarksSmallCardBlock||!fcn_bookmarksSmallCardTemplate||Object.keys(fcn_bookmarks.data).length<1||_$(".bookmark-card"))return;fcn_bookmarksSmallCardBlock.classList.remove("hidden"),_$(".bookmarks-block__no-bookmarks")?.remove(),_$$(".show-if-bookmarks").forEach((t=>t.classList.remove("hidden")));let t=parseInt(fcn_bookmarksSmallCardBlock.dataset.count);const e=document.createDocumentFragment();Object.entries(fcn_bookmarks.data).sort(((t,e)=>new Date(e[1].date)-new Date(t[1].date))).forEach((([n,{color:a,progress:o,link:c,chapter:s,"paragraph-id":i,date:r,image:l,thumb:f,content:d}])=>{if(0==t)return;t--;const _=fcn_bookmarksSmallCardTemplate.content.cloneNode(!0),h=new Date(r).toLocaleDateString(navigator.language??"en-US",{year:"2-digit",month:"short",day:"numeric"});l?(_.querySelector(".bookmark-card__image").href=l,_.querySelector(".bookmark-card__image img").src=f):_.querySelector(".bookmark-card__image").remove(),_.querySelector(".bookmark-card__excerpt").innerHTML+=d,_.querySelector(".bookmark-card").classList.add(`bookmark-${n}`),_.querySelector(".bookmark-card").dataset.color=a,_.querySelector(".bookmark-card__title > a").href=`${c}#paragraph-${i}`,_.querySelector(".bookmark-card__title > a").innerText=s,_.querySelector(".bookmark-card__percentage").innerText=`${o.toFixed(1)} %`,_.querySelector(".bookmark-card__progress").style.width=`${o.toFixed(1)}%`,_.querySelector("time").innerText=h,_.querySelector(".button-delete-bookmark").setAttribute("data-bookmark-id",n),e.appendChild(_)})),fcn_bookmarksSmallCardBlock.querySelector("ul").appendChild(e),fcn_bookmarkDeleteHandler(_$$(".button-delete-bookmark"))}function fcn_bookmarkDeleteHandler(t){("object"==typeof t?t:[t]).forEach((t=>{t.addEventListener("click",(t=>{fcn_removeBookmark(t.currentTarget.dataset.bookmarkId),fcn_setBookmarks(fcn_bookmarks),Object.keys(fcn_bookmarks.data).length<1&&(_$(".bookmarks-block")?.classList.add("hidden"),_$$(".show-if-bookmarks").forEach((t=>{t.classList.add("hidden")})))}))}))}function fcn_removeBookmark(t){const e=_$(".chapter__article"),n=_$(".current-bookmark");delete fcn_bookmarks.data[t],e&&e.id==t&&(fcn_jumpToBookmarkButtons.forEach((t=>{t.classList.add("hidden")})),fcn_mobileBookmarkJump?.setAttribute("hidden",!0),n&&(n.classList.remove("current-bookmark"),n.removeAttribute("data-bookmark-color"))),_$$(`.bookmark-${t}`)?.forEach((t=>{t.remove()}))}fcn_initializeLocalBookmarks(),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeUserBookmarks(t)})),fcn_jumpToBookmarkButtons.forEach((t=>{t.addEventListener("click",(()=>{fcn_scrollTo(_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`))}))}));const fcn_followsMenuItem=_$$$("follow-menu-button");var fcn_userFollowsTimeout,fcn_follows,fcn_checkmarks,fcn_userCheckmarksTimeout,fcn_userRemindersTimeout,fcn_reminders;function fcn_initializeFollows(t){const e=t.detail.data.follows;!1!==e&&(Array.isArray(e.data)&&0===e.data.length&&(e.data={}),fcn_follows=e,fcn_updateFollowsView(),localStorage.removeItem("fcnBookshelfContent"))}function fcn_toggleFollow(t){const e=fcn_getUserData();if(fcn_follows&&e.follows){if(localStorage.removeItem("fcnBookshelfContent"),JSON.stringify(fcn_follows.data[t])!==JSON.stringify(e.follows.data[t]))return fcn_follows=e.follows,fcn_showNotification(fictioneer_tl.notification.followsResynchronized),void fcn_updateFollowsView();fcn_follows.data.hasOwnProperty(t)?delete fcn_follows.data[t]:fcn_follows.data[t]={story_id:parseInt(t),timestamp:Date.now()},e.follows.data[t]=fcn_follows.data[t],e.lastLoaded=0,fcn_setUserData(e),fcn_updateFollowsView(),clearTimeout(fcn_userFollowsTimeout),fcn_userFollowsTimeout=setTimeout((()=>{fcn_ajaxPost({action:"fictioneer_ajax_toggle_follow",fcn_fast_ajax:1,story_id:t,set:fcn_follows.data.hasOwnProperty(t)}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{429===t.status?fcn_showNotification(fictioneer_tl.notification.slowDown,3,"warning"):t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}),fictioneer_ajax.post_debounce_rate)}}function fcn_updateFollowsView(){const t=fcn_getUserData();if(!fcn_follows||!t.follows)return;_$$(".button-follow-story").forEach((t=>{t.classList.toggle("_followed",fcn_follows?.data.hasOwnProperty(t.dataset.storyId))})),_$$(".card").forEach((t=>{t.classList.toggle("has-follow",fcn_follows?.data.hasOwnProperty(t.dataset.storyId))}));const e=parseInt(fcn_follows.new)>0;_$$(".mark-follows-read, .follows-alert-number, .mobile-menu-button").forEach((t=>{t.classList.toggle("_new",e),e>0&&(t.dataset.newCount=fcn_follows.new)}))}function fcn_setupFollowsHTML(){fcn_followsMenuItem.classList.contains("_loaded")||fcn_ajaxGet({action:"fictioneer_ajax_get_follows_notifications",fcn_fast_ajax:1}).then((t=>{if(t.data.html){const e=_$$$("follow-menu-scroll");e&&(e.innerHTML=t.data.html);const n=_$$$("mobile-menu-follows-list");n&&(n.innerHTML=t.data.html),!1===fcn_getUserData().loggedIn&&(fcn_prepareLogin(),fcn_fetchUserData())}})).catch((t=>{429===t.status?fcn_showNotification(fictioneer_tl.notification.slowDown,3,"warning"):t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),_$$$("follow-menu-scroll")?.remove(),_$$$("mobile-menu-follows-list")?.remove()})).then((()=>{fcn_followsMenuItem.classList.add("_loaded")}))}function fcn_markFollowsRead(){if(!fcn_followsMenuItem.classList.contains("_new")||!fcn_followsMenuItem.classList.contains("_loaded"))return;_$$(".mark-follows-read, .follows-alert-number, .follow-item, .mobile-menu-button").forEach((t=>{t.classList.remove("_new")}));const t=fcn_getUserData();t.new=0,t.lastLoaded=0,fcn_setUserData(t),fcn_ajaxPost({action:"fictioneer_ajax_mark_follows_read",fcn_fast_ajax:1}).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}function fcn_initializeCheckmarks(t){const e=t.detail.data.checkmarks;!1!==e&&(Array.isArray(e.data)&&0===e.data.length&&(e.data={}),fcn_checkmarks=e,fcn_updateCheckmarksView(),localStorage.removeItem("fcnBookshelfContent"),_$$("button.checkmark").forEach((t=>{t.addEventListener("click",(t=>{fcn_clickCheckmark(t.currentTarget)}))})))}function fcn_toggleCheckmark(t,e,n=null,a=null,o="toggle"){const c=fcn_getUserData();if(fcn_checkmarks&&c.checkmarks){if(localStorage.removeItem("fcnBookshelfContent"),"toggle"===o&&JSON.stringify(fcn_checkmarks.data[t])!==JSON.stringify(c.checkmarks.data[t]))return fcn_checkmarks=c.checkmarks,fcn_showNotification(fictioneer_tl.notification.checkmarksResynchronized),void fcn_updateCheckmarksView();if(fcn_checkmarks.data.hasOwnProperty(t)||(fcn_checkmarks.data[t]=[]),c.checkmarks.data.hasOwnProperty(t)||(c.checkmarks.data[t]=[]),n&&"progress"===e&&!fcn_checkmarks.data[t].includes(n)&&fcn_checkmarks.data[t].push(n),n&&"chapter"===e)if(!fcn_checkmarks.data[t].includes(n)&&"unset"!==o||"set"===o)fcn_checkmarks.data[t].push(n),a&&(a.classList.add("marked"),a.setAttribute("aria-checked",!0));else{fcn_removeItemOnce(fcn_checkmarks.data[t],n),a&&(a.classList.remove("marked"),a.setAttribute("aria-checked",!1)),fcn_removeItemOnce(fcn_checkmarks.data[t],t);const e=_$('button[data-type="story"]');e&&(e.classList.remove("marked"),e.setAttribute("aria-checked",!1))}if("story"===e){const e=(fcn_checkmarks.data[t].includes(t)||"unset"===o)&&"set"!==o;fcn_checkmarks.data[t]=[],e||(_$$("button.checkmark").forEach((e=>{fcn_checkmarks.data[t].push(parseInt(e.dataset.id))})),fcn_checkmarks.data[t].includes(t)||fcn_checkmarks.data[t].push(t))}fcn_checkmarks.data[t]=fcn_checkmarks.data[t].filter(((t,e,n)=>n.indexOf(t)==e)),c.checkmarks.data[t]=fcn_checkmarks.data[t],c.lastLoaded=0,fcn_setUserData(c),fcn_updateCheckmarksView(),clearTimeout(fcn_userCheckmarksTimeout),fcn_userCheckmarksTimeout=setTimeout((()=>{fcn_updateCheckmarks(t,fcn_checkmarks.data[t])}),fictioneer_ajax.post_debounce_rate)}}function fcn_clickCheckmark(t){fcn_toggleCheckmark(parseInt(t.dataset.storyId),t.dataset.type,parseInt(t.dataset.id),t)}function fcn_updateCheckmarks(t,e=null){fcn_ajaxPost({action:"fictioneer_ajax_set_checkmark",fcn_fast_ajax:1,story_id:t,update:(e=e||fcn_getUserData().checkmarks.data[t]).join(" ")}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,3,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}function fcn_updateCheckmarksView(){const t=fcn_getUserData(),e=t.checkmarks;if(!e)return;const n=parseInt(fcn_inlineStorage.storyId);if(n){const a=e.data.hasOwnProperty(n)&&e.data[n].includes(n);if(a){let a=!1;_$$("button.checkmark").forEach((t=>{const o=parseInt(t.dataset.id);e.data[n].includes(o)||(e.data[n].push(o),a=!0)})),a&&(t.checkmarks=e,fcn_setUserData(t),fcn_updateCheckmarks(n,e.data[n]))}_$$$("ribbon-read")?.classList.toggle("hidden",!a)}_$$("button.checkmark").forEach((t=>{const n=parseInt(t.dataset.storyId);if(e.data.hasOwnProperty(n)){const a=e.data[n].includes(parseInt(t.dataset.id));t.classList.toggle("marked",a),t.setAttribute("aria-checked",a)}})),_$$(".card").forEach((t=>{const n=parseInt(t.dataset.storyId),a=e.data.hasOwnProperty(n)&&(e.data[n].includes(parseInt(t.dataset.checkId))||e.data[n].includes(n));t.classList.toggle("has-checkmark",a)}))}function fcn_initializeReminders(t){const e=t.detail.data.reminders;!1!==e&&(Array.isArray(e.data)&&0===e.data.length&&(e.data={}),fcn_reminders=e,fcn_updateRemindersView(),localStorage.removeItem("fcnBookshelfContent"))}function fcn_toggleReminder(t){const e=fcn_getUserData();if(fcn_reminders&&e.reminders){if(localStorage.removeItem("fcnBookshelfContent"),JSON.stringify(fcn_reminders.data[t])!==JSON.stringify(e.reminders.data[t]))return fcn_reminders=e.reminders,fcn_showNotification(fictioneer_tl.notification.remindersResynchronized),void fcn_updateRemindersView();fcn_reminders.data.hasOwnProperty(t)?delete fcn_reminders.data[t]:fcn_reminders.data[t]={story_id:parseInt(t),timestamp:Date.now()},e.reminders.data[t]=fcn_reminders.data[t],e.lastLoaded=0,fcn_setUserData(e),fcn_updateRemindersView(),clearTimeout(fcn_userRemindersTimeout),fcn_userRemindersTimeout=setTimeout((()=>{fcn_ajaxPost({action:"fictioneer_ajax_toggle_reminder",fcn_fast_ajax:1,story_id:t,set:fcn_reminders.data.hasOwnProperty(t)}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{429===t.status?fcn_showNotification(fictioneer_tl.notification.slowDown,3,"warning"):t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}),fictioneer_ajax.post_debounce_rate)}}function fcn_updateRemindersView(){const t=fcn_getUserData();fcn_reminders&&t.reminders&&(_$$(".button-read-later").forEach((t=>{t.classList.toggle("_remembered",fcn_reminders.data.hasOwnProperty(t.dataset.storyId))})),_$$(".card").forEach((t=>{t.classList.toggle("has-reminder",fcn_reminders?.data.hasOwnProperty(t.dataset.storyId))})))}function fcn_addJSTrap(){const t=document.querySelector(".comment-form");t&&t.appendChild(fcn_html` - `)}function fcn_moderateComment(t,e){const n=_$$$(`comment-${t}`),a=n.querySelector(".mod-menu-toggle-icon");n.classList.contains("ajax-in-progress")||(n.classList.add("ajax-in-progress"),"trash"!=e&&"spam"!=e||(n.style.height=n.clientHeight+"px"),fcn_ajaxPost({action:"fictioneer_ajax_moderate_comment",operation:e,id:t}).then((t=>{if(t.success)switch(t.data.operation){case"sticky":n.classList.add("_sticky");break;case"unsticky":n.classList.remove("_sticky");break;case"approve":n.classList.remove("_unapproved");break;case"unapprove":n.classList.add("_unapproved");break;case"open":n.classList.remove("_closed");break;case"close":n.classList.add("_closed");break;case"trash":case"spam":n.style.cssText="overflow: hidden; height: 0; margin: 0; opacity: 0;"}else a.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",a.style.color="var(--notice-warning-background)",n.querySelector(".popup-menu-toggle").style.opacity="1",t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{a.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",a.style.color="var(--notice-warning-background)",n.querySelector(".popup-menu-toggle").style.opacity="1",t.status&&t.statusText?fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"):t&&fcn_showNotification(t,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),fcn_lastClicked?.classList.remove("last-clicked"),fcn_lastClicked=null})))}function fcn_addCommentMouseleaveEvents(){_$$(".fictioneer-comment__container").forEach((t=>{t.addEventListener("mouseleave",(t=>{fcn_lastClicked?.classList.remove("last-clicked"),fcn_lastClicked=null,t.stopPropagation()}))}))}function fcn_flagComment(t){if(!fcn_isLoggedIn)return;const e=t.closest(".fictioneer-comment"),n=e.querySelector(".fictioneer-report-comment-button");e.classList.contains("ajax-in-progress")||(e.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_report_comment",id:e.dataset.id,dubious:n.classList.contains("_dubious")}).then((t=>{t.success?(n.classList.toggle("on",t.data.flagged),n.classList.remove("_dubious"),t.data.resync&&fcn_showNotification(t.data.resync)):t.data?.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{e.classList.remove("ajax-in-progress")})))}function fcn_revealCommentFormInputs(t){t.closest("form").querySelectorAll(".fictioneer-respond__form-actions, .fictioneer-respond__form-bottom").forEach((t=>{t.classList.remove("hidden")}))}function fcn_addCommentFormEvents(){_$$$("comment")?.addEventListener("focus",(t=>{fcn_revealCommentFormInputs(t.currentTarget)}),{once:!0})}function fcn_textareaAdjust(t){t.style.height="auto",t.style.height=`${t.scrollHeight}px`}function fcn_wrapInTag(t,e,n={}){const a=n.href?' href="'+n.href+'" target="_blank" rel="nofollow noreferrer noopener"':"",o=n.shortcode?["[","]"]:["<",">"],c=t.selectionStart,s=t.selectionEnd,i=o[0]+e+a+o[1],r=o[0]+"/"+e+o[1],l=i+t.value.substring(c,s)+r;t.value=t.value.substring(0,c)+l+t.value.substring(s,t.value.length),t.setSelectionRange(c+i.length,s+i.length),t.focus()}function fcn_bindAJAXCommentSubmit(){fcn_theRoot.dataset.ajaxSubmit&&_$$$("commentform")?.addEventListener("submit",(t=>{if(t.preventDefault(),Date.now()1,a.classList.toggle("_error",!u),i&&(g=i.checked,i.classList.toggle("_error",!g)),c&&c.value.length>0&&(h=/\S+@\S+\.\S+/.test(c.value),c.classList.toggle("_error",!h)),!u||!g||!h)return!1;e.classList.add("ajax-in-progress"),n.disabled=!0,n.value=n.dataset.disabled;const m={action:"fictioneer_ajax_submit_comment",post_id:_$$$("comment_post_ID").value,content:a.value,private_comment:d?.checked??0,notification:_?.checked??0,cookie_consent:s?.checked??0,privacy_consent:i?.checked??0,unfiltered_html:_$$$("_wp_unfiltered_html_comment_disabled")?.value??"",depth:f?parseInt(f.dataset.depth)+1:1,fictioneer_comment_validator:r?.value??0};l&&(m.parent_id=l),c?.value&&(m.email=c?.value),o?.value&&(m.author=o?.value),fcn_ajaxPost(m).then((t=>{if(_$$$("comment-submit-error-notice")?.remove(),t.success&&t.data?.comment){let e=_$(".commentlist"),n="insertBefore";if(e&&!f&&e.firstElementChild){let t=null;if(e.firstElementChild.classList.contains("_sticky"))for(t=e.firstElementChild,e=t,n="insertAfter";t.nextElementSibling&&t.nextElementSibling.classList.contains("_sticky");)t=e.nextElementSibling,e=t}if(e||(e=document.createElement("ol"),e.classList="fictioneer-comments__list commentlist",_$$$("comments").appendChild(e),n="append"),f&&(e=f.querySelector(".children"),n="append",!e)){const t=document.createElement("ol");f.appendChild(t),e=t}let o=document.createElement("div");switch(o.innerHTML=t.data.comment,o=o.firstChild,n){case"append":e.appendChild(o);break;case"insertBefore":e.insertBefore(o,e.firstChild);break;case"insertAfter":e.nextSibling?e.parentNode.insertBefore(o,e.nextSibling):e.parentNode.appendChild(o)}fcn_addCommentMouseleaveEvents(),"0"!=_$$$("comment_parent").value&&_$$$("cancel-comment-reply-link").click(),a.value="",a.style.height="";const c=window.location.protocol+"//"+window.location.host+window.location.pathname;let s="";t.data.commentcode&&(s+=`?commentcode=${t.data.commentcode}`),history.pushState({path:c},"",c+s+`#comment-${t.data.comment_id}`),o.scrollIntoView({behavior:"smooth"})}else e.insertBefore(fcn_buildErrorNotice(t.data?.error??fictioneer_tl.notification.error,"comment-submit-error-notice",!1),e.firstChild)})).catch((t=>{_$$$("comment-submit-error-notice")?.remove(),e.insertBefore(fcn_buildErrorNotice(`${t.status}: ${t.statusText}`,"comment-submit-error-notice"),e.firstChild)})).then((()=>{e.classList.remove("ajax-in-progress"),n.disabled=!1,n.value=n.dataset.enabled}))}))}document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeFollows(t)})),fcn_followsMenuItem?.addEventListener("mouseover",(()=>{fcn_setupFollowsHTML()}),{once:!0}),fcn_followsMenuItem?.addEventListener("focus",(()=>{fcn_setupFollowsHTML()}),{once:!0}),_$('.mobile-menu__frame-button[data-frame-target="follows"]')?.addEventListener("click",(()=>{fcn_setupFollowsHTML()}),{once:!0}),_$$(".button-follow-story").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleFollow(t.currentTarget.dataset.storyId)}))})),_$$(".mark-follows-read").forEach((t=>{t.addEventListener("click",(()=>{fcn_markFollowsRead()}))})),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeCheckmarks(t)})),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeReminders(t)})),_$$(".button-read-later").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleReminder(t.currentTarget.dataset.storyId)}))})),document.addEventListener("fcnUserDataReady",(()=>{fcn_getUserData().fingerprint==fcn_theRoot.dataset.authorFingerprint&&fcn_theBody.classList.add("is-post-author")})),fcn_addJSTrap(),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),_$(".comment-section")?.addEventListener("click",(t=>{const e=t.target.closest("[data-bbcode]");e&&fcn_wrapInTag(_$$$("comment"),e.dataset.bbcode,{shortcode:!0})})),_$(".comment-section")?.addEventListener("keydown",(t=>{if(_$(".fictioneer-comment-toolbar")&&"TEXTAREA"===document.activeElement.tagName&&(t.ctrlKey||t.metaKey)){const e=t.key.toLowerCase();if(["b","i","s","q","h","l"].includes(e)){t.preventDefault();const n={q:"quote",h:"spoiler",l:"link"};fcn_wrapInTag(document.activeElement,n[e]||e,{shortcode:!0})}}})),fcn_bindAJAXCommentSubmit();const fcn_commentEditActionsTemplate=_$(".comment-edit-actions-template");var fcn_commentEditUndos={};function fcn_triggerInlineCommentEdit(t){const e=t.closest(".fictioneer-comment");if(e){const t=e.querySelector(".fictioneer-comment__content"),n=e.querySelector(".fictioneer-comment__edit"),a=e.querySelector(".comment-inline-edit-content");n.appendChild(fcn_commentEditActionsTemplate.content.cloneNode(!0)),fcn_commentEditUndos[e.id]=a.value,e.classList.add("_editing"),t.hidden=!0,n.hidden=!1,a.style.height=`${a.scrollHeight}px`}}function fcn_submitInlineCommentEdit(t){const e=t.closest(".fictioneer-comment"),n=e.querySelector(".fictioneer-comment__edit"),a=e.querySelector(".comment-inline-edit-content").value;let o=e.querySelector(".fictioneer-comment__edit-note");a!=fcn_commentEditUndos[e.id]?e&&(n.classList.add("ajax-in-progress"),t.innerHTML=t.dataset.disabled,t.disabled=!0,fcn_ajaxPost({action:"fictioneer_ajax_edit_comment",comment_id:e.id.replace("comment-",""),content:a}).then((t=>{if(t.success){const n=e.querySelector(".fictioneer-comment__content");n.innerHTML=t.data.content,fcn_restoreComment(e,!1,t.data.raw),o||(o=document.createElement("div")),o.classList.add("fictioneer-comment__edit-note"),o.innerHTML=t.data.edited,n.parentNode.appendChild(o)}else fcn_restoreComment(e,!0),t.data?.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{fcn_restoreComment(e,!0),t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),t.innerHTML=t.dataset.enabled,t.disabled=!1}))):fcn_restoreComment(e,!0)}function fcn_cancelInlineCommentEdit(t){const e=t.closest(".fictioneer-comment");e&&fcn_restoreComment(e,!0)}function fcn_restoreComment(t,e=!1,n=null){t.querySelector(".fictioneer-comment__content").hidden=!1,t.querySelector(".fictioneer-comment__edit").hidden=!0,t.querySelector(".fictioneer-comment__edit-actions")?.remove(),t.classList.remove("_editing"),e&&fcn_commentEditUndos[t.id]?t.querySelector(".comment-inline-edit-content").value=fcn_commentEditUndos[t.id]:n&&(t.querySelector(".comment-inline-edit-content").value=n)}function fcn_revealEditButton(){let t=parseInt(fcn_theRoot.dataset.editTime);t&&(t=t>0?6e4*t:t,_$$(".fictioneer-comment[data-fingerprint]").forEach((e=>{if(fcn_matchFingerprint(e.dataset.fingerprint)){if(t>0&&parseInt(e.dataset.timestamp)+t{if(fcn_matchFingerprint(t.dataset.fingerprint)){const e=t.querySelector(".fictioneer-comment__delete");e&&(e.hidden=!1)}}))}function fcn_deleteMyComment(t){if(!fcn_isLoggedIn)return;const e=prompt(t.dataset.dialogMessage);if(!e||e.toLowerCase()!=t.dataset.dialogConfirm.toLowerCase())return;const n=t.closest(".fictioneer-comment");n.classList.contains("ajax-in-progress")||(n.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_delete_my_comment",comment_id:n.dataset.id}).then((t=>{t.success?(n.classList.add("_deleted"),n.querySelector(".fictioneer-comment__container").innerHTML=t.data.html):t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")})))}document.addEventListener("fcnUserDataReady",(()=>{fcn_revealEditButton()})),document.addEventListener("fcnUserDataReady",(()=>{fcn_revealDeleteButton()}));const fcn_ajaxCommentForm=_$$$("ajax-comment-form-target");function fcn_setupCommentFormObserver(){const t=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentForm(),t.disconnect())}),{rootMargin:"450px",threshold:1});t.observe(fcn_ajaxCommentForm)}function fcn_getCommentForm(){let t;fcn_ajaxGet({action:"fictioneer_ajax_get_comment_form",post_id:_$$$("comments").dataset.postId}).then((e=>{if(e.success){const t=document.createElement("div");t.innerHTML=e.data.html;const n=t.querySelector("#comment_post_ID"),a=t.querySelector("#cancel-comment-reply-link"),o=t.querySelector(".logout-link");n&&(n.value=e.data.postId),a&&(a.href="#respond"),o&&(o.href=_$$$("comments").dataset.logoutUrl),fcn_ajaxCommentForm.innerHTML=t.innerHTML,t.remove(),fcn_applyCommentStack(),fcn_addCommentFormEvents(),fcn_theRoot.dataset.ajaxSubmit&&fcn_bindAJAXCommentSubmit(),fcn_addNonceHTML(e.data.nonceHtml),fcn_addJSTrap()}else t=fcn_buildErrorNotice(e.data.error)})).catch((e=>{t=fcn_buildErrorNotice(e)})).then((()=>{fcn_ajaxCommentForm.classList.remove("comments-skeleton"),t&&(fcn_ajaxCommentForm.innerHTML="",fcn_ajaxCommentForm.appendChild(t))}))}fcn_ajaxCommentForm&&(fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentFormObserver()})):fcn_setupCommentFormObserver());var fcn_commentStack=[];function fcn_applyCommentStack(t=null){(t=t??_$$$("comment"))&&(fcn_commentStack.forEach((e=>{t.value+=e})),fcn_commentStack=[],fcn_textareaAdjust(t))}_$(".fictioneer-comments")?.addEventListener("click",(t=>{const e=t.target.closest("[data-click]");if(e)switch(e?.dataset.click){case"submit-inline-comment-edit":fcn_submitInlineCommentEdit(e);break;case"cancel-inline-comment-edit":fcn_cancelInlineCommentEdit(e);break;case"trigger-inline-comment-edit":fcn_triggerInlineCommentEdit(e);break;case"delete-my-comment":fcn_deleteMyComment(e);break;case"flag-comment":fcn_flagComment(e);break;case"ajax-mod-action":fcn_moderateComment(e.dataset.id,e.dataset.action)}})),_$(".fictioneer-comments")?.addEventListener("input",(t=>{t.target.matches(".adaptive-textarea")&&fcn_textareaAdjust(t.target),t.target.closest("#fictioneer-private-comment-toggle")&&_$$$("respond")?.classList.toggle("_private",t.currentTarget.checked)}));const fcn_commentSection=_$("#comments[data-ajax-comments]");function fcn_getCommentSection(t=null,e=null,n=!1){if(!fcn_commentSection)return;let a,o="",c=_$$$("comment");if(c&&(o=c.value),fcn_commentSection.classList.contains("ajax-in-progress"))return;if(fcn_commentSection.classList.add("ajax-in-progress"),e||(e=fcn_urlParams.pg??1),!fcn_commentSection)return;const s={action:"fictioneer_ajax_get_comment_section",post_id:t??fcn_commentSection.dataset.postId,page:parseInt(e)};fcn_urlParams.commentcode&&(s.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(s).then((t=>{if(t.success){e=t.data.page;const a=document.createElement("div");if(a.innerHTML=t.data.html,a.querySelector("#comment_post_ID")){a.querySelector("#comment_post_ID").value=t.data.postId,a.querySelector("#cancel-comment-reply-link").href="#respond";const e=a.querySelector(".logout-link");e&&(e.href=fcn_commentSection.dataset.logoutUrl)}fcn_commentSection.innerHTML=a.innerHTML,a.remove(),t.data.disabled||(c=_$$$("comment"),c.value=o,fcn_applyCommentStack(c)),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const s=location.hash.includes("#comment")?location.hash:".respond",i=document.querySelector(s)??_$$$("respond");n&&i.scrollIntoView({behavior:"smooth"});const r=window.location.protocol+"//"+window.location.host+window.location.pathname;let l="";fcn_urlParams.commentcode&&(l+=`?commentcode=${fcn_urlParams.commentcode}`),e>1&&(l+=l.length>1?`&pg=${e}`:`?pg=${e}`),window.history.pushState({path:r},"",r+l+location.hash)}else a=fcn_buildErrorNotice(t.data.error)})).catch((t=>{a=fcn_buildErrorNotice(t)})).then((()=>{fcn_commentSection.classList.remove("ajax-in-progress"),a&&(fcn_commentSection.innerHTML="",fcn_commentSection.appendChild(a))}))}function fcn_reloadCommentsPage(t=null){fcn_getCommentSection(null,t,!0)}function fcn_jumpToCommentPage(){const t=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));t>0&&fcn_reloadCommentsPage(t)}var fct_commentSectionObserver;function fcn_setupCommentSectionObserver(){fct_commentSectionObserver=new IntersectionObserver((([t])=>{t.isIntersecting&&(fcn_getCommentSection(),fct_commentSectionObserver.disconnect())}),{rootMargin:"450px",threshold:1}),fcn_commentSection&&fct_commentSectionObserver.observe(fcn_commentSection)}function fcn_loadCommentEarly(){fcn_commentSection&&location.hash.includes("#comment")&&(_$$$("comment")||(fct_commentSectionObserver.disconnect(),fcn_reloadCommentsPage()))}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentSectionObserver()})):fcn_setupCommentSectionObserver(),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(t=>{if(t.target.closest("[data-page-jump]"))return void fcn_jumpToCommentPage();const e=t.target.closest("[data-page]");e&&fcn_reloadCommentsPage(e.dataset.page)}));const fcn_bookshelfTarget=_$$$("ajax-bookshelf-target");function fcn_getBookshelfContent(){return fcn_parseJSON(localStorage.getItem("fcnBookshelfContent"))??{html:{},count:{}}}function fcn_updateBookshelfView(t=null,e=null,n=null,a=!1){let o=fcn_getBookshelfContent();const c=(t=t??fcn_bookshelfTarget.dataset.action)+(e=e??fcn_bookshelfTarget.dataset.page)+(n=n??fcn_bookshelfTarget.dataset.order);if(!o.hasOwnProperty("timestamp")||o.timestamp+6e4{n.success?(c.timestamp=Date.now(),c.html[o]=n.data.html,c.count[t]=n.data.count,localStorage.setItem("fcnBookshelfContent",JSON.stringify(c)),fcn_bookshelfTarget.innerHTML=n.data.html,fcn_bookshelfTarget.dataset.page=e,_$(".item-number").innerHTML=`(${n.data.count})`):(fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(n.data.error)))})).catch((t=>{_$(".item-number").innerHTML="",fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(`${t.status}: ${t.statusText}`))})).then((()=>{fcn_bookshelfTarget.classList.remove("ajax-in-progress"),a&&_$$$("main").scrollIntoView({behavior:"smooth"})}))}fcn_bookshelfTarget&&(fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_updateBookshelfView()})):fcn_updateBookshelfView()),_$(".bookshelf__list")?.addEventListener("click",(t=>{const e=t.target.closest(".page-numbers[data-page]");e&&fcn_browseBookshelfPage(e.dataset.page)})); \ No newline at end of file + `)}function fcn_moderateComment(t,e){const n=_$$$(`comment-${t}`),a=n.querySelector(".mod-menu-toggle-icon");n.classList.contains("ajax-in-progress")||(n.classList.add("ajax-in-progress"),"trash"!=e&&"spam"!=e||(n.style.height=n.clientHeight+"px"),fcn_ajaxPost({action:"fictioneer_ajax_moderate_comment",operation:e,id:t}).then((t=>{if(t.success)switch(t.data.operation){case"sticky":n.classList.add("_sticky");break;case"unsticky":n.classList.remove("_sticky");break;case"approve":n.classList.remove("_unapproved");break;case"unapprove":n.classList.add("_unapproved");break;case"open":n.classList.remove("_closed");break;case"close":n.classList.add("_closed");break;case"trash":case"spam":n.style.cssText="overflow: hidden; height: 0; margin: 0; opacity: 0;"}else a.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",a.style.color="var(--notice-warning-background)",n.querySelector(".popup-menu-toggle").style.opacity="1",t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{a.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",a.style.color="var(--notice-warning-background)",n.querySelector(".popup-menu-toggle").style.opacity="1",t.status&&t.statusText?fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"):t&&fcn_showNotification(t,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),fcn_lastClicked?.classList.remove("last-clicked"),fcn_lastClicked=null})))}function fcn_addCommentMouseleaveEvents(){_$$(".fictioneer-comment__container").forEach((t=>{t.addEventListener("mouseleave",(t=>{fcn_lastClicked?.classList.remove("last-clicked"),fcn_lastClicked=null,t.stopPropagation()}))}))}function fcn_flagComment(t){if(!fcn_isLoggedIn)return;const e=t.closest(".fictioneer-comment"),n=e.querySelector(".fictioneer-report-comment-button");e.classList.contains("ajax-in-progress")||(e.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_report_comment",id:e.dataset.id,dubious:n.classList.contains("_dubious")}).then((t=>{t.success?(n.classList.toggle("on",t.data.flagged),n.classList.remove("_dubious"),t.data.resync&&fcn_showNotification(t.data.resync)):t.data?.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{e.classList.remove("ajax-in-progress")})))}function fcn_revealCommentFormInputs(t){t.closest("form").querySelectorAll(".fictioneer-respond__form-actions, .fictioneer-respond__form-bottom").forEach((t=>{t.classList.remove("hidden")}))}function fcn_addCommentFormEvents(){_$$$("comment")?.addEventListener("focus",(t=>{fcn_revealCommentFormInputs(t.currentTarget)}),{once:!0})}function fcn_textareaAdjust(t){t.style.height="auto",t.style.height=`${t.scrollHeight}px`}function fcn_wrapInTag(t,e,n={}){const a=n.href?' href="'+n.href+'" target="_blank" rel="nofollow noreferrer noopener"':"",o=n.shortcode?["[","]"]:["<",">"],c=t.selectionStart,s=t.selectionEnd,i=o[0]+e+a+o[1],r=o[0]+"/"+e+o[1],l=i+t.value.substring(c,s)+r;t.value=t.value.substring(0,c)+l+t.value.substring(s,t.value.length),t.setSelectionRange(c+i.length,s+i.length),t.focus()}function fcn_bindAJAXCommentSubmit(){fcn_theRoot.dataset.ajaxSubmit&&_$$$("commentform")?.addEventListener("submit",(t=>{if(t.preventDefault(),Date.now()1,a.classList.toggle("_error",!u),i&&(g=i.checked,i.classList.toggle("_error",!g)),c&&c.value.length>0&&(h=/\S+@\S+\.\S+/.test(c.value),c.classList.toggle("_error",!h)),!u||!g||!h)return!1;e.classList.add("ajax-in-progress"),n.disabled=!0,n.value=n.dataset.disabled;const m={action:"fictioneer_ajax_submit_comment",post_id:_$$$("comment_post_ID").value,content:a.value,private_comment:d?.checked??0,notification:_?.checked??0,cookie_consent:s?.checked??0,privacy_consent:i?.checked??0,unfiltered_html:_$$$("_wp_unfiltered_html_comment_disabled")?.value??"",depth:f?parseInt(f.dataset.depth)+1:1,fictioneer_comment_validator:r?.value??0};l&&(m.parent_id=l),c?.value&&(m.email=c?.value),o?.value&&(m.author=o?.value),fcn_ajaxPost(m).then((t=>{if(_$$$("comment-submit-error-notice")?.remove(),t.success&&t.data?.comment){let e=_$(".commentlist"),n="insertBefore";if(e&&!f&&e.firstElementChild){let t=null;if(e.firstElementChild.classList.contains("_sticky"))for(t=e.firstElementChild,e=t,n="insertAfter";t.nextElementSibling&&t.nextElementSibling.classList.contains("_sticky");)t=e.nextElementSibling,e=t}if(e||(e=document.createElement("ol"),e.classList="fictioneer-comments__list commentlist",_$$$("comments").appendChild(e),n="append"),f&&(e=f.querySelector(".children"),n="append",!e)){const t=document.createElement("ol");f.appendChild(t),e=t}let o=document.createElement("div");switch(o.innerHTML=t.data.comment,o=o.firstChild,n){case"append":e.appendChild(o);break;case"insertBefore":e.insertBefore(o,e.firstChild);break;case"insertAfter":e.nextSibling?e.parentNode.insertBefore(o,e.nextSibling):e.parentNode.appendChild(o)}fcn_addCommentMouseleaveEvents(),"0"!=_$$$("comment_parent").value&&_$$$("cancel-comment-reply-link").click(),a.value="",a.style.height="";const c=window.location.protocol+"//"+window.location.host+window.location.pathname;let s="";t.data.commentcode&&(s+=`?commentcode=${t.data.commentcode}`),history.pushState({path:c},"",c+s+`#comment-${t.data.comment_id}`),o.scrollIntoView({behavior:"smooth"})}else e.insertBefore(fcn_buildErrorNotice(t.data?.error??fictioneer_tl.notification.error,"comment-submit-error-notice",!1),e.firstChild)})).catch((t=>{_$$$("comment-submit-error-notice")?.remove(),e.insertBefore(fcn_buildErrorNotice(`${t.status}: ${t.statusText}`,"comment-submit-error-notice"),e.firstChild)})).then((()=>{e.classList.remove("ajax-in-progress"),n.disabled=!1,n.value=n.dataset.enabled}))}))}document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeFollows(t)})),fcn_followsMenuItem?.addEventListener("mouseover",(()=>{fcn_setupFollowsHTML()}),{once:!0}),fcn_followsMenuItem?.addEventListener("focus",(()=>{fcn_setupFollowsHTML()}),{once:!0}),_$('.mobile-menu__frame-button[data-frame-target="follows"]')?.addEventListener("click",(()=>{fcn_setupFollowsHTML()}),{once:!0}),_$$(".button-follow-story").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleFollow(t.currentTarget.dataset.storyId)}))})),_$$(".mark-follows-read").forEach((t=>{t.addEventListener("click",(()=>{fcn_markFollowsRead()}))})),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeCheckmarks(t)})),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeReminders(t)})),_$$(".button-read-later").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleReminder(t.currentTarget.dataset.storyId)}))})),document.addEventListener("fcnUserDataReady",(()=>{fcn_getUserData().fingerprint==fcn_theRoot.dataset.authorFingerprint&&fcn_theBody.classList.add("is-post-author")})),fcn_addJSTrap(),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),_$(".comment-section")?.addEventListener("click",(t=>{const e=t.target.closest("[data-bbcode]");e&&fcn_wrapInTag(_$$$("comment"),e.dataset.bbcode,{shortcode:!0})})),_$(".comment-section")?.addEventListener("keydown",(t=>{if(_$(".fictioneer-comment-toolbar")&&"TEXTAREA"===document.activeElement.tagName&&(t.ctrlKey||t.metaKey)){const e=t.key.toLowerCase();if(["b","i","s","q","h","l"].includes(e)){t.preventDefault();const n={q:"quote",h:"spoiler",l:"link"};fcn_wrapInTag(document.activeElement,n[e]||e,{shortcode:!0})}}})),fcn_bindAJAXCommentSubmit();const fcn_commentEditActionsTemplate=_$(".comment-edit-actions-template");var fcn_commentEditUndos={};function fcn_triggerInlineCommentEdit(t){const e=t.closest(".fictioneer-comment");if(e){const t=e.querySelector(".fictioneer-comment__content"),n=e.querySelector(".fictioneer-comment__edit"),a=e.querySelector(".comment-inline-edit-content");n.appendChild(fcn_commentEditActionsTemplate.content.cloneNode(!0)),fcn_commentEditUndos[e.id]=a.value,e.classList.add("_editing"),t.hidden=!0,n.hidden=!1,a.style.height=`${a.scrollHeight}px`}}function fcn_submitInlineCommentEdit(t){const e=t.closest(".fictioneer-comment"),n=e.querySelector(".fictioneer-comment__edit"),a=e.querySelector(".comment-inline-edit-content").value;let o=e.querySelector(".fictioneer-comment__edit-note");a!=fcn_commentEditUndos[e.id]?e&&(n.classList.add("ajax-in-progress"),t.innerHTML=t.dataset.disabled,t.disabled=!0,fcn_ajaxPost({action:"fictioneer_ajax_edit_comment",comment_id:e.id.replace("comment-",""),content:a}).then((t=>{if(t.success){const n=e.querySelector(".fictioneer-comment__content");n.innerHTML=t.data.content,fcn_restoreComment(e,!1,t.data.raw),o||(o=document.createElement("div")),o.classList.add("fictioneer-comment__edit-note"),o.innerHTML=t.data.edited,n.parentNode.appendChild(o)}else fcn_restoreComment(e,!0),t.data?.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{fcn_restoreComment(e,!0),t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),t.innerHTML=t.dataset.enabled,t.disabled=!1}))):fcn_restoreComment(e,!0)}function fcn_cancelInlineCommentEdit(t){const e=t.closest(".fictioneer-comment");e&&fcn_restoreComment(e,!0)}function fcn_restoreComment(t,e=!1,n=null){t.querySelector(".fictioneer-comment__content").hidden=!1,t.querySelector(".fictioneer-comment__edit").hidden=!0,t.querySelector(".fictioneer-comment__edit-actions")?.remove(),t.classList.remove("_editing"),e&&fcn_commentEditUndos[t.id]?t.querySelector(".comment-inline-edit-content").value=fcn_commentEditUndos[t.id]:n&&(t.querySelector(".comment-inline-edit-content").value=n)}function fcn_revealEditButton(){let t=parseInt(fcn_theRoot.dataset.editTime);t&&(t=t>0?6e4*t:t,_$$(".fictioneer-comment[data-fingerprint]").forEach((e=>{if(fcn_matchFingerprint(e.dataset.fingerprint)){if(t>0&&parseInt(e.dataset.timestamp)+t{if(fcn_matchFingerprint(t.dataset.fingerprint)){const e=t.querySelector(".fictioneer-comment__delete");e&&(e.hidden=!1)}}))}function fcn_deleteMyComment(t){if(!fcn_isLoggedIn)return;const e=prompt(t.dataset.dialogMessage);if(!e||e.toLowerCase()!=t.dataset.dialogConfirm.toLowerCase())return;const n=t.closest(".fictioneer-comment");n.classList.contains("ajax-in-progress")||(n.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_delete_my_comment",comment_id:n.dataset.id}).then((t=>{t.success?(n.classList.add("_deleted"),n.querySelector(".fictioneer-comment__container").innerHTML=t.data.html):t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")})))}document.addEventListener("fcnUserDataReady",(()=>{fcn_revealEditButton()})),document.addEventListener("fcnUserDataReady",(()=>{fcn_revealDeleteButton()}));const fcn_ajaxCommentForm=_$$$("ajax-comment-form-target");function fcn_setupCommentFormObserver(){const t=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentForm(),t.disconnect())}),{rootMargin:"450px",threshold:1});t.observe(fcn_ajaxCommentForm)}function fcn_getCommentForm(){let t;fcn_ajaxGet({action:"fictioneer_ajax_get_comment_form",post_id:_$$$("comments").dataset.postId}).then((e=>{if(e.success){const t=document.createElement("div");t.innerHTML=e.data.html;const n=t.querySelector("#comment_post_ID"),a=t.querySelector("#cancel-comment-reply-link"),o=t.querySelector(".logout-link");n&&(n.value=e.data.postId),a&&(a.href="#respond"),o&&(o.href=_$$$("comments").dataset.logoutUrl),fcn_ajaxCommentForm.innerHTML=t.innerHTML,t.remove(),fcn_applyCommentStack(),fcn_addCommentFormEvents(),fcn_theRoot.dataset.ajaxSubmit&&fcn_bindAJAXCommentSubmit(),fcn_addNonceHTML(e.data.nonceHtml),fcn_addJSTrap()}else t=fcn_buildErrorNotice(e.data.error)})).catch((e=>{t=fcn_buildErrorNotice(e)})).then((()=>{fcn_ajaxCommentForm.classList.remove("comments-skeleton"),t&&(fcn_ajaxCommentForm.innerHTML="",fcn_ajaxCommentForm.appendChild(t))}))}fcn_ajaxCommentForm&&(fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentFormObserver()})):fcn_setupCommentFormObserver());var fcn_commentStack=[];function fcn_applyCommentStack(t=null){(t=t??_$$$("comment"))&&(fcn_commentStack.forEach((e=>{t.value+=e})),fcn_commentStack=[],fcn_textareaAdjust(t))}_$(".fictioneer-comments")?.addEventListener("click",(t=>{const e=t.target.closest("[data-click]");if(e)switch(e?.dataset.click){case"submit-inline-comment-edit":fcn_submitInlineCommentEdit(e);break;case"cancel-inline-comment-edit":fcn_cancelInlineCommentEdit(e);break;case"trigger-inline-comment-edit":fcn_triggerInlineCommentEdit(e);break;case"delete-my-comment":fcn_deleteMyComment(e);break;case"flag-comment":fcn_flagComment(e);break;case"ajax-mod-action":fcn_moderateComment(e.dataset.id,e.dataset.action)}})),_$(".fictioneer-comments")?.addEventListener("input",(t=>{t.target.matches(".adaptive-textarea")&&fcn_textareaAdjust(t.target),t.target.closest("#fictioneer-private-comment-toggle")&&_$$$("respond")?.classList.toggle("_private",t.currentTarget.checked)}));const fcn_commentSection=_$("#comments[data-ajax-comments]");function fcn_getCommentSection(t=null,e=null,n=null,a=!1){if(!fcn_commentSection)return;let o,c="",s=_$$$("comment");if(s&&(c=s.value),fcn_commentSection.classList.contains("ajax-in-progress"))return;if(fcn_commentSection.classList.add("ajax-in-progress"),e||(e=fcn_urlParams.pg??1),!fcn_commentSection)return;const i={action:"fictioneer_ajax_get_comment_section",post_id:t??fcn_commentSection.dataset.postId,page:parseInt(e),order:n??fcn_commentSection.dataset.order??0};fcn_urlParams.commentcode&&(i.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(i).then((t=>{if(t.success){e=t.data.page;const n=document.createElement("div");if(n.innerHTML=t.data.html,n.querySelector("#comment_post_ID")){n.querySelector("#comment_post_ID").value=t.data.postId,n.querySelector("#cancel-comment-reply-link").href="#respond";const e=n.querySelector(".logout-link");e&&(e.href=fcn_commentSection.dataset.logoutUrl)}fcn_commentSection.innerHTML=n.innerHTML,n.remove(),t.data.disabled||(s=_$$$("comment"),s.value=c,fcn_applyCommentStack(s)),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const o=location.hash.includes("#comment")?location.hash:".respond",i=document.querySelector(o)??_$$$("respond");a&&i.scrollIntoView({behavior:"smooth"});const r=window.location.protocol+"//"+window.location.host+window.location.pathname;let l="";fcn_urlParams.commentcode&&(l+=`?commentcode=${fcn_urlParams.commentcode}`),e>1&&(l+=l.length>1?`&pg=${e}`:`?pg=${e}`),window.history.pushState({path:r},"",r+l+location.hash)}else o=fcn_buildErrorNotice(t.data.error)})).catch((t=>{o=fcn_buildErrorNotice(t)})).then((()=>{fcn_commentSection.classList.remove("ajax-in-progress"),o&&(fcn_commentSection.innerHTML="",fcn_commentSection.appendChild(o))}))}function fcn_reloadCommentsPage(t=null){fcn_getCommentSection(null,t,null,!0)}function fcn_jumpToCommentPage(){const t=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));t>0&&fcn_reloadCommentsPage(t)}var fct_commentSectionObserver;function fcn_setupCommentSectionObserver(){fct_commentSectionObserver=new IntersectionObserver((([t])=>{t.isIntersecting&&(fcn_getCommentSection(),fct_commentSectionObserver.disconnect())}),{rootMargin:"450px",threshold:1}),fcn_commentSection&&fct_commentSectionObserver.observe(fcn_commentSection)}function fcn_loadCommentEarly(){fcn_commentSection&&location.hash.includes("#comment")&&(_$$$("comment")||(fct_commentSectionObserver.disconnect(),fcn_reloadCommentsPage()))}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentSectionObserver()})):fcn_setupCommentSectionObserver(),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(t=>{if(t.target.closest("[data-page-jump]"))return void fcn_jumpToCommentPage();const e=t.target.closest("[data-page]");e&&fcn_reloadCommentsPage(e.dataset.page)}));const fcn_bookshelfTarget=_$$$("ajax-bookshelf-target");function fcn_getBookshelfContent(){return fcn_parseJSON(localStorage.getItem("fcnBookshelfContent"))??{html:{},count:{}}}function fcn_updateBookshelfView(t=null,e=null,n=null,a=!1){let o=fcn_getBookshelfContent();const c=(t=t??fcn_bookshelfTarget.dataset.action)+(e=e??fcn_bookshelfTarget.dataset.page)+(n=n??fcn_bookshelfTarget.dataset.order);if(!o.hasOwnProperty("timestamp")||o.timestamp+6e4{n.success?(c.timestamp=Date.now(),c.html[o]=n.data.html,c.count[t]=n.data.count,localStorage.setItem("fcnBookshelfContent",JSON.stringify(c)),fcn_bookshelfTarget.innerHTML=n.data.html,fcn_bookshelfTarget.dataset.page=e,_$(".item-number").innerHTML=`(${n.data.count})`):(fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(n.data.error)))})).catch((t=>{_$(".item-number").innerHTML="",fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(`${t.status}: ${t.statusText}`))})).then((()=>{fcn_bookshelfTarget.classList.remove("ajax-in-progress"),a&&_$$$("main").scrollIntoView({behavior:"smooth"})}))}fcn_bookshelfTarget&&(fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_updateBookshelfView()})):fcn_updateBookshelfView()),_$(".bookshelf__list")?.addEventListener("click",(t=>{const e=t.target.closest(".page-numbers[data-page]");e&&fcn_browseBookshelfPage(e.dataset.page)})); \ No newline at end of file diff --git a/src/js/ajax-comments.js b/src/js/ajax-comments.js index 39e4efd0..6a777221 100644 --- a/src/js/ajax-comments.js +++ b/src/js/ajax-comments.js @@ -20,9 +20,11 @@ const /** @const {HTMLElement} */ fcn_commentSection = _$('#comments[data-ajax-c * @since 5.0.0 * @param {Number=} post_id - The current post ID. * @param {Number=} page - The requested page number. + * @param {String=} order - Order of the comments. + * @param {Boolean=} scroll - Whether to scroll comments into view. Default false. */ -function fcn_getCommentSection(post_id = null, page = null, scroll = false) { +function fcn_getCommentSection(post_id = null, page = null, order = null, scroll = false) { //Abort conditions... if (!fcn_commentSection) { return; @@ -60,7 +62,8 @@ function fcn_getCommentSection(post_id = null, page = null, scroll = false) { const payload = { 'action': 'fictioneer_ajax_get_comment_section', 'post_id': post_id ?? fcn_commentSection.dataset.postId, - 'page': parseInt(page) + 'page': parseInt(page), + 'order': order ?? fcn_commentSection.dataset.order ?? 0 }; if (fcn_urlParams.commentcode) { @@ -169,7 +172,7 @@ function fcn_getCommentSection(post_id = null, page = null, scroll = false) { */ function fcn_reloadCommentsPage(page = null) { - fcn_getCommentSection(null, page, true); + fcn_getCommentSection(null, page, null, true); } function fcn_jumpToCommentPage() {