From 81b479de43b32242fa79224fbe15d968399d05f5 Mon Sep 17 00:00:00 2001
From: Tetrakern <26898880+Tetrakern@users.noreply.github.com>
Date: Thu, 1 Feb 2024 09:46:40 +0100
Subject: [PATCH] Cleanup and refactor some JS
Folded some class assignments into loops, refactored observers, dealt with some formatting.
---
js/admin.min.js | 2 +-
js/application.min.js | 2 +-
js/story.min.js | 2 +-
src/js/admin.js | 18 +++++----
src/js/application.js | 89 +++++++++++++++++++++----------------------
src/js/story.js | 4 +-
src/js/tts.js | 12 +++++-
7 files changed, 68 insertions(+), 61 deletions(-)
diff --git a/js/admin.min.js b/js/admin.min.js
index b944ec3b..44144bdc 100644
--- a/js/admin.min.js
+++ b/js/admin.min.js
@@ -1 +1 @@
-function fcn_toggleInProgress(e,t=null){(t=null!==t?t:!e.disabled)?(e.dataset.enableWith=e.innerHTML,e.innerHTML=e.dataset.disableWith,e.disabled=!0,e.classList.add("disabled")):(e.innerHTML=e.dataset.enableWith,e.disabled=!1,e.classList.remove("disabled"))}function fcn_purgeSchema(e){const t=_$(`a[data-id="${e}"]`),a=t.closest(".row-actions");t.closest("tr").classList.add("no-schema"),a.remove(),fcn_ajaxPost({action:"fictioneer_ajax_purge_schema",nonce:document.getElementById("fictioneer_admin_nonce").value,post_id:e}).then((e=>{e.success||console.log(e.data)})).catch((e=>{console.log(e)}))}function fcn_purgeAllSchemas(e=0,t=null,a=0){const o=_$$("[data-action-purge-all-schemas]");null===t&&o.forEach((e=>{fcn_toggleInProgress(e,!0)})),fcn_ajaxPost({action:"fictioneer_ajax_purge_all_schemas",offset:e,nonce:document.getElementById("fictioneer_admin_nonce").value}).then((e=>{if(e.data.finished)o.forEach((e=>{fcn_toggleInProgress(e,!1)})),_$$("tr").forEach((e=>{e.classList.add("no-schema")}));else{const t=parseInt(a/Math.max(e.data.total,1)*100),n=t>0?` ${t} %`:"";o.forEach((e=>{e.innerHTML=e.dataset.disableWith+n})),fcn_purgeAllSchemas(e.data.next_offset,e.data.total,a+e.data.processed)}})).catch((e=>{console.log(e)}))}function fcn_delete_epub(e){fcn_ajaxPost({action:"fictioneer_ajax_delete_epub",name:e,nonce:document.getElementById("fictioneer_admin_nonce").value}).then((t=>{t.success?document.querySelector(`[data-action="delete-epub"][data-name="${e}"]`).closest("tr").remove():console.log(t)})).catch((e=>{console.log(e)}))}function fcn_ogMediaUpload(e){e.preventDefault();var t=wp.media({multiple:!1,library:{type:"image"}}).open().on("select",(function(){const e=t.state().get("selection").first().toJSON();_$$$("fictioneer-seo-og-image").value=e.id,_$$$("fictioneer-seo-og-display").setAttribute("src",e.url),_$$$("fictioneer-button-seo-og-image-remove").classList.remove("hidden"),_$(".og-source").classList.add("hidden")}))}function fcn_update_seo_title_chars(){const e=_$$$("fictioneer-seo-title");_$$$("fictioneer-seo-title-chars").innerHTML=`(${e.value.length}/70)`}function fcn_remove_seo_og_image(e){e.preventDefault();const t=_$$$("fictioneer-seo-og-display").dataset.placeholder;_$$$("fictioneer-seo-og-image").value="",_$$$("fictioneer-seo-og-display").setAttribute("src",t),_$$$("fictioneer-button-seo-og-image-remove").classList.add("hidden")}function fcn_confirmIt(e){const t=e.currentTarget.dataset.dialogMessage,a=e.currentTarget.dataset.dialogConfirm;if(!t||!a)return;const o=prompt(t);o?o.toLowerCase()!=a.toLowerCase()&&e.preventDefault():e.preventDefault()}function fcn_imageMediaUpload(e){e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-image"]');var a=wp.media({multiple:!1,library:{type:"image"}}).open().on("select",(()=>{const e=a.state().get("selection").first().toJSON();t.querySelector('[data-target="fcn-meta-field-image-id"]').value=e.id,t.querySelector(".fictioneer-meta-field__image-display").style.backgroundImage=`url("${e.url}")`,t.querySelector(".fictioneer-meta-field__image-upload").classList.add("hidden"),t.querySelector(".fictioneer-meta-field__image-actions").classList.remove("hidden")}))}function fcn_ebookMediaUpload(e){e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-ebook"]');var a=wp.media({multiple:!1,library:{type:["application/pdf","text/plain","application/rtf","application/x-mobipocket-ebook","application/epub+zip"]}}).open().on("select",(()=>{const e=a.state().get("selection").first().toJSON();t.querySelector('[data-target*="id"]').value=e.id,t.querySelector('[data-target*="name"]').textContent=e.title,t.querySelector('[data-target*="size"]').textContent=e.filesizeHumanReadable,t.querySelector('[data-target*="filename"]').textContent=e.filename,t.querySelector('[data-target*="filename"]').href=e.url,t.querySelector('[data-target*="upload"]').classList.add("hidden"),t.querySelector('[data-target*="replace"]').classList.remove("hidden"),t.querySelector('[data-target*="remove"]').classList.remove("hidden"),t.querySelector('[data-target*="display"]').classList.remove("hidden")}))}function fcn_ebookMediaRemove(e){e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-ebook"]');t.querySelector('[data-target*="id"]').value=0,t.querySelector('[data-target*="name"]').textContent="",t.querySelector('[data-target*="size"]').textContent="",t.querySelector('[data-target*="filename"]').textContent="",t.querySelector('[data-target*="filename"]').href="",t.querySelector('[data-target*="upload"]').classList.remove("hidden"),t.querySelector('[data-target*="replace"]').classList.add("hidden"),t.querySelector('[data-target*="remove"]').classList.add("hidden"),t.querySelector('[data-target*="display"]').classList.add("hidden")}function fcn_tokensToggle(e,t){if(e<1)return void(t.querySelector("select").value=0);const a=JSON.parse(t.querySelector('[data-target="fcn-meta-field-tokens-options"]').value),o=t.querySelector('[data-target="fcn-meta-field-tokens-track"]'),n=t.querySelector('[data-target="fcn-meta-field-tokens-values"]'),r=fcn_splitList(n.value).filter((e=>!isNaN(e))).map((e=>Math.abs(parseInt(e)))),i=r.indexOf(e);-1===i?r.push(e):r.splice(i,1),n.value=r.join(", "),o.innerHTML="",r.forEach((e=>{const t=fcn_sanitizeHTML(a[e]?a[e]:e);o.innerHTML+=`${t}`})),t.querySelector("select").value=0}function fcn_insertIconClass(e){const t=e.closest(".fictioneer-meta-field");t&&e&&(t.querySelector(".fictioneer-meta-field__input").value=e.dataset.value,t.querySelector(".fictioneer-meta-field__fa-icon").setAttribute("class",`fictioneer-meta-field__fa-icon ${e.dataset.value}`))}function fcn_checkRequiredFields(){let e=null;_$$(".fictioneer-meta-field [required]").forEach((t=>{!0!==e&&(e=""===t?.value.trim())})),e?wp.data?.dispatch("core/editor").lockPostSaving("requiredValueLock"):wp.data?.dispatch("core/editor").unlockPostSaving("requiredValueLock")}function fcn_setGroupDataList(e){const t=e.value,a=e.dataset.target;_$$$(a)?.remove(),0!=t&&fcn_ajaxGet({action:"fictioneer_ajax_get_chapter_groups",story_id:t,nonce:fictioneer_ajax.fictioneer_nonce}).then((e=>{if(e.success){const t=fcn_html`>`;document.body.appendChild(t)}else e.data.error&&console.log(e.data.error)}))}var relationshipSearchTimer;function fcn_observeRelationshipSource(e){const t=e.closest(".fictioneer-meta-field"),a=new IntersectionObserver(((e,a)=>{e.forEach((e=>{if(e.isIntersecting){let o=t.querySelector('[data-target="fcn-relationships-search"]')?.value??"";o.length>200&&(o=o.slice(0,200)),fcn_queryRelationshipPosts({action:e.target.dataset.ajaxAction,page:e.target.dataset.page,nonce:e.target.dataset.nonce,key:e.target.dataset.key,post_id:e.target.dataset.postId,search:o,post_type:t.querySelector('[data-target="fcn-relationships-post-type"]')?.value??"",fcn_fast_ajax:1},e.target.closest('[data-target="fcn-relationships-source"')),a.unobserve(e.target)}}))}),{root:e,rootMargin:"0px",threshold:.5});e.querySelectorAll('[data-target="fcn-relationships-observer"]').forEach((e=>{a.observe(e)}))}function fcn_queryRelationshipPosts(e,t,a=!0){const o=t.closest(".fictioneer-meta-field"),n=o.querySelector('[data-target="fcn-relationships-source"]'),r=o.querySelector('[data-target="fcn-relationships-values"]');let i=null;fcn_ajaxPost(e).then((e=>(t.querySelector('[data-target="fcn-relationships-observer"]')?.remove(),e))).then((e=>{e.success?(a?t.innerHTML+=e.data.html:t.innerHTML=e.data.html,t.querySelectorAll("li").forEach((e=>{r.querySelector(`[data-id="${e.dataset.id}"]`)&&e.classList.add("disabled")})),fcn_observeRelationshipSource(t)):i=e.data.error})).catch((e=>{i=e})).then((()=>{if(i){const e=o.querySelector('[data-target="loading-error-template"]').content.cloneNode(!0);e.querySelector(".error-message").textContent=i,n.appendChild(e)}}))}function fcn_removeRelationship(e){const t=e.closest(".fictioneer-meta-field");if(!t)return;const a=t.querySelector('[data-target="fcn-relationships-source"]').querySelector(`[data-id="${e.dataset.id}"]`);a&&a.classList.remove("disabled"),e.remove()}function fcn_addRelationship(e,t){if(!e||!t||e.classList.contains("disabled"))return;const a=e.closest(".fictioneer-meta-field").querySelector('[data-target="selected-item-template"]').content.cloneNode(!0);a.querySelector("li").setAttribute("data-id",e.dataset.id),a.querySelector('input[type="hidden"]').value=e.dataset.id,a.querySelector("span").innerHTML=e.querySelector("span").innerHTML,e.dataset.info&&a.querySelector("li").setAttribute("data-info",e.dataset.info),t.appendChild(a),e.classList.add("disabled")}_$$("[data-purge-schema]").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_purgeSchema(e.currentTarget.dataset.id)}))})),_$$("[data-action-purge-all-schemas]").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_purgeAllSchemas()}))})),_$$('[data-dialog-target="schema-dialog"]').forEach((e=>{e.addEventListener("click",(e=>{const t=_$('[data-target="schema-content"]');t.value=e.currentTarget.closest("tr").querySelector("[data-schema-id]").textContent,t.scrollTop=0,setTimeout((()=>{t.scrollTop=0}),10)}))})),_$$('[data-action="delete-epub"]').forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_delete_epub(e.target.dataset.name)}))})),(button=_$$$("fictioneer-button-og-upload"))&&button.addEventListener("click",fcn_ogMediaUpload),(button=_$$$("fictioneer-seo-title"))&&(fcn_update_seo_title_chars(),button.addEventListener("keyup",fcn_update_seo_title_chars)),(button=_$$$("fictioneer-button-seo-og-image-remove"))&&button.addEventListener("click",fcn_remove_seo_og_image),_$$("[data-confirm-dialog]").forEach((e=>{e.addEventListener("click",(e=>{fcn_confirmIt(e)}))})),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{localStorage.removeItem("fcnProfileAvatar"),localStorage.removeItem("fcnUserData"),localStorage.removeItem("fcnAuth"),localStorage.removeItem("fcnBookshelfContent"),localStorage.removeItem("fcnChapterBookmarks")})),_$(".fictioneer-settings")?.addEventListener("click",(e=>{const t=e.target.closest("[data-click]"),a=t?.dataset.click;if(a&&"warning-dialog"===a)confirm(t.dataset.dialog)||e.preventDefault()})),_$$("[data-dialog-target]").forEach((e=>{e.addEventListener("click",(e=>{_$$$(e.currentTarget.dataset.dialogTarget)?.showModal()}))})),_$$('button[formmethod="dialog"][value="cancel"]').forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),e.currentTarget.closest("dialog").close()}))})),_$$("dialog").forEach((e=>{e.addEventListener("mousedown",(e=>{"dialog"===e.target.tagName.toLowerCase()&&e.target.close()}))})),_$$(".fictioneer-meta-field__image-upload, .fictioneer-meta-field__image-replace").forEach((e=>{e.addEventListener("click",fcn_imageMediaUpload)})),_$$(".fictioneer-meta-field__image-remove").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-image"]');t.querySelector('[data-target="fcn-meta-field-image-id"]').value="",t.querySelector(".fictioneer-meta-field__image-display").style.backgroundImage="",t.querySelector(".fictioneer-meta-field__image-upload").classList.remove("hidden"),t.querySelector(".fictioneer-meta-field__image-actions").classList.add("hidden")}))})),_$$('[data-target="fcn-meta-field-ebook-upload"], [data-target="fcn-meta-field-ebook-replace"]').forEach((e=>{e.addEventListener("click",fcn_ebookMediaUpload)})),_$$('[data-target="fcn-meta-field-ebook-remove"]').forEach((e=>{e.addEventListener("click",fcn_ebookMediaRemove)})),_$$('[data-target="fcn-meta-field-tokens-add"]').forEach((e=>{e.addEventListener("change",(e=>{e.preventDefault();fcn_tokensToggle(parseInt(e.currentTarget.value),e.currentTarget.closest('[data-target="fcn-meta-field-tokens"]'))}))})),_$$('[data-target="fcn-meta-field-tokens-track"]').forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault();const t=e.target.closest(".fictioneer-meta-field__token"),a=e.target.closest(".fictioneer-meta-field__token-button"),o=e.target.closest(".fictioneer-meta-field");t&&a?fcn_tokensToggle(parseInt(t.dataset.id),t.closest('[data-target="fcn-meta-field-tokens"]')):o&&o.querySelector("select").focus()}))})),_$$(".fictioneer-meta-field__icon-button[data-value]").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_insertIconClass(e.currentTarget)}))})),_$$(".fictioneer-meta-field__fa-icon").forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.closest(".fictioneer-meta-field").querySelector(".fictioneer-meta-field__button-grid");t.classList.toggle("hidden",!t.classList.contains("hidden"))}))})),document.addEventListener("DOMContentLoaded",(()=>{wp.data?.dispatch("core/editor").lockPostSaving("requiredValueLock"),fcn_checkRequiredFields(),_$$(".fictioneer-meta-field [required]").forEach((e=>{const t=e.closest(".fictioneer-meta-field");t.classList.add("pending-validation"),e.addEventListener("input",(()=>{fcn_checkRequiredFields()})),e.addEventListener("input",(()=>{t.classList.remove("pending-validation")}),{once:!0})})),wp.data?.subscribe((()=>{_$$(".fictioneer-meta-field [required]").forEach((e=>{e.closest(".fictioneer-meta-field").classList.toggle("fictioneer-meta-field--invalid",""===e?.value.trim())}))}))})),document.addEventListener("DOMContentLoaded",(()=>{_$$('[data-action="select-story"]').forEach((e=>{fcn_setGroupDataList(e),e.addEventListener("change",(e=>{fcn_setGroupDataList(e.currentTarget)}))}))})),_$$(".fictioneer-meta-field--relationships").forEach((e=>{const t=e.querySelector('[data-target="fcn-relationships-info"]');fcn_observeRelationshipSource(e),e.addEventListener("click",(t=>{t.target.closest('[data-action="remove"]')&&fcn_removeRelationship(t.target.closest("[data-id]")),t.target.closest('[data-action="add"]')&&fcn_addRelationship(t.target.closest("[data-id]"),e.querySelector('[data-target="fcn-relationships-values"]'))})),e.addEventListener("mouseover",(e=>{t&&(info=e.target.closest("[data-info]"))&&(t.innerHTML=info.dataset.info)}))})),_$$('[data-target="fcn-relationships-values"]').forEach((e=>{Sortable.create(e,{selectedClass:"is-dragged",ghostClass:"is-dragged-ghost",fallbackTolerance:3,animation:150,onStart:e=>{e.target.closest("ol, ul").classList.add("is-sorting")},onEnd:e=>{setTimeout((()=>{e.target.closest("ol, ul").classList.remove("is-sorting")}),5)}})})),_$$('[data-target="fcn-relationships-search"]').forEach((e=>{e.addEventListener("input",(()=>{clearTimeout(relationshipSearchTimer),relationshipSearchTimer=setTimeout((()=>{const t=e.closest(".fictioneer-meta-field"),a=t.querySelector('[data-target="fcn-relationships-source"]');a.innerHTML="",a.appendChild(_$('[data-target="spinner-template"]').content.cloneNode(!0)),e.value>200&&(e.value=e.value.slice(0,200)),fcn_queryRelationshipPosts({action:t.dataset.ajaxAction,nonce:t.dataset.nonce,key:t.dataset.key,post_id:t.dataset.postId,search:e.value,post_type:t.querySelector('[data-target="fcn-relationships-post-type"]')?.value??"",fcn_fast_ajax:1},a),(infoBox=t.querySelector('[data-target="fcn-relationships-info"]'))&&(infoBox.innerHTML=infoBox.dataset.default)}),800)}))})),_$$('[data-target="fcn-relationships-post-type"]').forEach((e=>{e.addEventListener("change",(e=>{const t=e.currentTarget.closest(".fictioneer-meta-field--relationships"),a=t.querySelector('[data-target="fcn-relationships-source"]');let o=t.querySelector('[data-target="fcn-relationships-search"]')?.value??"";a.innerHTML="",a.appendChild(_$('[data-target="spinner-template"]').content.cloneNode(!0)),o>200&&(o=o.slice(0,200)),fcn_queryRelationshipPosts({action:t.dataset.ajaxAction,nonce:t.dataset.nonce,key:t.dataset.key,post_id:t.dataset.postId,search:o,post_type:e.currentTarget.value,fcn_fast_ajax:1},a),(infoBox=t.querySelector('[data-target="fcn-relationships-info"]'))&&(infoBox.innerHTML=infoBox.dataset.default)}))})),_$$('[data-action="fcn-relationships-scroll"]').forEach((e=>{const t=e.closest(".fictioneer-meta-field").querySelector('[data-target="fcn-relationships-values"');e.addEventListener("click",(e=>{const a=parseInt(e.currentTarget.dataset.direction);t.scrollBy({top:a*t.offsetHeight*.75,behavior:"smooth"})}))}));
\ No newline at end of file
+function fcn_toggleInProgress(e,t=null){(t=null!==t?t:!e.disabled)?(e.dataset.enableWith=e.innerHTML,e.innerHTML=e.dataset.disableWith,e.disabled=!0,e.classList.add("disabled")):(e.innerHTML=e.dataset.enableWith,e.disabled=!1,e.classList.remove("disabled"))}function fcn_purgeSchema(e){const t=_$(`a[data-id="${e}"]`),a=t.closest(".row-actions");t.closest("tr").classList.add("no-schema"),a.remove(),fcn_ajaxPost({action:"fictioneer_ajax_purge_schema",nonce:document.getElementById("fictioneer_admin_nonce").value,post_id:e}).then((e=>{e.success||console.log(e.data)})).catch((e=>{console.log(e)}))}function fcn_purgeAllSchemas(e=0,t=null,a=0){const o=_$$("[data-action-purge-all-schemas]");null===t&&o.forEach((e=>{fcn_toggleInProgress(e,!0)})),fcn_ajaxPost({action:"fictioneer_ajax_purge_all_schemas",offset:e,nonce:document.getElementById("fictioneer_admin_nonce").value}).then((e=>{if(e.data.finished)o.forEach((e=>{fcn_toggleInProgress(e,!1)})),_$$("tr").forEach((e=>{e.classList.add("no-schema")}));else{const t=parseInt(a/Math.max(e.data.total,1)*100),n=t>0?` ${t} %`:"";o.forEach((e=>{e.innerHTML=e.dataset.disableWith+n})),fcn_purgeAllSchemas(e.data.next_offset,e.data.total,a+e.data.processed)}})).catch((e=>{console.log(e)}))}function fcn_delete_epub(e){fcn_ajaxPost({action:"fictioneer_ajax_delete_epub",name:e,nonce:document.getElementById("fictioneer_admin_nonce").value}).then((t=>{t.success?document.querySelector(`[data-action="delete-epub"][data-name="${e}"]`).closest("tr").remove():console.log(t)})).catch((e=>{console.log(e)}))}function fcn_ogMediaUpload(e){e.preventDefault();var t=wp.media({multiple:!1,library:{type:"image"}}).open().on("select",(function(){const e=t.state().get("selection").first().toJSON();_$$$("fictioneer-seo-og-image").value=e.id,_$$$("fictioneer-seo-og-display").setAttribute("src",e.url),_$$$("fictioneer-button-seo-og-image-remove").classList.remove("hidden"),_$(".og-source").classList.add("hidden")}))}function fcn_update_seo_title_chars(){const e=_$$$("fictioneer-seo-title");_$$$("fictioneer-seo-title-chars").innerHTML=`(${e.value.length}/70)`}function fcn_remove_seo_og_image(e){e.preventDefault();const t=_$$$("fictioneer-seo-og-display").dataset.placeholder;_$$$("fictioneer-seo-og-image").value="",_$$$("fictioneer-seo-og-display").setAttribute("src",t),_$$$("fictioneer-button-seo-og-image-remove").classList.add("hidden")}function fcn_confirmIt(e){const t=e.currentTarget.dataset.dialogMessage,a=e.currentTarget.dataset.dialogConfirm;if(!t||!a)return;const o=prompt(t);o?o.toLowerCase()!=a.toLowerCase()&&e.preventDefault():e.preventDefault()}function fcn_imageMediaUpload(e){e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-image"]');var a=wp.media({multiple:!1,library:{type:"image"}}).open().on("select",(()=>{const e=a.state().get("selection").first().toJSON();t.querySelector('[data-target="fcn-meta-field-image-id"]').value=e.id,t.querySelector(".fictioneer-meta-field__image-display").style.backgroundImage=`url("${e.url}")`,t.querySelector(".fictioneer-meta-field__image-upload").classList.add("hidden"),t.querySelector(".fictioneer-meta-field__image-actions").classList.remove("hidden")}))}function fcn_ebookMediaUpload(e){e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-ebook"]');var a=wp.media({multiple:!1,library:{type:["application/pdf","text/plain","application/rtf","application/x-mobipocket-ebook","application/epub+zip"]}}).open().on("select",(()=>{const e=a.state().get("selection").first().toJSON();t.querySelector('[data-target*="id"]').value=e.id,t.querySelector('[data-target*="name"]').textContent=e.title,t.querySelector('[data-target*="size"]').textContent=e.filesizeHumanReadable,t.querySelector('[data-target*="filename"]').textContent=e.filename,t.querySelector('[data-target*="filename"]').href=e.url,t.querySelector('[data-target*="upload"]').classList.add("hidden"),t.querySelectorAll('[data-target*="replace"], [data-target*="remove"], [data-target*="display"]').forEach((e=>e.classList.remove("hidden")))}))}function fcn_ebookMediaRemove(e){e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-ebook"]');t.querySelector('[data-target*="id"]').value=0,t.querySelector('[data-target*="name"]').textContent="",t.querySelector('[data-target*="size"]').textContent="",t.querySelector('[data-target*="filename"]').textContent="",t.querySelector('[data-target*="filename"]').href="",t.querySelector('[data-target*="upload"]').classList.remove("hidden"),t.querySelectorAll('[data-target*="replace"], [data-target*="remove"], [data-target*="display"]').forEach((e=>e.classList.add("hidden")))}function fcn_tokensToggle(e,t){if(e<1)return void(t.querySelector("select").value=0);const a=JSON.parse(t.querySelector('[data-target="fcn-meta-field-tokens-options"]').value),o=t.querySelector('[data-target="fcn-meta-field-tokens-track"]'),n=t.querySelector('[data-target="fcn-meta-field-tokens-values"]'),r=fcn_splitList(n.value).filter((e=>!isNaN(e))).map((e=>Math.abs(parseInt(e)))),i=r.indexOf(e);-1===i?r.push(e):r.splice(i,1),n.value=r.join(", "),o.innerHTML="",r.forEach((e=>{const t=fcn_sanitizeHTML(a[e]?a[e]:e);o.innerHTML+=`${t}`})),t.querySelector("select").value=0}function fcn_insertIconClass(e){const t=e.closest(".fictioneer-meta-field");t&&e&&(t.querySelector(".fictioneer-meta-field__input").value=e.dataset.value,t.querySelector(".fictioneer-meta-field__fa-icon").setAttribute("class",`fictioneer-meta-field__fa-icon ${e.dataset.value}`))}function fcn_checkRequiredFields(){let e=null;_$$(".fictioneer-meta-field [required]").forEach((t=>{!0!==e&&(e=""===t?.value.trim())})),e?wp.data?.dispatch("core/editor").lockPostSaving("requiredValueLock"):wp.data?.dispatch("core/editor").unlockPostSaving("requiredValueLock")}function fcn_setGroupDataList(e){const t=e.value,a=e.dataset.target;_$$$(a)?.remove(),0!=t&&fcn_ajaxGet({action:"fictioneer_ajax_get_chapter_groups",story_id:t,nonce:fictioneer_ajax.fictioneer_nonce}).then((e=>{if(e.success){const t=fcn_html`>`;document.body.appendChild(t)}else e.data.error&&console.log(e.data.error)}))}var relationshipSearchTimer;function fcn_observeRelationshipSource(e){const t=e.closest(".fictioneer-meta-field"),a=new IntersectionObserver(((e,a)=>{e.forEach((e=>{if(e.isIntersecting){let o=t.querySelector('[data-target="fcn-relationships-search"]')?.value??"";o.length>200&&(o=o.slice(0,200)),fcn_queryRelationshipPosts({action:e.target.dataset.ajaxAction,page:e.target.dataset.page,nonce:e.target.dataset.nonce,key:e.target.dataset.key,post_id:e.target.dataset.postId,search:o,post_type:t.querySelector('[data-target="fcn-relationships-post-type"]')?.value??"",fcn_fast_ajax:1},e.target.closest('[data-target="fcn-relationships-source"')),a.unobserve(e.target)}}))}),{root:e,rootMargin:"0px",threshold:.5});e.querySelectorAll('[data-target="fcn-relationships-observer"]').forEach((e=>{a.observe(e)}))}function fcn_queryRelationshipPosts(e,t,a=!0){const o=t.closest(".fictioneer-meta-field"),n=o.querySelector('[data-target="fcn-relationships-source"]'),r=o.querySelector('[data-target="fcn-relationships-values"]');let i=null;fcn_ajaxPost(e).then((e=>(t.querySelector('[data-target="fcn-relationships-observer"]')?.remove(),e))).then((e=>{e.success?(a?t.innerHTML+=e.data.html:t.innerHTML=e.data.html,t.querySelectorAll("li").forEach((e=>{r.querySelector(`[data-id="${e.dataset.id}"]`)&&e.classList.add("disabled")})),fcn_observeRelationshipSource(t)):i=e.data.error})).catch((e=>{i=e})).then((()=>{if(i){const e=o.querySelector('[data-target="loading-error-template"]').content.cloneNode(!0);e.querySelector(".error-message").textContent=i,n.appendChild(e)}}))}function fcn_removeRelationship(e){const t=e.closest(".fictioneer-meta-field");if(!t)return;const a=t.querySelector('[data-target="fcn-relationships-source"]').querySelector(`[data-id="${e.dataset.id}"]`);a&&a.classList.remove("disabled"),e.remove()}function fcn_addRelationship(e,t){if(!e||!t||e.classList.contains("disabled"))return;const a=e.closest(".fictioneer-meta-field").querySelector('[data-target="selected-item-template"]').content.cloneNode(!0);a.querySelector("li").setAttribute("data-id",e.dataset.id),a.querySelector('input[type="hidden"]').value=e.dataset.id,a.querySelector("span").innerHTML=e.querySelector("span").innerHTML,e.dataset.info&&a.querySelector("li").setAttribute("data-info",e.dataset.info),t.appendChild(a),e.classList.add("disabled")}_$$("[data-purge-schema]").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_purgeSchema(e.currentTarget.dataset.id)}))})),_$$("[data-action-purge-all-schemas]").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_purgeAllSchemas()}))})),_$$('[data-dialog-target="schema-dialog"]').forEach((e=>{e.addEventListener("click",(e=>{const t=_$('[data-target="schema-content"]');t.value=e.currentTarget.closest("tr").querySelector("[data-schema-id]").textContent,t.scrollTop=0,setTimeout((()=>{t.scrollTop=0}),10)}))})),_$$('[data-action="delete-epub"]').forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_delete_epub(e.target.dataset.name)}))})),(button=_$$$("fictioneer-button-og-upload"))&&button.addEventListener("click",fcn_ogMediaUpload),(button=_$$$("fictioneer-seo-title"))&&(fcn_update_seo_title_chars(),button.addEventListener("keyup",fcn_update_seo_title_chars)),(button=_$$$("fictioneer-button-seo-og-image-remove"))&&button.addEventListener("click",fcn_remove_seo_og_image),_$$("[data-confirm-dialog]").forEach((e=>{e.addEventListener("click",(e=>{fcn_confirmIt(e)}))})),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{localStorage.removeItem("fcnProfileAvatar"),localStorage.removeItem("fcnUserData"),localStorage.removeItem("fcnAuth"),localStorage.removeItem("fcnBookshelfContent"),localStorage.removeItem("fcnChapterBookmarks")})),_$(".fictioneer-settings")?.addEventListener("click",(e=>{const t=e.target.closest("[data-click]"),a=t?.dataset.click;if(a&&"warning-dialog"===a)confirm(t.dataset.dialog)||e.preventDefault()})),_$$("[data-dialog-target]").forEach((e=>{e.addEventListener("click",(e=>{_$$$(e.currentTarget.dataset.dialogTarget)?.showModal()}))})),_$$('button[formmethod="dialog"][value="cancel"]').forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),e.currentTarget.closest("dialog").close()}))})),_$$("dialog").forEach((e=>{e.addEventListener("mousedown",(e=>{"dialog"===e.target.tagName.toLowerCase()&&e.target.close()}))})),_$$(".fictioneer-meta-field__image-upload, .fictioneer-meta-field__image-replace").forEach((e=>{e.addEventListener("click",fcn_imageMediaUpload)})),_$$(".fictioneer-meta-field__image-remove").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault();const t=e.currentTarget.closest('[data-target="fcn-meta-field-image"]');t.querySelector('[data-target="fcn-meta-field-image-id"]').value="",t.querySelector(".fictioneer-meta-field__image-display").style.backgroundImage="",t.querySelector(".fictioneer-meta-field__image-upload").classList.remove("hidden"),t.querySelector(".fictioneer-meta-field__image-actions").classList.add("hidden")}))})),_$$('[data-target="fcn-meta-field-ebook-upload"], [data-target="fcn-meta-field-ebook-replace"]').forEach((e=>{e.addEventListener("click",fcn_ebookMediaUpload)})),_$$('[data-target="fcn-meta-field-ebook-remove"]').forEach((e=>{e.addEventListener("click",fcn_ebookMediaRemove)})),_$$('[data-target="fcn-meta-field-tokens-add"]').forEach((e=>{e.addEventListener("change",(e=>{e.preventDefault();fcn_tokensToggle(parseInt(e.currentTarget.value),e.currentTarget.closest('[data-target="fcn-meta-field-tokens"]'))}))})),_$$('[data-target="fcn-meta-field-tokens-track"]').forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault();const t=e.target.closest(".fictioneer-meta-field__token"),a=e.target.closest(".fictioneer-meta-field__token-button"),o=e.target.closest(".fictioneer-meta-field");t&&a?fcn_tokensToggle(parseInt(t.dataset.id),t.closest('[data-target="fcn-meta-field-tokens"]')):o&&o.querySelector("select").focus()}))})),_$$(".fictioneer-meta-field__icon-button[data-value]").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),fcn_insertIconClass(e.currentTarget)}))})),_$$(".fictioneer-meta-field__fa-icon").forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.closest(".fictioneer-meta-field").querySelector(".fictioneer-meta-field__button-grid");t.classList.toggle("hidden",!t.classList.contains("hidden"))}))})),document.addEventListener("DOMContentLoaded",(()=>{wp.data?.dispatch("core/editor").lockPostSaving("requiredValueLock"),fcn_checkRequiredFields(),_$$(".fictioneer-meta-field [required]").forEach((e=>{const t=e.closest(".fictioneer-meta-field");t.classList.add("pending-validation"),e.addEventListener("input",(()=>{fcn_checkRequiredFields()})),e.addEventListener("input",(()=>{t.classList.remove("pending-validation")}),{once:!0})})),wp.data?.subscribe((()=>{_$$(".fictioneer-meta-field [required]").forEach((e=>{e.closest(".fictioneer-meta-field").classList.toggle("fictioneer-meta-field--invalid",""===e?.value.trim())}))}))})),document.addEventListener("DOMContentLoaded",(()=>{_$$('[data-action="select-story"]').forEach((e=>{fcn_setGroupDataList(e),e.addEventListener("change",(e=>{fcn_setGroupDataList(e.currentTarget)}))}))})),_$$(".fictioneer-meta-field--relationships").forEach((e=>{const t=e.querySelector('[data-target="fcn-relationships-info"]');fcn_observeRelationshipSource(e),e.addEventListener("click",(t=>{t.target.closest('[data-action="remove"]')&&fcn_removeRelationship(t.target.closest("[data-id]")),t.target.closest('[data-action="add"]')&&fcn_addRelationship(t.target.closest("[data-id]"),e.querySelector('[data-target="fcn-relationships-values"]'))})),e.addEventListener("mouseover",(e=>{t&&(info=e.target.closest("[data-info]"))&&(t.innerHTML=info.dataset.info)}))})),_$$('[data-target="fcn-relationships-values"]').forEach((e=>{Sortable.create(e,{selectedClass:"is-dragged",ghostClass:"is-dragged-ghost",fallbackTolerance:3,animation:150,onStart:e=>{e.target.closest("ol, ul").classList.add("is-sorting")},onEnd:e=>{setTimeout((()=>{e.target.closest("ol, ul").classList.remove("is-sorting")}),5)}})})),_$$('[data-target="fcn-relationships-search"]').forEach((e=>{e.addEventListener("input",(()=>{clearTimeout(relationshipSearchTimer),relationshipSearchTimer=setTimeout((()=>{const t=e.closest(".fictioneer-meta-field"),a=t.querySelector('[data-target="fcn-relationships-source"]');a.innerHTML="",a.appendChild(_$('[data-target="spinner-template"]').content.cloneNode(!0)),e.value>200&&(e.value=e.value.slice(0,200)),fcn_queryRelationshipPosts({action:t.dataset.ajaxAction,nonce:t.dataset.nonce,key:t.dataset.key,post_id:t.dataset.postId,search:e.value,post_type:t.querySelector('[data-target="fcn-relationships-post-type"]')?.value??"",fcn_fast_ajax:1},a),(infoBox=t.querySelector('[data-target="fcn-relationships-info"]'))&&(infoBox.innerHTML=infoBox.dataset.default)}),800)}))})),_$$('[data-target="fcn-relationships-post-type"]').forEach((e=>{e.addEventListener("change",(e=>{const t=e.currentTarget.closest(".fictioneer-meta-field--relationships"),a=t.querySelector('[data-target="fcn-relationships-source"]');let o=t.querySelector('[data-target="fcn-relationships-search"]')?.value??"";a.innerHTML="",a.appendChild(_$('[data-target="spinner-template"]').content.cloneNode(!0)),o>200&&(o=o.slice(0,200)),fcn_queryRelationshipPosts({action:t.dataset.ajaxAction,nonce:t.dataset.nonce,key:t.dataset.key,post_id:t.dataset.postId,search:o,post_type:e.currentTarget.value,fcn_fast_ajax:1},a),(infoBox=t.querySelector('[data-target="fcn-relationships-info"]'))&&(infoBox.innerHTML=infoBox.dataset.default)}))})),_$$('[data-action="fcn-relationships-scroll"]').forEach((e=>{const t=e.closest(".fictioneer-meta-field").querySelector('[data-target="fcn-relationships-values"');e.addEventListener("click",(e=>{const a=parseInt(e.currentTarget.dataset.direction);t.scrollBy({top:a*t.offsetHeight*.75,behavior:"smooth"})}))}));
\ No newline at end of file
diff --git a/js/application.min.js b/js/application.min.js
index 25394370..a98ab0ca 100644
--- a/js/application.min.js
+++ b/js/application.min.js
@@ -1 +1 @@
-const fcn_theSite=_$$$("site"),fcn_theBody=_$("body"),fcn_theRoot=document.documentElement,fcn_inlineStorage=_$$$("inline-storage").dataset,fcn_mainNavigation=_$$$("full-navigation"),fcn_urlSearchParams=new URLSearchParams(window.location.search),fcn_urlParams=Object.fromEntries(fcn_urlSearchParams.entries()),fcn_pageLoadTimestamp=Date.now(),fcn_ajaxLimitThreshold=Date.now()-parseInt(fictioneer_ajax.ttl);var fcn_viewportWidth,fcn_mediaMinTablet,fcn_cssVars=getComputedStyle(document.documentElement),fcn_isLoggedIn=fcn_theBody.classList.contains("logged-in"),fcn_chapterList=_$("#story-chapter-list > ul");const{__:__,_x:_x,_n:_n,sprintf:sprintf}=wp.i18n;function fcn_cleanupWebStorage(e=!1){localStorage.removeItem("fcnProfileAvatar"),localStorage.removeItem("fcnBookshelfContent"),e||localStorage.removeItem("fcnChapterBookmarks");const t=fcn_parseJSON(localStorage.getItem("fcnUserData"));t&&(t.loggedIn=!1,t.follows=!1,t.reminders=!1,t.checkmarks=!1,t.bookmarks=!1,t.fingerprint=!1,localStorage.setItem("fcnUserData",JSON.stringify(t)));const n=fcn_parseJSON(localStorage.getItem("fcnAuth"));n?.loggedIn&&localStorage.removeItem("fcnAuth")}function fcn_prepareLogin(){localStorage.removeItem("fcnUserData"),localStorage.removeItem("fcnAuth")}function fcn_cleanupGuestView(){fcn_isLoggedIn=!1,fcn_theBody.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$$("fictioneer-ajax-nonce")?.remove(),_$$(".only-moderators, .only-admins, .only-authors, .only-editors, .chapter-group__list-item-checkmark").forEach((e=>{e.remove()}))}function fcn_ajaxAuth(){let e=!1,t=fcn_parseJSON(localStorage.getItem("fcnAuth"))??!1;if(fcn_isLoggedIn&&!t?.loggedIn&&(localStorage.removeItem("fcnAuth"),t=!1),t){fcn_addNonceHTML(t.nonceHtml);const n=new CustomEvent("fcnAuthReady",{detail:{nonceHtml:t.nonceHtml,nonce:t.nonce,loggedIn:t.loggedIn,isAdmin:t.isAdmin,isModerator:t.isModerator,isAuthor:t.isAuthor,isEditor:t.isEditor},bubbles:!0,cancelable:!1});if(document.dispatchEvent(n),e=!0,fcn_ajaxLimitThreshold{if(t.success){fcn_addNonceHTML(t.data.nonceHtml);const n={lastLoaded:Date.now(),nonceHtml:t.data.nonceHtml,nonce:t.data.nonce,loggedIn:t.data.loggedIn,isAdmin:t.data.isAdmin,isModerator:t.data.isModerator,isAuthor:t.data.isAuthor,isEditor:t.data.isEditor};if(!e){const e=new CustomEvent("fcnAuthReady",{detail:n,bubbles:!0,cancelable:!1});document.dispatchEvent(e)}localStorage.setItem("fcnAuth",JSON.stringify(n))}else{fcn_cleanupGuestView();const e=new Event("fcnAuthFailed");document.dispatchEvent(e)}})).catch((()=>{localStorage.removeItem("fcnAuth"),fcn_cleanupGuestView();const e=new Event("fcnAuthError");document.dispatchEvent(e)}))}function fcn_addNonceHTML(e){_$$$("fictioneer-ajax-nonce")?.remove(),fcn_theBody.appendChild(fcn_html`${e}`)}function fcn_setLoggedInState(e){fcn_isLoggedIn=e.loggedIn,fcn_theBody.classList.add("logged-in"),fcn_theBody.classList.toggle("is-admin",e.isAdmin),fcn_theBody.classList.toggle("is-moderator",e.isModerator),fcn_theBody.classList.toggle("is-author",e.isAuthor),fcn_theBody.classList.toggle("is-editor",e.isEditor),e.isAdmin||_$$(".only-admins").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-moderators").forEach((e=>{e.remove()})),e.isAuthor||e.isAdmin||_$$(".only-authors").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-editors").forEach((e=>{e.remove()})),_$$('label[for="modal-login-toggle"], #modal-login-toggle, #login-modal').forEach((e=>{e.remove()})),fcn_getProfileImage(),fcn_fetchUserData()}function fcn_updateViewportVariables(){fcn_viewportWidth=Math.max(document.documentElement.clientWidth??0,window.innerWidth??0),fcn_mediaMinTablet=fcn_viewportWidth>=768}function fcn_loadEmbed(e){e.target.parentNode.querySelectorAll("iframe, script")[0].src=e.target.dataset.src,e.target.parentElement.querySelector(".embed-logo")?.remove(),e.target.remove()}fcn_chapterList&&(fcn_chapterList=fcn_chapterList.cloneNode(!0),_$$$("story-chapter-list").remove(),fcn_chapterList.querySelector(`[data-id="${fcn_chapterList.dataset.currentId}"]`)?.classList.add("current-chapter")),fcn_isLoggedIn||fcn_theRoot.dataset.ajaxAuth||(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView()),"function"==typeof fcn_removeQueryArgs&&fcn_removeQueryArgs(),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{fcn_cleanupWebStorage()})),_$$(".subscriber-login, .oauth-login-link, [data-prepare-login]").forEach((e=>{e.addEventListener("click",(()=>{fcn_prepareLogin()}))})),document.addEventListener("DOMContentLoaded",(()=>{fcn_theRoot.dataset.ajaxAuth&&fcn_ajaxAuth()})),!fcn_isLoggedIn&&fcn_theRoot.dataset.ajaxAuth&&document.addEventListener("fcnAuthReady",(e=>{e.detail.loggedIn?fcn_setLoggedInState(e.detail):(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView())})),fcn_bindEventToAnimationFrame("scroll","scroll.rAF"),fcn_bindEventToAnimationFrame("resize","resize.rAF"),fcn_updateViewportVariables(),window.addEventListener("resize.rAF",fcn_throttle(fcn_updateViewportVariables,125)),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest(".toggle-last-clicked");if(t&&(!["BUTTON","A","INPUT","SELECT"].includes(e.target.tagName)||e.target.classList.contains("toggle-last-clicked")))return"function"==typeof fcn_toggleLastClicked&&fcn_toggleLastClicked(t),"function"==typeof fcn_popupPosition&&fcn_popupPosition(),void e.stopPropagation();const n=e.target.closest(".page-numbers.dots:not(button)");if(n)return void fcn_jumpPage(n);const o=e.target.closest(".spoiler");if(o)return void("function"==typeof fct_spoiler&&fct_spoiler(o));(e.target.closest(".oauth-login-link")||e.target.closest(".subscriber-login")||e.target.closest("[data-prepare-login]"))&&fcn_prepareLogin();const a=e.target.closest("[data-click]"),s=a?.dataset.click;if(s)switch(s){case"copy-to-clipboard":a.select(),fcn_copyToClipboard(a.value,a.dataset.message);break;case"reset-consent":fcn_deleteCookie("fcn_cookie_consent"),location.reload();break;case"clear-cookies":fcn_deleteAllCookies(),alert(a.dataset.message);break;case"logout":fcn_cleanupWebStorage();break;case"card-toggle-follow":fcn_isLoggedIn?fcn_toggleFollow(a.dataset.storyId):_$$$("modal-login-toggle")?.click();break;case"card-toggle-reminder":fcn_isLoggedIn?fcn_toggleReminder(a.dataset.storyId):_$$$("modal-login-toggle")?.click();break;case"card-toggle-checkmarks":fcn_isLoggedIn?(fcn_toggleCheckmark(parseInt(a.dataset.storyId),a.dataset.type,parseInt(a.dataset.chapterId),null,a.dataset.mode),fcn_updateCheckmarksView()):_$$$("modal-login-toggle")?.click();break;case"toggle-obfuscation":a.closest("[data-obfuscation-target]").classList.toggle("_obfuscated")}})),fcn_theBody.addEventListener("change",(e=>{const t=e.target.closest('[type="checkbox"]');if(!t)return;const n=t.name,o=n?_$$(`label[for="${n}"]`):[],a=t.checked;t.closest("[aria-checked]")?.setAttribute("aria-checked",a),o.forEach((e=>{e.closest("[aria-checked]")?.setAttribute("aria-checked",a)}))})),_$$(".iframe-consent, .twitter-consent").forEach((e=>{e.onclick=e=>{fcn_loadEmbed(e)}}));var fcn_lastScrollTop=0;function fcn_scrollDirection(){const e="hidden"!==window.getComputedStyle(document.documentElement).overflow?window.scrollY??document.documentElement.scrollTop:fcn_theBody.scrollTop??1;fcn_theBody.classList.toggle("scrolled-to-top",0===e),fcn_theSite.classList.contains("transformed-scroll")||Math.abs(fcn_lastScrollTop-e)>=25&&(fcn_theBody.classList.toggle("scrolling-down",e>fcn_lastScrollTop),fcn_theBody.classList.toggle("scrolling-up",!(e>fcn_lastScrollTop)),fcn_lastScrollTop=Math.max(e,0))}window.addEventListener("scroll.rAF",fcn_throttle(fcn_scrollDirection,200)),fcn_scrollDirection();const fcn_mainObserver=new IntersectionObserver((([e])=>{fcn_theBody.classList.toggle("is-inside-main",e.intersectionRatio<1&&e.boundingClientRect.top<=0)}),{threshold:[1]}),fcn_endOfChapterObserver=new IntersectionObserver((([e])=>{fcn_theBody.classList.toggle("is-end-of-chapter",e.isIntersecting||e.boundingClientRect.top<0)}),{root:null,threshold:0}),fct_navStickyObserver=new IntersectionObserver((([e])=>{fcn_mainNavigation.classList.toggle("is-sticky",e.intersectionRatio<1)}),{threshold:[1]});function fcn_dragElement(e){const t=e.querySelector(".drag-anchor")??e;let n,o;function a(t){t.preventDefault(),e.style.top=e.offsetTop-(o-t.clientY)+"px",e.style.left=e.offsetLeft-(n-t.clientX)+"px",n=t.clientX,o=t.clientY}function s(){t.onmouseup=null,t.onmousemove=null}t.onmousedown=function(e){e.preventDefault(),n=e.clientX,o=e.clientY,t.onmousemove=a,t.onmouseup=s}}function fcn_showNotification(e,t=3,n="base"){const o=_$("#notifications"),a=document.createElement("div");a.innerHTML=e,a.classList.add("notifications__message",`_${n}`),a.style.opacity=1,a.style.transitionDelay=`${t}s`,o.prepend(a),a.addEventListener("transitionend",(e=>{o.removeChild(e.target)})),a.addEventListener("click",(e=>{o.removeChild(e.currentTarget)})),setTimeout((()=>{a.style.opacity=0}),100)}if(document.addEventListener("DOMContentLoaded",(()=>{_$(".main-observer")&&fcn_mainObserver.observe(_$(".main-observer")),_$(".chapter-end")&&fcn_endOfChapterObserver.observe(_$(".chapter-end")),_$$$("nav-observer-sticky")&&fct_navStickyObserver.observe(_$$$("nav-observer-sticky"))})),_$$(".modal__header.drag-anchor").forEach((e=>{fcn_dragElement(e.closest(".modal__wrapper"))})),"oauth_email_taken"===fcn_urlParams.failure&&fcn_showNotification(__("The associated email address is already taken. You can link additional accounts in your profile.","fictioneer"),5,"warning"),"oauth_already_linked"===fcn_urlParams.failure&&fcn_showNotification(__("Account already linked to another profile.","fictioneer"),5,"warning"),"oauth_new"===fcn_urlParams.success&&fcn_showNotification(__("Your account has been successfully linked. Hint: You can change your display name in your profile and link additional accounts.","fictioneer"),10),fcn_urlParams.success?.includes("oauth_merged_")&&fcn_showNotification(__("Account has been successfully linked.","fictioneer"),3,"success"),fcn_urlParams["fictioneer-notice"]&&""!==fcn_urlParams["fictioneer-notice"]){let e="1"===fcn_urlParams.failure?"warning":"base";e="1"===fcn_urlParams.success?"success":e,fcn_showNotification(__(fcn_sanitizeHTML(fcn_urlParams["fictioneer-notice"]),"fictioneer"),3,e)}const fcn_settingMinimal=_$$$("site-setting-minimal"),fcn_settingChapterProgressBar=_$$$("site-setting-chapter-progress-bar"),fcn_settingHueRotateRange=_$$$("site-setting-hue-rotate-range"),fcn_settingHueRotateText=_$$$("site-setting-hue-rotate-text"),fcn_settingHueRotateReset=_$$$("site-setting-hue-rotate-reset"),fcn_settingDarkenRanges=_$$(".setting-darken-range"),fcn_settingDarkenTexts=_$$(".setting-darken-text"),fcn_settingDarkenResets=_$$(".setting-darken-reset"),fcn_settingSaturationRanges=_$$(".setting-saturation-range"),fcn_settingSaturationTexts=_$$(".setting-saturation-text"),fcn_settingSaturationResets=_$$(".setting-saturation-resets"),fcn_settingEvents=["nav-sticky","background-textures","polygons","covers","text-shadows","minimal","chapter-progress-bar"];var fcn_siteSettings=fcn_getSiteSettings();function fcn_updateSiteSetting(e,t,n){e.checked=n,fcn_siteSettings[t]=n,fcn_applySiteSettings(fcn_siteSettings)}function fcn_toggleLightMode(){fcn_setLightMode(!(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault))}function fcn_setLightMode(e,t=!1){localStorage.setItem("fcnLightmode",e),fcn_theRoot.dataset.mode=e?"light":"dark",_$$(".toggle-light-mode").forEach((t=>{t.closest("[aria-checked]")?.setAttribute("aria-checked",e)})),t||fcn_updateThemeColor()}function fcn_updateFontWeight(){const e="default"!=fcn_siteSettings["font-weight"];_$$(".site-setting-font-weight").forEach((e=>{e.value=fcn_siteSettings["font-weight"]})),_$$(".font-weight-reset").forEach((t=>{t.classList.toggle("_modified",e)}))}function fcn_resetFontWeight(){fcn_siteSettings["font-weight"]="default",fcn_theRoot.dataset.fontWeight="default",fcn_applySiteSettings(fcn_siteSettings)}function fcn_updateHueRotate(e){e=fcn_clamp(0,360,e??0),fcn_settingHueRotateText.value=e,fcn_settingHueRotateRange.value=e,fcn_settingHueRotateReset.classList.toggle("_modified",0!=e),fcn_theRoot.style.setProperty("--hue-rotate",`${e}deg + var(--hue-offset)`),fcn_siteSettings["hue-rotate"]=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setHueRotate(){fcn_updateHueRotate(this.value)}function fcn_updateDarken(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.darken),e=Math.round(100*(e+Number.EPSILON))/100,fcn_settingDarkenResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingDarkenRanges.forEach((t=>{t.value=e})),fcn_settingDarkenTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--darken",`(${t} + var(--lightness-offset))`),fcn_siteSettings.darken=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setDarkenFromRange(){fcn_updateDarken(this.value)}function fcn_setDarkenFromText(){"-"!=this.value&&""!=this.value&&fcn_updateDarken((parseInt(this.value)??0)/100)}function fcn_updateSaturation(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.saturation),fcn_settingSaturationResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingSaturationRanges.forEach((t=>{t.value=e})),fcn_settingSaturationTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--saturation",`(${t} + var(--saturation-offset))`),fcn_siteSettings.saturation=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setSaturationFromRange(){fcn_updateSaturation(this.value)}function fcn_setSaturationFromText(){"-"!=this.value&&""!=this.value&&fcn_updateSaturation((parseInt(this.value)??0)/100)}function fcn_defaultSiteSettings(){return{"nav-sticky":!0,"background-textures":!0,polygons:!0,covers:!0,"text-shadows":!1,minimal:!1,"chapter-progress-bar":!0,"site-theme":"default","font-weight":"default",darken:0,saturation:0,"font-saturation":0,"hue-rotate":0}}function fcn_getSiteSettings(){const e=fcn_parseJSON(localStorage.getItem("fcnSiteSettings"))??fcn_defaultSiteSettings();return fcn_setSiteSettings(e),e}function fcn_setSiteSettings(e=null){"object"==typeof(e=e||fcn_siteSettings)&&(fcn_siteSettings=e,localStorage.setItem("fcnSiteSettings",JSON.stringify(e)))}function fcn_applySiteSettings(e){e="object"!=typeof e?fcn_defaultSiteSettings():e,Object.entries(e).forEach((e=>{const t=_$$$(`site-setting-${e[0]}`);switch(t&&(t.checked=e[1]),e[0]){case"minimal":fcn_theRoot.classList.toggle("minimal",e[1]);break;case"darken":fcn_updateDarken();break;case"saturation":fcn_updateSaturation();break;case"font-saturation":break;case"hue-rotate":fcn_updateHueRotate(e[1]);break;case"font-weight":fcn_updateFontWeight();break;default:fcn_theRoot.classList.toggle(`no-${e[0]}`,!e[1])}})),fcn_setSiteSettings(e)}function fcn_updateSiteTheme(e){fcn_siteSettings["site-theme"]=e,fcn_theRoot.dataset.theme=e,_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e),fcn_applySiteSettings(fcn_siteSettings),fcn_updateThemeColor()}function fcn_resetSiteTheme(){fcn_updateSiteTheme("default"),_$$(".site-setting-site-theme").forEach((e=>{e.value="default"}))}function fcn_jumpPage(e){if(fcn_theRoot.dataset.disablePageJump)return;const t=parseInt(window.prompt(_x("Enter page number:","Pagination jump prompt.","fictioneer")));if(t>0){const n=e.nextElementSibling.getAttribute("href"),o=["page=","paged=","comment-page-","pg="];for(const e of o)if(n.includes(e))return void(window.location.href=n.replace(new RegExp(`${e}\\d+`),e+t));window.location.href=n.replace(/page\/\d+/,`page/${t}`)}}fcn_settingEvents.forEach((e=>{_$$$(`site-setting-${e}`)?.addEventListener("change",(t=>{fcn_updateSiteSetting(t.currentTarget,e,t.currentTarget.checked)}))})),fcn_setLightMode(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault,!0),_$$(".toggle-light-mode").forEach((e=>{e.onclick=()=>fcn_toggleLightMode()})),_$$(".font-weight-reset").forEach((e=>{e.addEventListener("click",fcn_resetFontWeight)})),_$$(".site-setting-font-weight").forEach((e=>{e.onchange=e=>{fcn_siteSettings["font-weight"]=e.target.value,fcn_theRoot.dataset.fontWeight=e.target.value,fcn_applySiteSettings(fcn_siteSettings),fcn_updateFontWeight()}})),fcn_settingHueRotateReset?.addEventListener("click",(()=>{fcn_updateHueRotate(0)})),fcn_settingHueRotateRange?.addEventListener("input",fcn_throttle(fcn_setHueRotate,1e3/24)),fcn_settingHueRotateText?.addEventListener("input",fcn_setHueRotate),fcn_settingDarkenResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateDarken(0)}))})),fcn_settingDarkenRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setDarkenFromRange,1e3/24))})),fcn_settingDarkenTexts.forEach((e=>{e.addEventListener("input",fcn_setDarkenFromText)})),fcn_settingSaturationResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateSaturation(0)}))})),fcn_settingSaturationRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setSaturationFromRange,1e3/24))})),fcn_settingSaturationTexts.forEach((e=>{e.addEventListener("input",fcn_setSaturationFromText)})),fcn_applySiteSettings(fcn_siteSettings),_$$(".site-setting-site-theme").forEach((e=>{e.value=fcn_siteSettings.hasOwnProperty("site-theme")?fcn_siteSettings["site-theme"]:"default",_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e.value),e.addEventListener("change",(e=>{fcn_updateSiteTheme(e.target.value)}))})),_$$$("site-setting-theme-reset")?.addEventListener("click",fcn_resetSiteTheme),fcn_updateThemeColor();const fcn_cardLists=_$$(".card-list:not(._no-mutation-observer)");var fcn_cardListMutationObserver=new MutationObserver((e=>{e[0].addedNodes&&("function"==typeof fcn_updateFollowsView&&fcn_updateFollowsView(),"function"==typeof fcn_updateCheckmarksView&&fcn_updateCheckmarksView(),"function"==typeof fcn_updateRemindersView&&fcn_updateRemindersView())}));function fct_spoiler(e){e.classList.toggle("_open")}function fcn_revealCommentImage(e){const t=e.parentElement.querySelector("img");t.src=t.dataset.src,e.remove()}function fcn_contactFormSubmit(e){const t=e.closest("form"),n=new FormData(t),o={action:"fictioneer_ajax_submit_contact_form"};if(t.reportValidity()&&(e.disabled=!0,e.innerHTML=e.dataset.disabled,!(Date.now(){n.success?(t.querySelector("textarea").value="",e.innerHTML=e.dataset.done,fcn_showNotification(n.data.success,3,"success")):n.data.error&&(e.disabled=!1,e.innerHTML=e.dataset.enabled,fcn_showNotification(n.data.error,5,"warning"))})).catch((t=>{t.status&&t.statusText&&(fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),e.disabled=!1,e.innerHTML=e.dataset.enabled)})).then((()=>{t.classList.remove("ajax-in-progress")}))}}fcn_cardLists.length&&fcn_cardLists.forEach((e=>{fcn_cardListMutationObserver.observe(e,{childList:!0,subtree:!0})})),_$$(".chapter-group__name").forEach((e=>{e.addEventListener("click",(e=>{var t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list"),o=!t.classList.contains("_closed");n.style.height=`${n.scrollHeight}px`,setTimeout((()=>{t.classList.toggle("_closed",o)}),10)})),e.closest(".chapter-group").querySelector(".chapter-group__list").addEventListener("transitionend",(e=>{const t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list");n.style.height="",n.querySelectorAll("a, button, label, input:not([hidden])").forEach((e=>{e.tabIndex=t.classList.contains("_closed")?"-1":"0"}))}))})),_$(".fictioneer-comments")?.addEventListener("click",(e=>{e.target?.classList.contains("consent-button")&&fcn_revealCommentImage(e.target)})),_$$(".fcn-contact-form").forEach((e=>{e.querySelector(".fcn-contact-form__submit").addEventListener("click",(e=>{fcn_contactFormSubmit(e.currentTarget)}))})),fcn_theBody.querySelectorAll(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{if(e.currentTarget.checked){const t=e.currentTarget.nextElementSibling.querySelector('[tabindex="0"]');t?.focus(),t?.blur()}else fcn_theBody.classList.contains("user-is-tabbing")&&fcn_theSite.querySelector(`label[for="${e.currentTarget.id}"]`)?.focus()}))})),fcn_theBody.addEventListener("keydown",(e=>{let t=document.activeElement.closest('[tabindex="0"]:not(a, input, button, select)');if(["BUTTON","A","INPUT","SELECT"].includes(document.activeElement.tagName)&&(t=null),t&&(32!=e.keyCode&&13!=e.keyCode||(e.preventDefault(),t.click())),27==e.keyCode){_$$(".modal-toggle:checked").forEach((e=>{e.checked=!1,e.dispatchEvent(new Event("change"))}));const e=_$(".lightbox.show");if(e)return void e.querySelector(".lightbox__close").click();const t=_$(".selected-paragraph #button-close-paragraph-tools");if(t)return void t.click();const n=_$("#tts-interface:not(.hidden)");if(n){if(n.classList.contains("playing")){const e=_$$$("button-tts-pause");e?.click(),e?.focus(),e?.blur()}else _$$$("button-tts-stop").click();return}}}));class FCN_KeywordInput{constructor(e){this.input=e,this.operator=e.closest(".keyword-input").querySelector(".keyword-input__operator input"),this.inputWrapper=e.closest(".keyword-input__input-wrapper"),this.block=e.closest(".keyword-input"),this.form=this.block.closest(".search-form"),this.collection=this.block.querySelector(".keyword-input__collection"),this.suggestionList=this.block.querySelector(".keyword-input__suggestion-list"),this.tabSuggestion=this.block.querySelector(".keyword-input__tab-suggestion"),this.allowText=this.form.querySelector(".allow-list")?.innerText??"{}",this.allowList=JSON.parse(this.allowText),this.hints=this.block.querySelector(".keyword-input__hints"),this.noHint=this.block.querySelector(".keyword-input__no-suggestions"),this.keywords=this.collection.value.length>0?this.collection.value.split(","):[],this.bindEvents(),this.resize(),this.filterSuggestions()}resize(){const e=this.tabSuggestion.innerText.length>0?this.tabSuggestion.innerText.length:this.input.value.length;this.input.style.width=.88*e+2+"ch"}reset(){this.keywords=[],this.block.querySelectorAll(".node").forEach((e=>{e.remove()})),this.block.querySelectorAll(".keyword-input__operator > input").forEach((e=>{e.checked=!1})),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}encode(e){return encodeURIComponent(e.toLowerCase()).replace(/'/g,"%27")}filterSuggestions(){const e=this.input.value.toLowerCase();let t=0,n="";""==e?this.suggestionList.querySelectorAll(".keyword-button").forEach((e=>{e.hidden=!0})):this.suggestionList.querySelectorAll(".keyword-button").forEach((o=>{const a=o.innerText.toLowerCase();a.includes(e)&&this.keywords.indexOf(a)<0?(o.hidden=!1,t++,""==n&&a.startsWith(e)&&(n=a)):o.hidden=!0})),this.hints.querySelectorAll(".keyword-button").forEach((e=>{this.keywords.indexOf(e.value.toLowerCase())>-1?e.hidden=!0:e.hidden=!1})),this.tabSuggestion.innerHTML=n,this.hints.hidden=!(""==e),this.noHint.hidden=!(""!=e&&t<1)}addNode(e=null){const t=e??this.input.value.replace(",",""),n=this.allowList[this.encode(t)];if(!n||this.keywords.indexOf(n)>-1)return;this.keywords.push(n);const o=document.createElement("div");o.innerHTML=`${t}`,o.classList.add("node"),o.dataset.value=n,this.inputWrapper.parentNode.insertBefore(o,this.inputWrapper),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}removeNodeByValue(e){this.block.querySelector(`[data-value="${e}"]`)?.remove(),this.keywords.splice(this.keywords.indexOf(e),1),this.updateCollection(),this.filterSuggestions(),this.resize()}updateCollection(){this.collection.value=this.keywords.join(","),this.block.classList.toggle("_empty",""===this.collection.value),this.form.querySelector(".search-form__current").innerHTML=""}bindEvents(){this.input.addEventListener("input",(e=>{e.currentTarget.value.includes(",")&&this.addNode(),this.block.classList.toggle("_empty",""===e.currentTarget.value),this.filterSuggestions(),this.resize()})),this.input.addEventListener("keydown",(e=>{9!=e.keyCode&&13!=e.keyCode||""!=this.tabSuggestion.innerText&&(e.preventDefault(),this.input.value=this.tabSuggestion.innerText,this.addNode()),27==e.keyCode&&(this.input.value="",this.tabSuggestion.innerHTML="",document.activeElement.blur()),8==e.keyCode&&""==this.input.value&&this.keywords.length>0&&this.removeNodeByValue(this.keywords.slice(-1))})),this.input.addEventListener("blur",(()=>{const e=this.allowList[this.encode(this.input.value)];this.blurTimeout=e?setTimeout((()=>{this.addNode()}),150):setTimeout((()=>{this.input.value="",this.tabSuggestion.innerHTML="",this.filterSuggestions(),this.resize()}),150)})),this.block.addEventListener("click",(e=>{e.target.closest(".node-delete")&&(e.preventDefault(),this.removeNodeByValue(e.target.closest(".node").dataset.value))})),this.block.querySelectorAll(".keyword-button").forEach((e=>{e.addEventListener("click",(e=>{clearTimeout(this.blurTimeout),this.addNode(e.currentTarget.innerText)}))}))}}function fcn_handleTabInput(e){9==e.keyCode&&(fcn_theBody.classList.add("user-is-tabbing"),window.removeEventListener("keydown",fcn_handleTabInput),window.addEventListener("mousedown",fcn_handleMouseInput))}function fcn_handleMouseInput(){fcn_theBody.classList.remove("user-is-tabbing"),window.removeEventListener("mousedown",fcn_handleMouseInput),window.addEventListener("keydown",fcn_handleTabInput)}function fcn_popupPosition(){_$$(".popup-menu-toggle.last-clicked .popup-menu:not(._fixed-position)").forEach((e=>{if("none"===window.getComputedStyle(e).display)return;const t=fcn_detectScreenCollision(e);t&&0===t.length||(t.includes("top")?(e.classList.remove("_top"),e.classList.add("_bottom")):t.includes("bottom")&&(e.classList.remove("_bottom"),e.classList.add("_top")))}))}function fcn_markCurrentMenuItem(){_$$(`.menu-item > [data-nav-object-id="${fcn_theBody.dataset.postId}"]`).forEach((e=>{e.setAttribute("aria-current","page"),e.closest(".menu-item").classList.add("current-menu-item")}))}function fcn_showAgeConfirmationModal(){const e=_$(".story__article, .chapter__article")?.dataset.ageRating;if(!fcn_theRoot.dataset.ageConfirmation&&e&&"adult"!==e)return void _$$$("age-confirmation-modal")?.remove();const t=_$$$("age-confirmation-leave");fcn_theRoot.classList.add("age-modal-open"),_$$$("age-confirmation-modal").classList.add("_open"),_$$$("age-confirmation-confirm")?.addEventListener("click",(e=>{fcn_theRoot.classList.remove("age-modal-open"),e.currentTarget.closest(".modal").remove(),localStorage.setItem("fcnAgeConfirmation","1")})),t?.addEventListener("click",(()=>{window.location.href=t.dataset.redirect??"https://search.brave.com/",localStorage.removeItem("fcnAgeConfirmation")}))}_$$(".search-form").forEach((e=>{const t=[];e.classList.contains("_simple")||(e.querySelectorAll(".keyword-input__input").forEach((e=>{t.push(new FCN_KeywordInput(e))})),e.querySelector(".allow-list")?.remove(),e.addEventListener("change",(t=>{t.target.classList.contains("search-form__advanced-control")||t.target.classList.contains("search-form__string")||(e.querySelector(".search-form__current").innerHTML="")})),e.querySelectorAll(".reset").forEach((n=>{n.addEventListener("click",(o=>{t.forEach((e=>{e.reset()})),e.querySelector("input[name=s]").value="",e.querySelector("select[name=post_type]").value="any",e.querySelector("select[name=sentence]").value="0",e.querySelector("select[name=orderby]").value="modified",e.querySelector("select[name=order]").value="desc",e.querySelector(".search-form__current").innerHTML="",fcn_showNotification(n.dataset.reset,2)}))})))})),_$$(".search-form__advanced-toggle").forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.closest("form");t.dataset.advanced="true"==t.dataset.advanced?"false":"true"}))})),window.addEventListener("keydown",fcn_handleTabInput),window.addEventListener("scroll.rAF",fcn_throttle(fcn_popupPosition,250)),_$$(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{const t=_$$$(e.currentTarget.dataset.target);t.classList.toggle("_open",e.currentTarget.checked);const n=t.querySelector(".close");n?.focus(),n?.blur()}))})),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest("[href]"),n=t?.getAttribute("href");if(!t||"A"===!t.tagName||!n.startsWith("#")||n.length<2||"#respond"===n)return;const o=n.replace("#",""),a=_$$(`[name="${o}"], #${o}`)[0],s=t.closest(".comment._story-comment");s&&(window.location.href=s.querySelector(".fictioneer-comment__link").href+n),a&&(e.preventDefault(),a.scrollIntoView({behavior:"smooth",block:t.dataset?.block??"start"}))})),fcn_markCurrentMenuItem(),_$$$("age-confirmation-modal")&&"1"!==localStorage.getItem("fcnAgeConfirmation")?setTimeout((()=>{fcn_showAgeConfirmationModal()}),2e3):_$$$("age-confirmation-modal")?.remove();
\ No newline at end of file
+const fcn_theSite=_$$$("site"),fcn_theBody=_$("body"),fcn_theRoot=document.documentElement,fcn_inlineStorage=_$$$("inline-storage").dataset,fcn_mainNavigation=_$$$("full-navigation"),fcn_urlSearchParams=new URLSearchParams(window.location.search),fcn_urlParams=Object.fromEntries(fcn_urlSearchParams.entries()),fcn_pageLoadTimestamp=Date.now(),fcn_ajaxLimitThreshold=Date.now()-parseInt(fictioneer_ajax.ttl);var fcn_viewportWidth,fcn_mediaMinTablet,fcn_cssVars=getComputedStyle(document.documentElement),fcn_isLoggedIn=fcn_theBody.classList.contains("logged-in"),fcn_chapterList=_$("#story-chapter-list > ul");const{__:__,_x:_x,_n:_n,sprintf:sprintf}=wp.i18n;function fcn_cleanupWebStorage(e=!1){const t=["fcnProfileAvatar","fcnBookshelfContent"];e||t.push("fcnChapterBookmarks"),t.forEach((e=>localStorage.removeItem(e)));const n=["loggedIn","follows","reminders","checkmarks","bookmarks","fingerprint"],o=fcn_parseJSON(localStorage.getItem("fcnUserData"));o&&(n.forEach((e=>o[e]=!1)),localStorage.setItem("fcnUserData",JSON.stringify(o)));const a=fcn_parseJSON(localStorage.getItem("fcnAuth"));a?.loggedIn&&localStorage.removeItem("fcnAuth")}function fcn_prepareLogin(){localStorage.removeItem("fcnUserData"),localStorage.removeItem("fcnAuth")}function fcn_cleanupGuestView(){fcn_isLoggedIn=!1,fcn_theBody.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$$("fictioneer-ajax-nonce")?.remove(),_$$(".only-moderators, .only-admins, .only-authors, .only-editors, .chapter-group__list-item-checkmark").forEach((e=>{e.remove()}))}function fcn_ajaxAuth(){let e=!1,t=fcn_parseJSON(localStorage.getItem("fcnAuth"))??!1;if(fcn_isLoggedIn&&!t?.loggedIn&&(localStorage.removeItem("fcnAuth"),t=!1),t){fcn_addNonceHTML(t.nonceHtml);const n=new CustomEvent("fcnAuthReady",{detail:{nonceHtml:t.nonceHtml,nonce:t.nonce,loggedIn:t.loggedIn,isAdmin:t.isAdmin,isModerator:t.isModerator,isAuthor:t.isAuthor,isEditor:t.isEditor},bubbles:!0,cancelable:!1});if(document.dispatchEvent(n),e=!0,fcn_ajaxLimitThreshold{if(t.success){fcn_addNonceHTML(t.data.nonceHtml);const n={lastLoaded:Date.now(),nonceHtml:t.data.nonceHtml,nonce:t.data.nonce,loggedIn:t.data.loggedIn,isAdmin:t.data.isAdmin,isModerator:t.data.isModerator,isAuthor:t.data.isAuthor,isEditor:t.data.isEditor};if(!e){const e=new CustomEvent("fcnAuthReady",{detail:n,bubbles:!0,cancelable:!1});document.dispatchEvent(e)}localStorage.setItem("fcnAuth",JSON.stringify(n))}else{fcn_cleanupGuestView();const e=new Event("fcnAuthFailed");document.dispatchEvent(e)}})).catch((()=>{localStorage.removeItem("fcnAuth"),fcn_cleanupGuestView();const e=new Event("fcnAuthError");document.dispatchEvent(e)}))}function fcn_addNonceHTML(e){_$$$("fictioneer-ajax-nonce")?.remove(),fcn_theBody.appendChild(fcn_html`${e}`)}function fcn_setLoggedInState(e){fcn_isLoggedIn=e.loggedIn,fcn_theBody.classList.add("logged-in"),fcn_theBody.classList.toggle("is-admin",e.isAdmin),fcn_theBody.classList.toggle("is-moderator",e.isModerator),fcn_theBody.classList.toggle("is-author",e.isAuthor),fcn_theBody.classList.toggle("is-editor",e.isEditor),e.isAdmin||_$$(".only-admins").forEach((e=>e.remove())),e.isModerator||e.isAdmin||_$$(".only-moderators").forEach((e=>e.remove())),e.isAuthor||e.isAdmin||_$$(".only-authors").forEach((e=>e.remove())),e.isModerator||e.isAdmin||_$$(".only-editors").forEach((e=>e.remove())),_$$('label[for="modal-login-toggle"], #modal-login-toggle, #login-modal').forEach((e=>e.remove())),fcn_getProfileImage(),fcn_fetchUserData()}function fcn_updateViewportVariables(){fcn_viewportWidth=Math.max(document.documentElement.clientWidth??0,window.innerWidth??0),fcn_mediaMinTablet=fcn_viewportWidth>=768}function fcn_loadEmbed(e){e.target.parentNode.querySelectorAll("iframe, script")[0].src=e.target.dataset.src,e.target.parentElement.querySelector(".embed-logo")?.remove(),e.target.remove()}fcn_chapterList&&(fcn_chapterList=fcn_chapterList.cloneNode(!0),_$$$("story-chapter-list").remove(),fcn_chapterList.querySelector(`[data-id="${fcn_chapterList.dataset.currentId}"]`)?.classList.add("current-chapter")),fcn_isLoggedIn||fcn_theRoot.dataset.ajaxAuth||(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView()),"function"==typeof fcn_removeQueryArgs&&fcn_removeQueryArgs(),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{fcn_cleanupWebStorage()})),_$$(".subscriber-login, .oauth-login-link, [data-prepare-login]").forEach((e=>{e.addEventListener("click",(()=>{fcn_prepareLogin()}))})),document.addEventListener("DOMContentLoaded",(()=>{fcn_theRoot.dataset.ajaxAuth&&fcn_ajaxAuth()})),!fcn_isLoggedIn&&fcn_theRoot.dataset.ajaxAuth&&document.addEventListener("fcnAuthReady",(e=>{e.detail.loggedIn?fcn_setLoggedInState(e.detail):(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView())})),fcn_bindEventToAnimationFrame("scroll","scroll.rAF"),fcn_bindEventToAnimationFrame("resize","resize.rAF"),fcn_updateViewportVariables(),window.addEventListener("resize.rAF",fcn_throttle(fcn_updateViewportVariables,125)),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest(".toggle-last-clicked");if(t&&(!["BUTTON","A","INPUT","SELECT"].includes(e.target.tagName)||e.target.classList.contains("toggle-last-clicked")))return"function"==typeof fcn_toggleLastClicked&&fcn_toggleLastClicked(t),"function"==typeof fcn_popupPosition&&fcn_popupPosition(),void e.stopPropagation();const n=e.target.closest(".page-numbers.dots:not(button)");if(n)return void fcn_jumpPage(n);const o=e.target.closest(".spoiler");if(o)return void("function"==typeof fct_spoiler&&fct_spoiler(o));(e.target.closest(".oauth-login-link")||e.target.closest(".subscriber-login")||e.target.closest("[data-prepare-login]"))&&fcn_prepareLogin();const a=e.target.closest("[data-click]"),s=a?.dataset.click;if(s)switch(s){case"copy-to-clipboard":a.select(),fcn_copyToClipboard(a.value,a.dataset.message);break;case"reset-consent":fcn_deleteCookie("fcn_cookie_consent"),location.reload();break;case"clear-cookies":fcn_deleteAllCookies(),alert(a.dataset.message);break;case"logout":fcn_cleanupWebStorage();break;case"card-toggle-follow":fcn_isLoggedIn?fcn_toggleFollow(a.dataset.storyId):_$$$("modal-login-toggle")?.click();break;case"card-toggle-reminder":fcn_isLoggedIn?fcn_toggleReminder(a.dataset.storyId):_$$$("modal-login-toggle")?.click();break;case"card-toggle-checkmarks":fcn_isLoggedIn?(fcn_toggleCheckmark(parseInt(a.dataset.storyId),a.dataset.type,parseInt(a.dataset.chapterId),null,a.dataset.mode),fcn_updateCheckmarksView()):_$$$("modal-login-toggle")?.click();break;case"toggle-obfuscation":a.closest("[data-obfuscation-target]").classList.toggle("_obfuscated")}})),fcn_theBody.addEventListener("change",(e=>{const t=e.target.closest('[type="checkbox"]');if(!t)return;const n=t.name,o=n?_$$(`label[for="${n}"]`):[],a=t.checked;t.closest("[aria-checked]")?.setAttribute("aria-checked",a),o.forEach((e=>{e.closest("[aria-checked]")?.setAttribute("aria-checked",a)}))})),_$$(".iframe-consent, .twitter-consent").forEach((e=>{e.onclick=e=>{fcn_loadEmbed(e)}}));var fcn_lastScrollTop=0;function fcn_scrollDirection(){const e="hidden"!==window.getComputedStyle(document.documentElement).overflow?window.scrollY??document.documentElement.scrollTop:fcn_theBody.scrollTop??1;fcn_theBody.classList.toggle("scrolled-to-top",0===e),fcn_theSite.classList.contains("transformed-scroll")||Math.abs(fcn_lastScrollTop-e)>=25&&(fcn_theBody.classList.toggle("scrolling-down",e>fcn_lastScrollTop),fcn_theBody.classList.toggle("scrolling-up",!(e>fcn_lastScrollTop)),fcn_lastScrollTop=Math.max(e,0))}function fcn_observe(e,t,n={}){const o=_$(e);if(!o)return null;new IntersectionObserver((e=>t(e[0])),n).observe(o)}function fcn_dragElement(e){const t=e.querySelector(".drag-anchor")??e;let n,o;function a(t){t.preventDefault(),e.style.top=e.offsetTop-(o-t.clientY)+"px",e.style.left=e.offsetLeft-(n-t.clientX)+"px",n=t.clientX,o=t.clientY}function s(){t.onmouseup=null,t.onmousemove=null}t.onmousedown=function(e){e.preventDefault(),n=e.clientX,o=e.clientY,t.onmousemove=a,t.onmouseup=s}}function fcn_showNotification(e,t=3,n="base"){const o=_$("#notifications"),a=document.createElement("div");a.innerHTML=e,a.classList.add("notifications__message",`_${n}`),a.style.opacity=1,a.style.transitionDelay=`${t}s`,o.prepend(a),a.addEventListener("transitionend",(e=>{o.removeChild(e.target)})),a.addEventListener("click",(e=>{o.removeChild(e.currentTarget)})),setTimeout((()=>{a.style.opacity=0}),100)}if(window.addEventListener("scroll.rAF",fcn_throttle(fcn_scrollDirection,200)),fcn_scrollDirection(),document.addEventListener("DOMContentLoaded",(()=>{fcn_observe(".main-observer",(e=>{fcn_theBody.classList.toggle("is-inside-main",e.intersectionRatio<1&&e.boundingClientRect.top<=0)}),{threshold:[1]}),fcn_observe(".chapter-end",(e=>{fcn_theBody.classList.toggle("is-end-of-chapter",e.isIntersecting||e.boundingClientRect.top<0)}),{root:null,threshold:0}),fcn_observe("#nav-observer-sticky",(e=>{fcn_mainNavigation.classList.toggle("is-sticky",e.intersectionRatio<1)}),{threshold:[1]})})),_$$(".modal__header.drag-anchor").forEach((e=>{fcn_dragElement(e.closest(".modal__wrapper"))})),"oauth_email_taken"===fcn_urlParams.failure&&fcn_showNotification(__("The associated email address is already taken. You can link additional accounts in your profile.","fictioneer"),5,"warning"),"oauth_already_linked"===fcn_urlParams.failure&&fcn_showNotification(__("Account already linked to another profile.","fictioneer"),5,"warning"),"oauth_new"===fcn_urlParams.success&&fcn_showNotification(__("Your account has been successfully linked. Hint: You can change your display name in your profile and link additional accounts.","fictioneer"),10),fcn_urlParams.success?.includes("oauth_merged_")&&fcn_showNotification(__("Account has been successfully linked.","fictioneer"),3,"success"),fcn_urlParams["fictioneer-notice"]&&""!==fcn_urlParams["fictioneer-notice"]){let e="1"===fcn_urlParams.failure?"warning":"base";e="1"===fcn_urlParams.success?"success":e,fcn_showNotification(__(fcn_sanitizeHTML(fcn_urlParams["fictioneer-notice"]),"fictioneer"),3,e)}const fcn_settingMinimal=_$$$("site-setting-minimal"),fcn_settingChapterProgressBar=_$$$("site-setting-chapter-progress-bar"),fcn_settingHueRotateRange=_$$$("site-setting-hue-rotate-range"),fcn_settingHueRotateText=_$$$("site-setting-hue-rotate-text"),fcn_settingHueRotateReset=_$$$("site-setting-hue-rotate-reset"),fcn_settingDarkenRanges=_$$(".setting-darken-range"),fcn_settingDarkenTexts=_$$(".setting-darken-text"),fcn_settingDarkenResets=_$$(".setting-darken-reset"),fcn_settingSaturationRanges=_$$(".setting-saturation-range"),fcn_settingSaturationTexts=_$$(".setting-saturation-text"),fcn_settingSaturationResets=_$$(".setting-saturation-resets"),fcn_settingEvents=["nav-sticky","background-textures","polygons","covers","text-shadows","minimal","chapter-progress-bar"];var fcn_siteSettings=fcn_getSiteSettings();function fcn_updateSiteSetting(e,t,n){e.checked=n,fcn_siteSettings[t]=n,fcn_applySiteSettings(fcn_siteSettings)}function fcn_toggleLightMode(){fcn_setLightMode(!(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault))}function fcn_setLightMode(e,t=!1){localStorage.setItem("fcnLightmode",e),fcn_theRoot.dataset.mode=e?"light":"dark",_$$(".toggle-light-mode").forEach((t=>{t.closest("[aria-checked]")?.setAttribute("aria-checked",e)})),t||fcn_updateThemeColor()}function fcn_updateFontWeight(){const e="default"!=fcn_siteSettings["font-weight"];_$$(".site-setting-font-weight").forEach((e=>{e.value=fcn_siteSettings["font-weight"]})),_$$(".font-weight-reset").forEach((t=>{t.classList.toggle("_modified",e)}))}function fcn_resetFontWeight(){fcn_siteSettings["font-weight"]="default",fcn_theRoot.dataset.fontWeight="default",fcn_applySiteSettings(fcn_siteSettings)}function fcn_updateHueRotate(e){e=fcn_clamp(0,360,e??0),fcn_settingHueRotateText.value=e,fcn_settingHueRotateRange.value=e,fcn_settingHueRotateReset.classList.toggle("_modified",0!=e),fcn_theRoot.style.setProperty("--hue-rotate",`${e}deg + var(--hue-offset)`),fcn_siteSettings["hue-rotate"]=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setHueRotate(){fcn_updateHueRotate(this.value)}function fcn_updateDarken(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.darken),e=Math.round(100*(e+Number.EPSILON))/100,fcn_settingDarkenResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingDarkenRanges.forEach((t=>{t.value=e})),fcn_settingDarkenTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--darken",`(${t} + var(--lightness-offset))`),fcn_siteSettings.darken=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setDarkenFromRange(){fcn_updateDarken(this.value)}function fcn_setDarkenFromText(){"-"!=this.value&&""!=this.value&&fcn_updateDarken((parseInt(this.value)??0)/100)}function fcn_updateSaturation(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.saturation),fcn_settingSaturationResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingSaturationRanges.forEach((t=>{t.value=e})),fcn_settingSaturationTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--saturation",`(${t} + var(--saturation-offset))`),fcn_siteSettings.saturation=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setSaturationFromRange(){fcn_updateSaturation(this.value)}function fcn_setSaturationFromText(){"-"!=this.value&&""!=this.value&&fcn_updateSaturation((parseInt(this.value)??0)/100)}function fcn_defaultSiteSettings(){return{"nav-sticky":!0,"background-textures":!0,polygons:!0,covers:!0,"text-shadows":!1,minimal:!1,"chapter-progress-bar":!0,"site-theme":"default","font-weight":"default",darken:0,saturation:0,"font-saturation":0,"hue-rotate":0}}function fcn_getSiteSettings(){const e=fcn_parseJSON(localStorage.getItem("fcnSiteSettings"))??fcn_defaultSiteSettings();return fcn_setSiteSettings(e),e}function fcn_setSiteSettings(e=null){"object"==typeof(e=e||fcn_siteSettings)&&(fcn_siteSettings=e,localStorage.setItem("fcnSiteSettings",JSON.stringify(e)))}function fcn_applySiteSettings(e){e="object"!=typeof e?fcn_defaultSiteSettings():e,Object.entries(e).forEach((e=>{const t=_$$$(`site-setting-${e[0]}`);switch(t&&(t.checked=e[1]),e[0]){case"minimal":fcn_theRoot.classList.toggle("minimal",e[1]);break;case"darken":fcn_updateDarken();break;case"saturation":fcn_updateSaturation();break;case"font-saturation":break;case"hue-rotate":fcn_updateHueRotate(e[1]);break;case"font-weight":fcn_updateFontWeight();break;default:fcn_theRoot.classList.toggle(`no-${e[0]}`,!e[1])}})),fcn_setSiteSettings(e)}function fcn_updateSiteTheme(e){fcn_siteSettings["site-theme"]=e,fcn_theRoot.dataset.theme=e,_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e),fcn_applySiteSettings(fcn_siteSettings),fcn_updateThemeColor()}function fcn_resetSiteTheme(){fcn_updateSiteTheme("default"),_$$(".site-setting-site-theme").forEach((e=>{e.value="default"}))}function fcn_jumpPage(e){if(fcn_theRoot.dataset.disablePageJump)return;const t=parseInt(window.prompt(_x("Enter page number:","Pagination jump prompt.","fictioneer")));if(t>0){const n=e.nextElementSibling.getAttribute("href"),o=["page=","paged=","comment-page-","pg="];for(const e of o)if(n.includes(e))return void(window.location.href=n.replace(new RegExp(`${e}\\d+`),e+t));window.location.href=n.replace(/page\/\d+/,`page/${t}`)}}fcn_settingEvents.forEach((e=>{_$$$(`site-setting-${e}`)?.addEventListener("change",(t=>{fcn_updateSiteSetting(t.currentTarget,e,t.currentTarget.checked)}))})),fcn_setLightMode(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault,!0),_$$(".toggle-light-mode").forEach((e=>{e.onclick=()=>fcn_toggleLightMode()})),_$$(".font-weight-reset").forEach((e=>{e.addEventListener("click",fcn_resetFontWeight)})),_$$(".site-setting-font-weight").forEach((e=>{e.onchange=e=>{fcn_siteSettings["font-weight"]=e.target.value,fcn_theRoot.dataset.fontWeight=e.target.value,fcn_applySiteSettings(fcn_siteSettings),fcn_updateFontWeight()}})),fcn_settingHueRotateReset?.addEventListener("click",(()=>{fcn_updateHueRotate(0)})),fcn_settingHueRotateRange?.addEventListener("input",fcn_throttle(fcn_setHueRotate,1e3/24)),fcn_settingHueRotateText?.addEventListener("input",fcn_setHueRotate),fcn_settingDarkenResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateDarken(0)}))})),fcn_settingDarkenRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setDarkenFromRange,1e3/24))})),fcn_settingDarkenTexts.forEach((e=>{e.addEventListener("input",fcn_setDarkenFromText)})),fcn_settingSaturationResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateSaturation(0)}))})),fcn_settingSaturationRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setSaturationFromRange,1e3/24))})),fcn_settingSaturationTexts.forEach((e=>{e.addEventListener("input",fcn_setSaturationFromText)})),fcn_applySiteSettings(fcn_siteSettings),_$$(".site-setting-site-theme").forEach((e=>{e.value=fcn_siteSettings.hasOwnProperty("site-theme")?fcn_siteSettings["site-theme"]:"default",_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e.value),e.addEventListener("change",(e=>{fcn_updateSiteTheme(e.target.value)}))})),_$$$("site-setting-theme-reset")?.addEventListener("click",fcn_resetSiteTheme),fcn_updateThemeColor();const fcn_cardLists=_$$(".card-list:not(._no-mutation-observer)");var fcn_cardListMutationObserver=new MutationObserver((e=>{e[0].addedNodes&&("function"==typeof fcn_updateFollowsView&&fcn_updateFollowsView(),"function"==typeof fcn_updateCheckmarksView&&fcn_updateCheckmarksView(),"function"==typeof fcn_updateRemindersView&&fcn_updateRemindersView())}));function fct_spoiler(e){e.classList.toggle("_open")}function fcn_revealCommentImage(e){const t=e.parentElement.querySelector("img");t.src=t.dataset.src,e.remove()}function fcn_contactFormSubmit(e){const t=e.closest("form"),n=new FormData(t),o={action:"fictioneer_ajax_submit_contact_form"};if(t.reportValidity()&&(e.disabled=!0,e.innerHTML=e.dataset.disabled,!(Date.now(){n.success?(t.querySelector("textarea").value="",e.innerHTML=e.dataset.done,fcn_showNotification(n.data.success,3,"success")):n.data.error&&(e.disabled=!1,e.innerHTML=e.dataset.enabled,fcn_showNotification(n.data.error,5,"warning"))})).catch((t=>{t.status&&t.statusText&&(fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),e.disabled=!1,e.innerHTML=e.dataset.enabled)})).then((()=>{t.classList.remove("ajax-in-progress")}))}}fcn_cardLists.length&&fcn_cardLists.forEach((e=>{fcn_cardListMutationObserver.observe(e,{childList:!0,subtree:!0})})),_$$(".chapter-group__name").forEach((e=>{e.addEventListener("click",(e=>{var t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list"),o=!t.classList.contains("_closed");n.style.height=`${n.scrollHeight}px`,setTimeout((()=>{t.classList.toggle("_closed",o)}),10)})),e.closest(".chapter-group").querySelector(".chapter-group__list").addEventListener("transitionend",(e=>{const t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list");n.style.height="",n.querySelectorAll("a, button, label, input:not([hidden])").forEach((e=>{e.tabIndex=t.classList.contains("_closed")?"-1":"0"}))}))})),_$(".fictioneer-comments")?.addEventListener("click",(e=>{e.target?.classList.contains("consent-button")&&fcn_revealCommentImage(e.target)})),_$$(".fcn-contact-form").forEach((e=>{e.querySelector(".fcn-contact-form__submit").addEventListener("click",(e=>{fcn_contactFormSubmit(e.currentTarget)}))})),fcn_theBody.querySelectorAll(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{if(e.currentTarget.checked){const t=e.currentTarget.nextElementSibling.querySelector('[tabindex="0"]');t?.focus(),t?.blur()}else fcn_theBody.classList.contains("user-is-tabbing")&&fcn_theSite.querySelector(`label[for="${e.currentTarget.id}"]`)?.focus()}))})),fcn_theBody.addEventListener("keydown",(e=>{let t=document.activeElement.closest('[tabindex="0"]:not(a, input, button, select)');if(["BUTTON","A","INPUT","SELECT"].includes(document.activeElement.tagName)&&(t=null),t&&(32!=e.keyCode&&13!=e.keyCode||(e.preventDefault(),t.click())),27==e.keyCode){_$$(".modal-toggle:checked").forEach((e=>{e.checked=!1,e.dispatchEvent(new Event("change"))}));const e=_$(".lightbox.show");if(e)return void e.querySelector(".lightbox__close").click();const t=_$(".selected-paragraph #button-close-paragraph-tools");if(t)return void t.click();const n=_$("#tts-interface:not(.hidden)");if(n){if(n.classList.contains("playing")){const e=_$$$("button-tts-pause");e?.click(),e?.focus(),e?.blur()}else _$$$("button-tts-stop").click();return}}}));class FCN_KeywordInput{constructor(e){this.input=e,this.operator=e.closest(".keyword-input").querySelector(".keyword-input__operator input"),this.inputWrapper=e.closest(".keyword-input__input-wrapper"),this.block=e.closest(".keyword-input"),this.form=this.block.closest(".search-form"),this.collection=this.block.querySelector(".keyword-input__collection"),this.suggestionList=this.block.querySelector(".keyword-input__suggestion-list"),this.tabSuggestion=this.block.querySelector(".keyword-input__tab-suggestion"),this.allowText=this.form.querySelector(".allow-list")?.innerText??"{}",this.allowList=JSON.parse(this.allowText),this.hints=this.block.querySelector(".keyword-input__hints"),this.noHint=this.block.querySelector(".keyword-input__no-suggestions"),this.keywords=this.collection.value.length>0?this.collection.value.split(","):[],this.bindEvents(),this.resize(),this.filterSuggestions()}resize(){const e=this.tabSuggestion.innerText.length>0?this.tabSuggestion.innerText.length:this.input.value.length;this.input.style.width=.88*e+2+"ch"}reset(){this.keywords=[],this.block.querySelectorAll(".node").forEach((e=>{e.remove()})),this.block.querySelectorAll(".keyword-input__operator > input").forEach((e=>{e.checked=!1})),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}encode(e){return encodeURIComponent(e.toLowerCase()).replace(/'/g,"%27")}filterSuggestions(){const e=this.input.value.toLowerCase();let t=0,n="";""==e?this.suggestionList.querySelectorAll(".keyword-button").forEach((e=>{e.hidden=!0})):this.suggestionList.querySelectorAll(".keyword-button").forEach((o=>{const a=o.innerText.toLowerCase();a.includes(e)&&this.keywords.indexOf(a)<0?(o.hidden=!1,t++,""==n&&a.startsWith(e)&&(n=a)):o.hidden=!0})),this.hints.querySelectorAll(".keyword-button").forEach((e=>{this.keywords.indexOf(e.value.toLowerCase())>-1?e.hidden=!0:e.hidden=!1})),this.tabSuggestion.innerHTML=n,this.hints.hidden=!(""==e),this.noHint.hidden=!(""!=e&&t<1)}addNode(e=null){const t=e??this.input.value.replace(",",""),n=this.allowList[this.encode(t)];if(!n||this.keywords.indexOf(n)>-1)return;this.keywords.push(n);const o=document.createElement("div");o.innerHTML=`${t}`,o.classList.add("node"),o.dataset.value=n,this.inputWrapper.parentNode.insertBefore(o,this.inputWrapper),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}removeNodeByValue(e){this.block.querySelector(`[data-value="${e}"]`)?.remove(),this.keywords.splice(this.keywords.indexOf(e),1),this.updateCollection(),this.filterSuggestions(),this.resize()}updateCollection(){this.collection.value=this.keywords.join(","),this.block.classList.toggle("_empty",""===this.collection.value),this.form.querySelector(".search-form__current").innerHTML=""}bindEvents(){this.input.addEventListener("input",(e=>{e.currentTarget.value.includes(",")&&this.addNode(),this.block.classList.toggle("_empty",""===e.currentTarget.value),this.filterSuggestions(),this.resize()})),this.input.addEventListener("keydown",(e=>{9!=e.keyCode&&13!=e.keyCode||""!=this.tabSuggestion.innerText&&(e.preventDefault(),this.input.value=this.tabSuggestion.innerText,this.addNode()),27==e.keyCode&&(this.input.value="",this.tabSuggestion.innerHTML="",document.activeElement.blur()),8==e.keyCode&&""==this.input.value&&this.keywords.length>0&&this.removeNodeByValue(this.keywords.slice(-1))})),this.input.addEventListener("blur",(()=>{const e=this.allowList[this.encode(this.input.value)];this.blurTimeout=e?setTimeout((()=>{this.addNode()}),150):setTimeout((()=>{this.input.value="",this.tabSuggestion.innerHTML="",this.filterSuggestions(),this.resize()}),150)})),this.block.addEventListener("click",(e=>{e.target.closest(".node-delete")&&(e.preventDefault(),this.removeNodeByValue(e.target.closest(".node").dataset.value))})),this.block.querySelectorAll(".keyword-button").forEach((e=>{e.addEventListener("click",(e=>{clearTimeout(this.blurTimeout),this.addNode(e.currentTarget.innerText)}))}))}}function fcn_handleTabInput(e){9==e.keyCode&&(fcn_theBody.classList.add("user-is-tabbing"),window.removeEventListener("keydown",fcn_handleTabInput),window.addEventListener("mousedown",fcn_handleMouseInput))}function fcn_handleMouseInput(){fcn_theBody.classList.remove("user-is-tabbing"),window.removeEventListener("mousedown",fcn_handleMouseInput),window.addEventListener("keydown",fcn_handleTabInput)}function fcn_popupPosition(){_$$(".popup-menu-toggle.last-clicked .popup-menu:not(._fixed-position)").forEach((e=>{if("none"===window.getComputedStyle(e).display)return;const t=fcn_detectScreenCollision(e);t&&0===t.length||(t.includes("top")?(e.classList.remove("_top"),e.classList.add("_bottom")):t.includes("bottom")&&(e.classList.remove("_bottom"),e.classList.add("_top")))}))}function fcn_markCurrentMenuItem(){_$$(`.menu-item > [data-nav-object-id="${fcn_theBody.dataset.postId}"]`).forEach((e=>{e.setAttribute("aria-current","page"),e.closest(".menu-item").classList.add("current-menu-item")}))}function fcn_showAgeConfirmationModal(){const e=_$(".story__article, .chapter__article")?.dataset.ageRating;if(!fcn_theRoot.dataset.ageConfirmation&&e&&"adult"!==e)return void _$$$("age-confirmation-modal")?.remove();const t=_$$$("age-confirmation-leave");fcn_theRoot.classList.add("age-modal-open"),_$$$("age-confirmation-modal").classList.add("_open"),_$$$("age-confirmation-confirm")?.addEventListener("click",(e=>{fcn_theRoot.classList.remove("age-modal-open"),e.currentTarget.closest(".modal").remove(),localStorage.setItem("fcnAgeConfirmation","1")})),t?.addEventListener("click",(()=>{window.location.href=t.dataset.redirect??"https://search.brave.com/",localStorage.removeItem("fcnAgeConfirmation")}))}_$$(".search-form").forEach((e=>{const t=[];e.classList.contains("_simple")||(e.querySelectorAll(".keyword-input__input").forEach((e=>{t.push(new FCN_KeywordInput(e))})),e.querySelector(".allow-list")?.remove(),e.addEventListener("change",(t=>{t.target.classList.contains("search-form__advanced-control")||t.target.classList.contains("search-form__string")||(e.querySelector(".search-form__current").innerHTML="")})),e.querySelectorAll(".reset").forEach((n=>{n.addEventListener("click",(o=>{t.forEach((e=>{e.reset()})),e.querySelector("input[name=s]").value="",e.querySelector("select[name=post_type]").value="any",e.querySelector("select[name=sentence]").value="0",e.querySelector("select[name=orderby]").value="modified",e.querySelector("select[name=order]").value="desc",e.querySelector(".search-form__current").innerHTML="",fcn_showNotification(n.dataset.reset,2)}))})))})),_$$(".search-form__advanced-toggle").forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.closest("form");t.dataset.advanced="true"==t.dataset.advanced?"false":"true"}))})),window.addEventListener("keydown",fcn_handleTabInput),window.addEventListener("scroll.rAF",fcn_throttle(fcn_popupPosition,250)),_$$(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{const t=_$$$(e.currentTarget.dataset.target);t.classList.toggle("_open",e.currentTarget.checked);const n=t.querySelector(".close");n?.focus(),n?.blur()}))})),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest("[href]"),n=t?.getAttribute("href");if(!t||"A"===!t.tagName||!n.startsWith("#")||n.length<2||"#respond"===n)return;const o=n.replace("#",""),a=_$$(`[name="${o}"], #${o}`)[0],s=t.closest(".comment._story-comment");s&&(window.location.href=s.querySelector(".fictioneer-comment__link").href+n),a&&(e.preventDefault(),a.scrollIntoView({behavior:"smooth",block:t.dataset?.block??"start"}))})),fcn_markCurrentMenuItem(),_$$$("age-confirmation-modal")&&"1"!==localStorage.getItem("fcnAgeConfirmation")?setTimeout((()=>{fcn_showAgeConfirmationModal()}),2e3):_$$$("age-confirmation-modal")?.remove();
\ No newline at end of file
diff --git a/js/story.min.js b/js/story.min.js
index 98781b37..2f8607a1 100644
--- a/js/story.min.js
+++ b/js/story.min.js
@@ -1 +1 @@
-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){_$$(".story__article ._current").forEach((t=>{t.classList.remove("_current")})),_$$(`[data-finder="${t.dataset.target}"]`).forEach((t=>{t.classList.add("_current")})),_$$$("tabs").dataset.current=t.dataset.target,t.classList.add("_current")}function fcn_loadStoryComments(){let t;_$(".load-more-list-item").remove(),_$(".comments-loading-placeholder").classList.remove("hidden"),fcn_ajaxGet({post_id:fcn_inlineStorage.postId,page:fcn_storyCommentPage},"get_story_comments").then((e=>{e.success?(_$(".fictioneer-comments__list > ul").innerHTML+=e.data.html,fcn_storyCommentPage++):e.data?.error&&(t=fcn_buildErrorNotice(e.data.error))})).catch((e=>{t=fcn_buildErrorNotice(e)})).then((()=>{_$(".comments-loading-placeholder").remove(),t&&_$(".fictioneer-comments__list > ul").appendChild(t)}))}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((r=>{r.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")}))}fcn_applyStorySettings(),_$$$("button-toggle-chapter-order")?.addEventListener("click",(t=>{fcn_storySettings.order="asc"===t.currentTarget.dataset.order?"desc":"asc",fcn_setStorySettings(fcn_storySettings),fcn_applyStorySettings()})),_$$$("button-toggle-chapter-view")?.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()})),_$$('[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))}))}));
\ No newline at end of file
+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){_$$(".story__article ._current").forEach((t=>{t.classList.remove("_current")})),_$$(`[data-finder="${t.dataset.target}"]`).forEach((t=>{t.classList.add("_current")})),_$$$("tabs").dataset.current=t.dataset.target,t.classList.add("_current")}function fcn_loadStoryComments(){let t;_$(".load-more-list-item").remove(),_$(".comments-loading-placeholder").classList.remove("hidden"),fcn_ajaxGet({post_id:fcn_inlineStorage.postId,page:fcn_storyCommentPage},"get_story_comments").then((e=>{e.success?(_$(".fictioneer-comments__list > ul").innerHTML+=e.data.html,fcn_storyCommentPage++):e.data?.error&&(t=fcn_buildErrorNotice(e.data.error))})).catch((e=>{t=fcn_buildErrorNotice(e)})).then((()=>{_$(".comments-loading-placeholder").remove(),t&&_$(".fictioneer-comments__list > ul").appendChild(t)}))}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((r=>{r.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")}))}fcn_applyStorySettings(),_$$$("button-toggle-chapter-order")?.addEventListener("click",(t=>{fcn_storySettings.order="asc"===t.currentTarget.dataset.order?"desc":"asc",fcn_setStorySettings(fcn_storySettings),fcn_applyStorySettings()})),_$$$("button-toggle-chapter-view")?.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()})),_$$('[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))}))}));
\ No newline at end of file
diff --git a/src/js/admin.js b/src/js/admin.js
index dc0ebedd..dae4f907 100644
--- a/src/js/admin.js
+++ b/src/js/admin.js
@@ -460,8 +460,8 @@ function fcn_ebookMediaUpload(event) {
// Open media modal
var uploader = wp.media({
multiple: false,
- library : {
- type : ['application/pdf', 'text/plain', 'application/rtf', 'application/x-mobipocket-ebook', 'application/epub+zip']
+ library: {
+ type: ['application/pdf', 'text/plain', 'application/rtf', 'application/x-mobipocket-ebook', 'application/epub+zip']
}
})
.open()
@@ -473,10 +473,11 @@ function fcn_ebookMediaUpload(event) {
metabox.querySelector('[data-target*="size"]').textContent = attachment.filesizeHumanReadable;
metabox.querySelector('[data-target*="filename"]').textContent = attachment.filename;
metabox.querySelector('[data-target*="filename"]').href = attachment.url;
+
metabox.querySelector('[data-target*="upload"]').classList.add('hidden');
- metabox.querySelector('[data-target*="replace"]').classList.remove('hidden');
- metabox.querySelector('[data-target*="remove"]').classList.remove('hidden');
- metabox.querySelector('[data-target*="display"]').classList.remove('hidden');
+
+ metabox.querySelectorAll('[data-target*="replace"], [data-target*="remove"], [data-target*="display"]')
+ .forEach(el => el.classList.remove('hidden'));
});
}
@@ -503,10 +504,11 @@ function fcn_ebookMediaRemove(event) {
metabox.querySelector('[data-target*="size"]').textContent = '';
metabox.querySelector('[data-target*="filename"]').textContent = '';
metabox.querySelector('[data-target*="filename"]').href = '';
+
metabox.querySelector('[data-target*="upload"]').classList.remove('hidden');
- metabox.querySelector('[data-target*="replace"]').classList.add('hidden');
- metabox.querySelector('[data-target*="remove"]').classList.add('hidden');
- metabox.querySelector('[data-target*="display"]').classList.add('hidden');
+
+ metabox.querySelectorAll('[data-target*="replace"], [data-target*="remove"], [data-target*="display"]')
+ .forEach(el => el.classList.add('hidden'));
}
// Listen for clicks on upload and replace
diff --git a/src/js/application.js b/src/js/application.js
index 02ff12ad..5c93cc6a 100644
--- a/src/js/application.js
+++ b/src/js/application.js
@@ -59,28 +59,25 @@ if (typeof fcn_removeQueryArgs === 'function') {
*/
function fcn_cleanupWebStorage(keepGuestData = false) {
- localStorage.removeItem('fcnProfileAvatar');
- localStorage.removeItem('fcnBookshelfContent');
+ const localItems = ['fcnProfileAvatar', 'fcnBookshelfContent'];
if (!keepGuestData) {
- localStorage.removeItem('fcnChapterBookmarks');
+ localItems.push('fcnChapterBookmarks');
}
- // Clean up user data
+ // Remove local data
+ localItems.forEach(item => localStorage.removeItem(item));
+
+ // Remove user data (if any)
+ const userDataKeys = ['loggedIn', 'follows', 'reminders', 'checkmarks', 'bookmarks', 'fingerprint'];
const userData = fcn_parseJSON(localStorage.getItem('fcnUserData'));
if (userData) {
- userData['loggedIn'] = false;
- userData['follows'] = false;
- userData['reminders'] = false;
- userData['checkmarks'] = false;
- userData['bookmarks'] = false;
- userData['fingerprint'] = false;
-
+ userDataKeys.forEach(key => userData[key] = false);
localStorage.setItem('fcnUserData', JSON.stringify(userData));
}
- // Clean up private authentication data
+ // Remove private authentication data
const auth = fcn_parseJSON(localStorage.getItem('fcnAuth'));
if (auth?.loggedIn) {
@@ -294,22 +291,22 @@ function fcn_setLoggedInState(state) {
// Cleanup view for users
if (!state.isAdmin) {
- _$$('.only-admins').forEach(element => { element.remove() });
+ _$$('.only-admins').forEach(el => el.remove());
}
if (!state.isModerator && !state.isAdmin) {
- _$$('.only-moderators').forEach(element => { element.remove() });
+ _$$('.only-moderators').forEach(el => el.remove());
}
if (!state.isAuthor && !state.isAdmin) {
- _$$('.only-authors').forEach(element => { element.remove() });
+ _$$('.only-authors').forEach(el => el.remove());
}
if (!state.isModerator && !state.isAdmin) {
- _$$('.only-editors').forEach(element => { element.remove() });
+ _$$('.only-editors').forEach(el => el.remove());
}
- _$$('label[for="modal-login-toggle"], #modal-login-toggle, #login-modal').forEach(element => { element.remove() });
+ _$$('label[for="modal-login-toggle"], #modal-login-toggle, #login-modal').forEach(el => el.remove());
// Initialize local user
fcn_getProfileImage();
@@ -566,41 +563,41 @@ fcn_scrollDirection();
// OBSERVERS
// =============================================================================
-// Main observer
-const /** @const {IntersectionObserver} */ fcn_mainObserver = new IntersectionObserver(
- ([e]) => {
- fcn_theBody.classList.toggle('is-inside-main', e.intersectionRatio < 1 && e.boundingClientRect.top <= 0);
- },
- { threshold: [1] }
-);
+/**
+ * Create and initialize an IntersectionObserver.
+ *
+ * @param {String} selector - Selector for the element to be observed.
+ * @param {Function} callback - Callback for the IntersectionObserver.
+ * @param {Object} options - Options for the IntersectionObserver.
+ */
+function fcn_observe(selector, callback, options = {}) {
+ const element = _$(selector);
-// End of chapter observer
-const /** @const {IntersectionObserver} */ fcn_endOfChapterObserver = new IntersectionObserver(
- ([e]) => {
- fcn_theBody.classList.toggle('is-end-of-chapter', e.isIntersecting || e.boundingClientRect.top < 0)
- }, { root: null, threshold: 0 }
-);
+ if (!element) {
+ return null;
+ }
-// Sticky navigation observer
-const /** @const {IntersectionObserver} */ fct_navStickyObserver = new IntersectionObserver(
- ([e]) => {
- fcn_mainNavigation.classList.toggle('is-sticky', e.intersectionRatio < 1);
- }, { threshold: [1] }
-);
+ const observer = new IntersectionObserver(entries => callback(entries[0]), options);
+ observer.observe(element);
+}
-// Apply observers
document.addEventListener('DOMContentLoaded', () => {
- if (_$('.main-observer')) {
- fcn_mainObserver.observe(_$('.main-observer'));
- }
+ const mainObserverCallback = e => {
+ fcn_theBody.classList.toggle('is-inside-main', e.intersectionRatio < 1 && e.boundingClientRect.top <= 0);
+ };
- if (_$('.chapter-end')) {
- fcn_endOfChapterObserver.observe(_$('.chapter-end'));
- }
+ const endOfChapterCallback = e => {
+ fcn_theBody.classList.toggle('is-end-of-chapter', e.isIntersecting || e.boundingClientRect.top < 0);
+ };
- if (_$$$('nav-observer-sticky')) {
- fct_navStickyObserver.observe(_$$$('nav-observer-sticky'));
- }
+ const navStickyCallback = e => {
+ fcn_mainNavigation.classList.toggle('is-sticky', e.intersectionRatio < 1);
+ };
+
+ // Initialize observers
+ fcn_observe('.main-observer', mainObserverCallback, { threshold: [1] });
+ fcn_observe('.chapter-end', endOfChapterCallback, { root: null, threshold: 0 });
+ fcn_observe('#nav-observer-sticky', navStickyCallback, { threshold: [1] });
});
// =============================================================================
diff --git a/src/js/story.js b/src/js/story.js
index 48e0cf5a..78fa22e0 100644
--- a/src/js/story.js
+++ b/src/js/story.js
@@ -143,7 +143,7 @@ _$$('.chapter-group__folding-toggle').forEach(element => {
// =============================================================================
/**
- * Toggles the active story tab
+ * Toggles the active story tab.
*
* @since 5.4.0
*
@@ -152,7 +152,7 @@ _$$('.chapter-group__folding-toggle').forEach(element => {
function fcn_toggleStoryTab(target) {
// Clear previous tab
- _$$('.story__article ._current').forEach(item => {
+ _$$('.story__article ._current').forEach(item => {
item.classList.remove('_current');
});
diff --git a/src/js/tts.js b/src/js/tts.js
index 0348ce28..aa4cd63f 100644
--- a/src/js/tts.js
+++ b/src/js/tts.js
@@ -264,7 +264,11 @@ function fcn_readTextStack() {
// End of stack reached
if (fcn_ttsStack.length === 0) {
fcn_ttsInterface.classList.add('ended');
- if (current) current.classList.remove('current-reading');
+
+ if (current) {
+ current.classList.remove('current-reading');
+ }
+
fcn_currentReadingId = -1;
fcn_ttsCurrentText = '';
return;
@@ -277,7 +281,11 @@ function fcn_readTextStack() {
if (fcn_currentReadingId != item[0]) {
fcn_currentReadingId = item[0];
- if (current) current.classList.remove('current-reading');
+
+ if (current) {
+ current.classList.remove('current-reading');
+ }
+
_$$$(fcn_currentReadingId).classList.add('current-reading');
}