fictioneer/js/complete.min.js

6 lines
133 KiB
JavaScript

const _$=document.querySelector.bind(document),_$$=document.querySelectorAll.bind(document),_$$$=document.getElementById.bind(document);async function fcn_ajaxPost(t={},e=null,n={}){e&&!e.startsWith("http")&&(e=fictioneer_ajax.rest_url+e),e=e||fictioneer_ajax.ajax_url;let a={"Content-Type":"application/x-www-form-urlencoded","Cache-Control":"no-cache"};a={...a,...n},t={nonce:fcn_getNonce(),...t};const o=await fetch(e,{method:"POST",credentials:"same-origin",headers:a,mode:"same-origin",body:new URLSearchParams(t)});return o.ok?o.json():Promise.reject(o)}async function fcn_ajaxGet(t={},e=null,n={}){e&&!e.startsWith("http")&&(e=fictioneer_ajax.rest_url+e),e=e||fictioneer_ajax.ajax_url,e=fcn_buildUrl(t={nonce:fcn_getNonce(),...t},e);let a={"Content-Type":"application/x-www-form-urlencoded","Cache-Control":"no-cache"};a={...a,...n};const o=await fetch(e,{method:"GET",credentials:"same-origin",headers:a,mode:"same-origin"});return o.ok?o.json():Promise.reject(o)}function fcn_evaluateAsBoolean(t,e=!1){if(void 0===t)return e;if("boolean"==typeof t)return t;if(t instanceof HTMLInputElement&&"checkbox"===t.getAttribute("type"))return t.checked;t instanceof HTMLElement&&(t.hasAttribute("value")?t=t.value:t.hasAttribute("data-value")&&(t=t.dataset.value));const n=String(t),a=parseInt(t);return"true"===n||"1"===n||1===a||"false"!==n&&"0"!==n&&0!==a&&e}function fcn_copyToClipboard(t,e=!1){e=e||fictioneer_tl.notification.copiedToClipboard,navigator.clipboard&&(navigator.clipboard.writeText(t),e&&fcn_showNotification(e,2))}function fcn_parseJSON(t){if(null==t||"string"!=typeof t)return null;try{return JSON.parse(t)}catch(t){return null}}function fcn_removeItemOnce(t,e){var n=t.indexOf(e);return n>-1&&t.splice(n,1),t}function fcn_clamp(t,e,n){return Math.min(Math.max(n,t),e)}function fcn_updateThemeColor(t=!1){const e=fcn_siteSettings.darken?fcn_siteSettings.darken:0,n=fcn_siteSettings.saturation?fcn_siteSettings.saturation:0,a=fcn_siteSettings["hue-rotate"]?fcn_siteSettings["hue-rotate"]:0,o=e>=0?1+e**2:1-e**2,c=n>=0?1+n**2:1-n**2;let s=getComputedStyle(document.documentElement).getPropertyValue("--theme-color-base").trim().split(" ");s=`hsl(${(parseInt(s[0])+a)%360}deg ${(parseInt(s[1])*c).toFixed(2)}% ${(parseInt(s[2])*o).toFixed(2)}%)`,_$("meta[name=theme-color]").setAttribute("content",t||s)}function fcn_offset(t){const e=t.getBoundingClientRect();return{top:e.top+window.scrollY,left:e.left+window.scrollX}}function fcn_throttle(t,e,n){var a,o,c,s=null,i=0;n||(n={});var r=function(){i=!1===n.leading?0:Date.now(),s=null,c=t.apply(a,o),s||(a=o=null)};return function(){var l=Date.now();i||!1!==n.leading||(i=l);var f=e-(l-i);return a=this,o=arguments,f<=0||f>e?(s&&(clearTimeout(s),s=null),i=l,c=t.apply(a,o),s||(a=o=null)):s||!1===n.trailing||(s=setTimeout(r,f)),c}}var fcn_lastClicked,fcn_animFrameEvents=new Map;function fcn_bindEventToAnimationFrame(t,e,n=window){n.addEventListener(t,(function(){fcn_animFrameEvents.get(e)||(fcn_animFrameEvents.set(e,!0),requestAnimationFrame((()=>{n.dispatchEvent(new CustomEvent(e)),fcn_animFrameEvents.set(e,!1)})))}))}function fcn_toggleLastClicked(t){const e=!t.classList.contains("last-clicked");t.classList.toggle("last-clicked",e),t.closest(".watch-last-clicked")?.classList.toggle("has-last-clicked",e),fcn_lastClicked&&fcn_lastClicked!=t&&fcn_removeLastClick(fcn_lastClicked),fcn_lastClicked=t}function fcn_removeLastClick(t){t.closest(".watch-last-clicked")?.classList.remove("has-last-clicked"),t.classList.remove("last-clicked"),fcn_lastClicked=null}function fcn_cleanTextSelectionFromButtons(t){return t=(t=(t=(t=(t=(t=t.replace(/[\r\n]{2,}/g,"__$__")).replace(new RegExp("(__Bookmark|__Quote|__Link)","g"),"")).replace(new RegExp("(__Bookmark|__Quote|__TTS|__Link)","g"),"")).replace(new RegExp("(__Bookmark|__Quote|__Suggestion|__TTS|__Link)","g"),"")).replace(new RegExp("(__Bookmark|__Quote|__Suggestion|__Link)","g"),"")).replace(/[__$]{1,}/g,"\n\n").replace(/^[\r\n]+|[\r\n]+$/g,"")}function fcn_deleteCookie(t){document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"}function fcn_deleteAllCookies(){localStorage.clear(),document.cookie.split(";").forEach((t=>{document.cookie=t.replace(/^ +/,"").replace(/=.*/,"=;expires="+(new Date).toUTCString()+";path=/")}))}function fcn_setCookie(t,e,n=30){const a=new Date;a.setTime(a.getTime()+24*n*60*60*1e3);const o="expires="+a.toUTCString();document.cookie=t+"="+encodeURIComponent(e)+";"+o+";SameSite=Strict;path=/"}function fcn_getCookie(t){const e=t+"=",n=document.cookie.split(";");for(var a=0;a<n.length;a++){const t=n[a].trim();if(0==t.indexOf(e))return decodeURIComponent(t.substring(e.length,t.length))}return null}function fcn_isValidUrl(t){return!!t&&null!=t.match(/^(https?:\/\/)/)}function fcn_getNonce(){return _$$$("fictioneer-ajax-nonce")?.value??_$$$("general-fictioneer-nonce")?.value??_$('[name="fictioneer_nonce"]')?.value??0}function fcn_matchFingerprint(t){const e=fcn_getUserData().fingerprint;return!!e&&e===t}function fcn_buildUrl(t={},e=null){return e=e?new URL(e):new URL(window.location.protocol+"//"+window.location.host+window.location.pathname),t&&Object.keys(t).forEach((n=>{e.searchParams.append(n,t[n])})),e}function fcn_buildErrorNotice(t,e=!1,n=!0){console.error("Error Message",t);const a=document.createElement("div");let o=t;return e&&(a.id=e),a.classList="notice _warning","object"==typeof t&&(o="",t.status&&(o=`${t.status}: `),t.statusText&&(o+=t.statusText),o||(o="Unknown error.")),a.innerHTML=`<i class="fa-solid fa-triangle-exclamation"></i><div>${n?fcn_sanitizeHTML(o):o}</div>`,a}function fcn_sanitizeHTML(t){const e=document.createElement("div");return e.innerText=t instanceof HTMLElement?t.innerHTML:t,e.innerHTML}function fcn_detectScreenCollision(t){const e=t.getBoundingClientRect(),n=window.innerHeight??document.documentElement.clientHeight,a=window.innerWidth??document.documentElement.clientWidth,o=(t.closest(".popup-menu-toggle")?.clientHeight??32)+16,c=n-e.bottom,s=[];return e.top<=50&&c>50+o&&s.push("top"),e.bottom>=n-50&&e.top>50+o&&s.push("bottom"),e.left<=10&&s.push("left"),e.right>=a-10&&s.push("right"),s}function fcn_scrollTo(t,e=64){window.scrollTo({top:t.getBoundingClientRect().top+window.scrollY-e,behavior:"smooth"})}function fcn_html(...t){const e=document.createElement("template");return e.innerHTML=String.raw(...t).trim(),e.content.firstChild}function fcn_splitList(t,e=","){if(!t||""===t.trim())return[];let n=t.replace(/\r?\n|\r/g,"").split(e);return n=n.map((t=>t.trim())).filter((t=>t.length>0)),n}function fcn_isSearchEngineCrawler(){const t=navigator.userAgent.toLowerCase();return["googlebot","bingbot","slurp","duckduckbot","baiduspider","yandexbot","sogou","exabot","facebot","ia_archiver"].some((e=>t.includes(e)))}_$("body").addEventListener("click",(t=>{!["BUTTON","A"].includes(t.target.tagName)&&t.target.closest(".toggle-last-clicked")||null!==t.target.closest(".escape-last-click")||fcn_lastClicked&&t.currentTarget!=fcn_lastClicked&&fcn_removeLastClick(fcn_lastClicked)})),_$("body").addEventListener("keydown",(t=>{27==t.keyCode&&fcn_lastClicked&&(fcn_removeLastClick(fcn_lastClicked),document.activeElement?.blur())}));const fcn_theSite=_$$$("site"),fcn_theBody=_$("body"),fcn_theRoot=document.documentElement,fcn_inlineStorage=_$$$("inline-storage").dataset,fcn_urlParams=Object.fromEntries(new URLSearchParams(window.location.search).entries()),fcn_pageLoadTimestamp=Date.now(),fcn_ajaxLimitThreshold=Date.now()-parseInt(fictioneer_ajax.ttl);var fcn_isLoggedIn=fcn_theBody.classList.contains("logged-in"),fcn_chapterList=_$("#story-chapter-list > ul");function fcn_cleanupWebStorage(t=!1){const e=["fcnProfileAvatar","fcnBookshelfContent"];t||e.push("fcnChapterBookmarks"),e.forEach((t=>localStorage.removeItem(t)));const n=["loggedIn","follows","reminders","checkmarks","bookmarks","fingerprint"],a=fcn_parseJSON(localStorage.getItem("fcnUserData"));a&&(n.forEach((t=>a[t]=!1)),localStorage.setItem("fcnUserData",JSON.stringify(a)));const o=fcn_parseJSON(localStorage.getItem("fcnAuth"));o?.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((t=>{t.remove()}))}function fcn_ajaxAuth(){let t=!1,e=fcn_parseJSON(localStorage.getItem("fcnAuth"))??!1;if(fcn_isLoggedIn&&!e?.loggedIn&&(localStorage.removeItem("fcnAuth"),e=!1),e){fcn_addNonceHTML(e.nonceHtml);const n=new CustomEvent("fcnAuthReady",{detail:{nonceHtml:e.nonceHtml,nonce:e.nonce,loggedIn:e.loggedIn,isAdmin:e.isAdmin,isModerator:e.isModerator,isAuthor:e.isAuthor,isEditor:e.isEditor},bubbles:!0,cancelable:!1});if(document.dispatchEvent(n),t=!0,fcn_ajaxLimitThreshold<e.lastLoaded)return}fcn_ajaxGet({action:"fictioneer_ajax_get_auth",fcn_fast_ajax:1}).then((e=>{if(e.success){fcn_addNonceHTML(e.data.nonceHtml);const n={lastLoaded:Date.now(),nonceHtml:e.data.nonceHtml,nonce:e.data.nonce,loggedIn:e.data.loggedIn,isAdmin:e.data.isAdmin,isModerator:e.data.isModerator,isAuthor:e.data.isAuthor,isEditor:e.data.isEditor};if(!t){const t=new CustomEvent("fcnAuthReady",{detail:n,bubbles:!0,cancelable:!1});document.dispatchEvent(t)}localStorage.setItem("fcnAuth",JSON.stringify(n))}else{fcn_cleanupGuestView();const t=new Event("fcnAuthFailed");document.dispatchEvent(t)}})).catch((()=>{localStorage.removeItem("fcnAuth"),fcn_cleanupGuestView();const t=new Event("fcnAuthError");document.dispatchEvent(t)}))}function fcn_addNonceHTML(t){_$$$("fictioneer-ajax-nonce")?.remove(),fcn_theBody.appendChild(fcn_html`${t}`)}function fcn_setLoggedInState(t){fcn_isLoggedIn=t.loggedIn,fcn_theBody.classList.add("logged-in"),fcn_theBody.classList.toggle("is-admin",t.isAdmin),fcn_theBody.classList.toggle("is-moderator",t.isModerator),fcn_theBody.classList.toggle("is-author",t.isAuthor),fcn_theBody.classList.toggle("is-editor",t.isEditor);const e=['label[for="modal-login-toggle"]',"#modal-login-toggle","#login-modal"];t.isAdmin||(e.push(".only-admins"),t.isModerator||e.push(".only-moderators"),t.isAuthor||e.push(".only-authors"),t.isEditor||e.push(".only-editors")),_$$(e.join(", ")).forEach((t=>t.remove())),fcn_getProfileImage(),fcn_fetchUserData()}function fcn_loadEmbed(t){t.target.parentNode.querySelectorAll("iframe, script")[0].src=t.target.dataset.src,t.target.parentElement.querySelector(".embed-logo")?.remove(),t.target.remove()}function fcn_appendTermMenu(t,e){const n=_$$$(`term-submenu-${t}`);if(!n)return;const a=n.content.cloneNode(!0);e.classList.add("menu-item-has-children"),e.querySelector('[href="#"]').addEventListener("click",(t=>{t.preventDefault()})),e.appendChild(a)}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((t=>{t.addEventListener("click",(()=>{fcn_prepareLogin()}))})),document.addEventListener("DOMContentLoaded",(()=>{fcn_theRoot.dataset.ajaxAuth&&fcn_ajaxAuth()})),!fcn_isLoggedIn&&fcn_theRoot.dataset.ajaxAuth&&document.addEventListener("fcnAuthReady",(t=>{t.detail.loggedIn?fcn_setLoggedInState(t.detail):(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView())})),fcn_bindEventToAnimationFrame("scroll","scroll.rAF"),fcn_bindEventToAnimationFrame("resize","resize.rAF"),fcn_theBody.addEventListener("click",(t=>{const e=t.target.closest(".toggle-last-clicked");if(e&&(!["BUTTON","A","INPUT","SELECT"].includes(t.target.tagName)||t.target.classList.contains("toggle-last-clicked")))return fcn_toggleLastClicked?.(e),fcn_popupPosition?.(),void t.stopPropagation();const n=t.target.closest(".page-numbers.dots:not(button)");if(n)return void fcn_jumpPage(n);const a=t.target.closest(".spoiler");if(a)return void a.classList.toggle("_open");t.target.closest(".oauth-login-link, .subscriber-login, [data-prepare-login]")&&fcn_prepareLogin();const o=t.target.closest("[data-click]"),c=o?.dataset.click;if(c)switch(c){case"copy-to-clipboard":o.select(),fcn_copyToClipboard(o.value,o.dataset.message);break;case"reset-consent":fcn_deleteCookie("fcn_cookie_consent"),location.reload();break;case"clear-cookies":fcn_deleteAllCookies(),alert(o.dataset.message);break;case"logout":fcn_cleanupWebStorage();break;case"card-toggle-follow":fcn_isLoggedIn?fcn_toggleFollow(o.dataset.storyId):_$$$("modal-login-toggle")?.click();break;case"card-toggle-reminder":fcn_isLoggedIn?fcn_toggleReminder(o.dataset.storyId):_$$$("modal-login-toggle")?.click();break;case"card-toggle-checkmarks":fcn_isLoggedIn?(fcn_toggleCheckmark(parseInt(o.dataset.storyId),o.dataset.type,parseInt(o.dataset.chapterId),null,o.dataset.mode),fcn_updateCheckmarksView()):_$$$("modal-login-toggle")?.click();break;case"toggle-obfuscation":o.closest("[data-obfuscation-target]").classList.toggle("_obfuscated")}})),fcn_theBody.addEventListener("change",(t=>{const e=t.target.closest('[type="checkbox"]');if(!e)return;const n=e.name,a=n?_$$(`label[for="${n}"]`):[],o=e.checked;e.closest("[aria-checked]")?.setAttribute("aria-checked",o),a.forEach((t=>{t.closest("[aria-checked]")?.setAttribute("aria-checked",o)}))})),_$$(".iframe-consent, .twitter-consent").forEach((t=>{t.onclick=t=>{fcn_loadEmbed(t)}})),document.addEventListener("DOMContentLoaded",(()=>{const t=_$("#menu-navigation > .menu-item"),e=_$$$("full-navigation");t&&e&&t.offsetHeight<e.offsetHeight&&e.classList.add("_oversized-navigation"),_$$(".main-navigation .trigger-term-menu-categories").forEach((t=>{fcn_appendTermMenu("category",t)})),_$$(".main-navigation .trigger-term-menu-tags").forEach((t=>{fcn_appendTermMenu("post_tag",t)})),_$$(".main-navigation .trigger-term-menu-genres").forEach((t=>{fcn_appendTermMenu("fcn_genre",t)})),_$$(".main-navigation .trigger-term-menu-fandoms").forEach((t=>{fcn_appendTermMenu("fcn_fandom",t)})),_$$(".main-navigation .trigger-term-menu-characters").forEach((t=>{fcn_appendTermMenu("fcn_character",t)})),_$$(".main-navigation .trigger-term-menu-warnings").forEach((t=>{fcn_appendTermMenu("fcn_content_warning",t)}))}));var fcn_lastScrollTop=0;function fcn_scrollDirection(){if(fcn_theSite.classList.contains("transformed-scroll"))return;const t="hidden"!==window.getComputedStyle(document.documentElement).overflow?window.scrollY??document.documentElement.scrollTop:fcn_theBody.scrollTop??1;fcn_theBody.classList.toggle("scrolled-to-top",0===t),Math.abs(fcn_lastScrollTop-t)>=25&&(fcn_theBody.classList.toggle("scrolling-down",t>fcn_lastScrollTop),fcn_theBody.classList.toggle("scrolling-up",!(t>fcn_lastScrollTop)),fcn_lastScrollTop=Math.max(t,0))}function fcn_observe(t,e,n={}){const a=_$(t);if(!a)return null;new IntersectionObserver((t=>e(t[0])),n).observe(a)}function fcn_dragElement(t){const e=t.querySelector(".drag-anchor")??t;let n,a;function o(e){e.preventDefault(),t.style.top=t.offsetTop-(a-e.clientY)+"px",t.style.left=t.offsetLeft-(n-e.clientX)+"px",n=e.clientX,a=e.clientY}function c(){e.onmouseup=null,e.onmousemove=null}e.onmousedown=function(t){t.preventDefault(),n=t.clientX,a=t.clientY,e.onmousemove=o,e.onmouseup=c}}function fcn_showNotification(t,e=3,n="base"){const a=_$("#notifications"),o=document.createElement("div");o.innerHTML=t,o.classList.add("notifications__message",`_${n}`),o.style.opacity=1,o.style.transitionDelay=`${e}s`,a.prepend(o),o.addEventListener("transitionend",(t=>{"opacity"===t.propertyName&&a.removeChild(t.target)})),o.addEventListener("click",(t=>{a.removeChild(t.currentTarget)})),setTimeout((()=>{o.style.opacity=0}),100)}if(window.addEventListener("scroll.rAF",fcn_throttle(fcn_scrollDirection,200)),fcn_scrollDirection(),document.addEventListener("DOMContentLoaded",(()=>{fcn_observe(".main-observer",(t=>{fcn_theBody.classList.toggle("is-inside-main",t.intersectionRatio<1&&t.boundingClientRect.top<=0)}),{threshold:[1]}),fcn_observe(".chapter-end",(t=>{fcn_theBody.classList.toggle("is-end-of-chapter",t.isIntersecting||t.boundingClientRect.top<0)}),{root:null,threshold:0}),fcn_observe("#nav-observer-sticky",(t=>{_$$$("full-navigation").classList.toggle("is-sticky",t.intersectionRatio<1)}),{threshold:[1]})})),_$$(".modal__header.drag-anchor").forEach((t=>{fcn_dragElement(t.closest(".modal__wrapper"))})),fcn_urlParams){switch(fcn_urlParams.failure&&console.error("Failure:",fcn_urlParams.failure),fcn_urlParams.failure){case"oauth_email_taken":fcn_showNotification(fictioneer_tl.notification.oauthEmailTaken,5,"warning");break;case"oauth_already_linked":fcn_showNotification(fictioneer_tl.notification.oauthAccountAlreadyLinked,5,"warning")}if("oauth_new"===fcn_urlParams.success)fcn_showNotification(fictioneer_tl.notification.oauthNew,10);else fcn_urlParams.success?.startsWith("oauth_merged_")&&fcn_showNotification(fictioneer_tl.notification.oauthAccountLinked,3,"success");if(fcn_urlParams["fictioneer-notice"]){let t="1"===fcn_urlParams.failure?"warning":"base";t="1"===fcn_urlParams.success?"success":t,fcn_showNotification(fcn_sanitizeHTML(fcn_urlParams["fictioneer-notice"]),3,t)}}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-reset"),fcn_settingFontLightnessRanges=_$$(".setting-font-lightness-range"),fcn_settingFontLightnessTexts=_$$(".setting-font-lightness-text"),fcn_settingFontLightnessResets=_$$(".setting-font-lightness-reset"),fcn_settingEvents=["nav-sticky","background-textures","polygons","covers","text-shadows","minimal","chapter-progress-bar"];var fcn_siteSettings=fcn_getSiteSettings();function fcn_updateSiteSetting(t,e,n){t.checked=n,fcn_siteSettings[e]=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(t,e=!1){localStorage.setItem("fcnLightmode",t),fcn_theRoot.dataset.mode=t?"light":"dark",_$$(".toggle-light-mode").forEach((e=>{e.closest("[aria-checked]")?.setAttribute("aria-checked",t)})),e||fcn_updateThemeColor()}function fcn_updateFontWeight(){const t="default"!=fcn_siteSettings["font-weight"];_$$(".site-setting-font-weight").forEach((t=>{t.value=fcn_siteSettings["font-weight"]})),_$$(".font-weight-reset").forEach((e=>{e.classList.toggle("_modified",t)}))}function fcn_resetFontWeight(){fcn_siteSettings["font-weight"]="default",fcn_theRoot.dataset.fontWeight="default",fcn_applySiteSettings(fcn_siteSettings)}function fcn_updateHueRotate(t){t=fcn_clamp(0,360,t??0),fcn_settingHueRotateText.value=t,fcn_settingHueRotateRange.value=t,fcn_settingHueRotateReset.classList.toggle("_modified",0!=t),fcn_theRoot.style.setProperty("--hue-rotate",`(${t}deg + var(--hue-offset))`),fcn_siteSettings["hue-rotate"]=t,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setHueRotate(){fcn_updateHueRotate(this.value)}function fcn_updateDarken(t=null){t=fcn_clamp(-1,1,t??fcn_siteSettings.darken),t=Math.round(100*(t+Number.EPSILON))/100,fcn_settingDarkenResets.forEach((e=>{e.classList.toggle("_modified",0!=t)})),fcn_settingDarkenRanges.forEach((e=>{e.value=t})),fcn_settingDarkenTexts.forEach((e=>{e.value=parseInt(100*t)}));const e=t>=0?1+t**2:1-t**2;fcn_theRoot.style.setProperty("--darken",`(${e} + var(--lightness-offset))`),fcn_siteSettings.darken=t,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(t=null){t=fcn_clamp(-1,1,t??fcn_siteSettings.saturation),fcn_settingSaturationResets.forEach((e=>{e.classList.toggle("_modified",0!=t)})),fcn_settingSaturationRanges.forEach((e=>{e.value=t})),fcn_settingSaturationTexts.forEach((e=>{e.value=parseInt(100*t)}));const e=t>=0?1+t**2:1-t**2;fcn_theRoot.style.setProperty("--saturation",`(${e} + var(--saturation-offset))`),fcn_siteSettings.saturation=t,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_updateFontLightness(t=null){t=fcn_clamp(-1,1,t??fcn_siteSettings["font-lightness"]??1),fcn_settingFontLightnessResets.forEach((e=>{e.classList.toggle("_modified",0!=t)})),fcn_settingFontLightnessRanges.forEach((e=>{e.value=t})),fcn_settingFontLightnessTexts.forEach((e=>{e.value=parseInt(100*t)}));const e=t>=0?1+t**2:1-t**2;fcn_theRoot.style.setProperty("--font-lightness",`(${e} + var(--font-lightness-offset))`),fcn_siteSettings["font-lightness"]=t,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setFontLightnessFromRange(){fcn_updateFontLightness(this.value)}function fcn_setFontLightnessFromText(){"-"!=this.value&&""!=this.value&&fcn_updateFontLightness((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,"font-lightness":0,"hue-rotate":0}}function fcn_getSiteSettings(){const t=fcn_parseJSON(localStorage.getItem("fcnSiteSettings"))??fcn_defaultSiteSettings();return fcn_setSiteSettings(t),t}function fcn_setSiteSettings(t=null){"object"==typeof(t=t||fcn_siteSettings)&&(fcn_siteSettings=t,localStorage.setItem("fcnSiteSettings",JSON.stringify(t)))}function fcn_applySiteSettings(t){t="object"!=typeof t?fcn_defaultSiteSettings():t,Object.entries(t).forEach((t=>{const e=_$$$(`site-setting-${t[0]}`);switch(e&&(e.checked=t[1]),t[0]){case"minimal":fcn_theRoot.classList.toggle("minimal",t[1]);break;case"darken":fcn_updateDarken();break;case"saturation":fcn_updateSaturation();break;case"font-saturation":break;case"font-lightness":fcn_updateFontLightness();break;case"hue-rotate":fcn_updateHueRotate(t[1]);break;case"font-weight":fcn_updateFontWeight();break;default:fcn_theRoot.classList.toggle(`no-${t[0]}`,!t[1])}})),fcn_setSiteSettings(t)}function fcn_updateSiteTheme(t){fcn_siteSettings["site-theme"]=t,fcn_theRoot.dataset.theme=t,_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=t),fcn_applySiteSettings(fcn_siteSettings),fcn_updateThemeColor()}function fcn_resetSiteTheme(){fcn_updateSiteTheme("default"),_$$(".site-setting-site-theme").forEach((t=>{t.value="default"}))}function fcn_jumpPage(t){if(fcn_theRoot.dataset.disablePageJump)return;const e=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));if(e>0){const n=t.nextElementSibling.getAttribute("href"),a=["page=","paged=","comment-page-","pg="];for(const t of a)if(n.includes(t))return void(window.location.href=n.replace(new RegExp(`${t}\\d+`),t+e));window.location.href=n.replace(/page\/\d+/,`page/${e}`)}}fcn_settingEvents.forEach((t=>{_$$$(`site-setting-${t}`)?.addEventListener("change",(e=>{fcn_updateSiteSetting(e.currentTarget,t,e.currentTarget.checked)}))})),fcn_setLightMode(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault,!0),_$$(".toggle-light-mode").forEach((t=>{t.onclick=()=>fcn_toggleLightMode()})),_$$(".font-weight-reset").forEach((t=>{t.addEventListener("click",fcn_resetFontWeight)})),_$$(".site-setting-font-weight").forEach((t=>{t.onchange=t=>{fcn_siteSettings["font-weight"]=t.target.value,fcn_theRoot.dataset.fontWeight=t.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((t=>{t.addEventListener("click",(()=>{fcn_updateDarken(0)}))})),fcn_settingDarkenRanges.forEach((t=>{t.addEventListener("input",fcn_throttle(fcn_setDarkenFromRange,1e3/24))})),fcn_settingDarkenTexts.forEach((t=>{t.addEventListener("input",fcn_setDarkenFromText)})),fcn_settingSaturationResets.forEach((t=>{t.addEventListener("click",(()=>{fcn_updateSaturation(0)}))})),fcn_settingSaturationRanges.forEach((t=>{t.addEventListener("input",fcn_throttle(fcn_setSaturationFromRange,1e3/24))})),fcn_settingSaturationTexts.forEach((t=>{t.addEventListener("input",fcn_setSaturationFromText)})),fcn_settingFontLightnessResets.forEach((t=>{t.addEventListener("click",(()=>{fcn_updateFontLightness(0)}))})),fcn_settingFontLightnessRanges.forEach((t=>{t.addEventListener("input",fcn_throttle(fcn_setFontLightnessFromRange,1e3/24))})),fcn_settingFontLightnessTexts.forEach((t=>{t.addEventListener("input",fcn_setFontLightnessFromText)})),fcn_applySiteSettings(fcn_siteSettings),_$$(".site-setting-site-theme").forEach((t=>{t.value=fcn_siteSettings["site-theme"]?fcn_siteSettings["site-theme"]:"default",_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=t.value),t.addEventListener("change",(t=>{fcn_updateSiteTheme(t.target.value)}))})),_$$$("site-setting-theme-reset")?.addEventListener("click",fcn_resetSiteTheme),fcn_updateThemeColor();const fcn_cardListMutationObserver=new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.length>0&&(fcn_updateFollowsView?.(),fcn_updateCheckmarksView?.(),fcn_updateRemindersView?.())}))}));function fcn_revealCommentImage(t){const e=t.parentElement.querySelector("img");e.src=e.dataset.src,t.remove()}function fcn_contactFormSubmit(t){const e=t.closest("form"),n=new FormData(e),a={action:"fictioneer_ajax_submit_contact_form"};if(e.reportValidity()&&(t.disabled=!0,t.innerHTML=t.dataset.disabled,!(Date.now()<fcn_pageLoadTimestamp+3e3))){for(const[t,e]of n)a[t]=e;e.classList.add("ajax-in-progress"),fcn_ajaxPost(a).then((n=>{n.success?(e.querySelector("textarea").value="",t.innerHTML=t.dataset.done,fcn_showNotification(n.data.success,3,"success")):n.data.error&&(t.disabled=!1,t.innerHTML=t.dataset.enabled,fcn_showNotification(n.data.error,5,"warning"))})).catch((e=>{e.status&&e.statusText&&(fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning"),t.disabled=!1,t.innerHTML=t.dataset.enabled)})).then((()=>{e.classList.remove("ajax-in-progress")}))}}_$$(".card-list:not(._no-mutation-observer)").forEach((t=>fcn_cardListMutationObserver.observe(t,{childList:!0,subtree:!0}))),_$$(".chapter-group__name").forEach((t=>{t.addEventListener("click",(t=>{const e=t.currentTarget.closest(".chapter-group"),n=e.querySelector(".chapter-group__list"),a=!e.classList.contains("_closed");_$(".main__background")?.classList.add("will-change"),n.style.height=`${n.scrollHeight}px`,requestAnimationFrame((()=>{requestAnimationFrame((()=>{e.classList.toggle("_closed",a),n.style.height=a?"0":`${n.scrollHeight}px`}))}))}))})),_$$(".chapter-group__list").forEach((t=>{t.addEventListener("transitionend",(e=>{t.style.height="",t.querySelectorAll("a, button, label, input:not([hidden])").forEach((e=>{e.tabIndex=t.parentElement.classList.contains("_closed")?"-1":"0"})),_$(".main__background")?.classList.remove("will-change")}))})),_$(".fictioneer-comments")?.addEventListener("click",(t=>{t.target?.classList.contains("consent-button")&&fcn_revealCommentImage(t.target)})),_$$(".fcn-contact-form").forEach((t=>{t.querySelector(".fcn-contact-form__submit").addEventListener("click",(t=>{fcn_contactFormSubmit(t.currentTarget)}))})),fcn_theBody.querySelectorAll(".modal-toggle").forEach((t=>{t.addEventListener("change",(t=>{if(t.currentTarget.checked){const e=t.currentTarget.nextElementSibling.querySelector('[tabindex="0"]');e?.focus(),e?.blur()}else fcn_theBody.classList.contains("user-is-tabbing")&&fcn_theSite.querySelector(`label[for="${t.currentTarget.id}"]`)?.focus()}))})),_$$('[data-click-action*="open-dialog-modal"]').forEach((t=>{t.addEventListener("click",(t=>{document.querySelector(t.currentTarget.dataset.clickTarget).showModal()}))})),_$$('[data-click-action*="close-dialog-modal"]').forEach((t=>{t.addEventListener("click",(t=>{t.preventDefault(),t.target.closest("dialog").close()}))})),_$$("dialog").forEach((t=>{t.addEventListener("mousedown",(t=>{"dialog"===t.target.tagName.toLowerCase()&&(t.preventDefault(),t.target.close())}))})),fcn_theBody.addEventListener("keydown",(t=>{let e=document.activeElement.closest('[tabindex="0"]:not(a, input, button, select)');if(["BUTTON","A","INPUT","SELECT"].includes(document.activeElement.tagName)&&(e=null),e&&(32!=t.keyCode&&13!=t.keyCode||(t.preventDefault(),e.click())),27==t.keyCode){_$$(".modal-toggle:checked").forEach((t=>{t.checked=!1,t.dispatchEvent(new Event("change"))}));const t=_$(".lightbox.show");if(t)return void t.querySelector(".lightbox__close").click();const e=_$(".selected-paragraph #button-close-paragraph-tools");if(e)return void e.click();const n=_$("#tts-interface:not(.hidden)");if(n){if(n.classList.contains("playing")){const t=_$$$("button-tts-pause");t?.click(),t?.focus(),t?.blur()}else _$$$("button-tts-stop").click();return}}}));class FCN_KeywordInput{constructor(t){this.input=t,this.operator=t.closest(".keyword-input").querySelector(".keyword-input__operator input"),this.inputWrapper=t.closest(".keyword-input__input-wrapper"),this.block=t.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 t=this.tabSuggestion.innerText.length>0?this.tabSuggestion.innerText.length:this.input.value.length;this.input.style.width=.88*t+2+"ch"}reset(){this.keywords=[],this.block.querySelectorAll(".node").forEach((t=>{t.remove()})),this.block.querySelectorAll(".keyword-input__operator > input").forEach((t=>{t.checked=!1})),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}encode(t){const e=(new TextEncoder).encode(t.toLowerCase());return btoa(String.fromCharCode.apply(null,e))}filterSuggestions(){const t=this.input.value.toLowerCase();let e=0,n="";""==t?this.suggestionList.querySelectorAll(".keyword-button").forEach((t=>{t.hidden=!0})):this.suggestionList.querySelectorAll(".keyword-button").forEach((a=>{const o=a.innerText.toLowerCase();o.includes(t)&&this.keywords.indexOf(o)<0?(a.hidden=!1,e++,""==n&&o.startsWith(t)&&(n=o)):a.hidden=!0})),this.hints.querySelectorAll(".keyword-button").forEach((t=>{this.keywords.indexOf(t.value.toLowerCase())>-1?t.hidden=!0:t.hidden=!1})),this.tabSuggestion.innerHTML=n,
this.hints.hidden=!(""==t),this.noHint.hidden=!(""!=t&&e<1)}addNode(t=null,e=null){const n=t??this.input.value.replace(",","");let a=this.allowList[this.encode(n)];if("authors"==this.collection.name&&e&&(a=this.allowList[this.encode(n)+"_"+e.value]),!a||this.keywords.indexOf(a)>-1)return;this.keywords.push(a);const o=document.createElement("div");o.innerHTML=`<span class="node-name">${n}</span><span class="node-delete"><i class="fa-solid fa-xmark"></i></span>`,o.classList.add("node"),o.dataset.value=a,this.inputWrapper.parentNode.insertBefore(o,this.inputWrapper),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}removeNodeByValue(t){this.block.querySelector(`[data-value="${t}"]`)?.remove(),this.keywords=this.keywords.filter((e=>e!=t)),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",(t=>{t.currentTarget.value.includes(",")&&this.addNode(),this.block.classList.toggle("_empty",""===t.currentTarget.value&&""===this.collection.value),this.filterSuggestions(),this.resize()})),this.input.addEventListener("keydown",(t=>{9!=t.keyCode&&13!=t.keyCode||""!=this.tabSuggestion.innerText&&(t.preventDefault(),this.input.value=this.tabSuggestion.innerText,this.addNode()),27==t.keyCode&&(this.input.value="",this.tabSuggestion.innerHTML="",document.activeElement.blur()),8==t.keyCode&&""==this.input.value&&this.keywords.length>0&&this.removeNodeByValue(this.keywords.slice(-1))})),this.input.addEventListener("blur",(()=>{const t=this.allowList[this.encode(this.input.value)];this.blurTimeout=t?setTimeout((()=>{this.addNode()}),150):setTimeout((()=>{this.input.value="",this.tabSuggestion.innerHTML="",this.filterSuggestions(),this.resize()}),150)})),this.block.addEventListener("click",(t=>{t.target.closest(".node-delete")&&(t.preventDefault(),this.removeNodeByValue(t.target.closest(".node").dataset.value))})),this.block.querySelectorAll(".keyword-button").forEach((t=>{t.addEventListener("click",(t=>{clearTimeout(this.blurTimeout),this.addNode(t.currentTarget.innerText,t.currentTarget)}))}))}}function fcn_resetSearchForm(t,e,n){n.forEach((t=>t.reset())),e.querySelectorAll("input, select").forEach((t=>{t.value=t.dataset.default??t.value})),e.querySelector(".search-form__current").innerHTML="",fcn_showNotification(t.dataset.reset,2)}function fcn_handleTabInput(t){9==t.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((t=>{if("none"===window.getComputedStyle(t).display)return;const e=fcn_detectScreenCollision(t);e&&0===e.length||(e.includes("top")?(t.classList.remove("_top"),t.classList.add("_bottom")):e.includes("bottom")&&(t.classList.remove("_bottom"),t.classList.add("_top")),t.closest("._fixed-horizontal")||(e.includes("left")?(t.classList.remove("_center","_justify-right"),t.classList.add("_justify-left")):e.includes("right")&&(t.classList.remove("_center","_justify-left"),t.classList.add("_justify-right"))))}))}function fcn_markCurrentMenuItem(){_$$(`.menu-item > [data-nav-object-id="${fcn_theBody.dataset.postId}"]`).forEach((t=>{t.setAttribute("aria-current","page"),t.closest(".menu-item").classList.add("current-menu-item")}))}function fcn_showAgeConfirmationModal(){const t=_$(".story__article, .chapter__article")?.dataset.ageRating;if(!fcn_theRoot.dataset.ageConfirmation&&t&&"adult"!==t)return void _$$$("age-confirmation-modal")?.remove();const e=_$$$("age-confirmation-leave");fcn_theRoot.classList.add("age-modal-open"),_$$$("age-confirmation-modal").classList.add("_open"),_$$$("age-confirmation-confirm")?.addEventListener("click",(t=>{fcn_theRoot.classList.remove("age-modal-open"),t.currentTarget.closest(".modal").remove(),localStorage.setItem("fcnAgeConfirmation","1")})),e?.addEventListener("click",(()=>{window.location.href=e.dataset.redirect??"https://search.brave.com/",localStorage.removeItem("fcnAgeConfirmation")}))}function fcn_showLightbox(t){const e=_$$$("fictioneer-lightbox"),n=_$(".lightbox__content");let a=!1,o=null;if(n.innerHTML="",t.classList.add("lightbox-last-trigger"),"IMG"==t.tagName?(o=t.cloneNode(),a=!0):t.href&&(o=document.createElement("img"),o.src=t.href,a=!0),a&&o){["class","style","height","width"].forEach((t=>o.removeAttribute(t))),n.appendChild(o),e.classList.add("show");const t=e.querySelector(".lightbox__close");t?.focus(),t?.blur()}}function fcn_toggleMobileMenu(t){_$(".mobile-menu._advanced-mobile-menu")?fcn_toggleAdvancedMobileMenu(t):fcn_toggleSimpleMobileMenu(t)}function fcn_toggleSimpleMobileMenu(t){t?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down"),fcn_theBody.classList.remove("scrolling-up")):(fcn_theBody.classList.remove("mobile-menu-open"),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),_$$$("mobile-menu-toggle").checked=!1)}function fcn_toggleAdvancedMobileMenu(t){const e=_$$$("wpadminbar")?.offsetHeight??0,n=window.scrollY,a=fcn_theSite.scrollTop;t?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down","scrolled-to-top"),fcn_theBody.classList.remove("scrolling-up"),fcn_theSite.classList.add("transformed-scroll","transformed-site"),fcn_theSite.scrollTop=n-e,fcn_updateThemeColor()):(fcn_theSite.classList.remove("transformed-site","transformed-scroll"),fcn_theBody.classList.remove("mobile-menu-open"),fcn_updateThemeColor(),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),fcn_theRoot.style.scrollBehavior="auto",window.scroll(0,a+e),fcn_theRoot.style.scrollBehavior="",_$$$("mobile-menu-toggle").checked=!1,"function"==typeof fcn_trackProgress&&fcn_trackProgress())}function fcn_setupMobileJumpButton(t,e){const n=_$(t);n&&n.addEventListener("click",(()=>{fcn_toggleMobileMenu(!1),setTimeout((()=>{const t=e();t&&fcn_scrollTo(t)}),200)}))}function fcn_openMobileFrame(t){fcn_closeMobileFrames(),_$(`.mobile-menu__frame[data-frame="${t}"]`)?.classList.add("_active")}function fcn_closeMobileFrames(){_$$(".mobile-menu__frame._active").forEach((t=>{t.classList.remove("_active")}));const t=_$(".mobile-menu__bookmarks-panel");t&&(t.dataset.editing="false")}function fcn_appendChapterList(){const t=_$$$("mobile-menu-chapters-list");fcn_chapterList&&!t.hasChildNodes()&&t.appendChild(fcn_chapterList.cloneNode(!0))}_$$(".search-form").forEach((t=>{if(t.classList.contains("_simple"))return;const e=[];t.querySelectorAll(".keyword-input__input").forEach((t=>{e.push(new FCN_KeywordInput(t))})),t.querySelector(".allow-list")?.remove(),t.addEventListener("change",(e=>{e.target.classList.contains("search-form__advanced-control")||e.target.classList.contains("search-form__string")||(t.querySelector(".search-form__current").innerHTML="")})),t.querySelectorAll(".reset").forEach((n=>{n.addEventListener("click",(()=>{fcn_resetSearchForm(n,t,e)}))}))})),_$$(".search-form__advanced-toggle").forEach((t=>{t.addEventListener("click",(t=>{const e=t.currentTarget.closest("form");e.dataset.advanced="true"==e.dataset.advanced?"false":"true"}))})),window.addEventListener("keydown",fcn_handleTabInput),window.addEventListener("scroll.rAF",fcn_throttle(fcn_popupPosition,250)),_$$(".modal-toggle").forEach((t=>{t.addEventListener("change",(t=>{const e=_$$$(t.currentTarget.dataset.target);e.classList.toggle("_open",t.currentTarget.checked),e.hidden=!t.currentTarget.checked;const n=e.querySelector(".close");n?.focus(),n?.blur()}))})),fcn_theBody.addEventListener("click",(t=>{const e=t.target.closest("[href]"),n=e?.getAttribute("href");if(!e||"A"===!e.tagName||!n.startsWith("#")||n.length<2||"#respond"===n)return;const a=n.replace("#",""),o=_$$(`[name="${a}"], #${a}`)[0],c=e.closest(".comment._story-comment");c&&(window.location.href=c.querySelector(".fictioneer-comment__link").href+n),o&&(t.preventDefault(),o.scrollIntoView({behavior:"smooth",block:e.dataset?.block??"start"}))})),fcn_markCurrentMenuItem(),_$$$("age-confirmation-modal")&&"1"!==localStorage.getItem("fcnAgeConfirmation")&&!fcn_isSearchEngineCrawler()?setTimeout((()=>{fcn_showAgeConfirmationModal()}),2500):_$$$("age-confirmation-modal")?.remove(),fcn_theBody.addEventListener("click",(t=>{const e=t.target.closest("[data-lightbox]:not(.no-auto-lightbox)");e&&(t.preventDefault(),fcn_showLightbox(e))})),fcn_theBody.addEventListener("keydown",(t=>{const e=t.target.closest("[data-lightbox]:not(.no-auto-lightbox)");e&&(32!=t.keyCode&&13!=t.keyCode||(t.preventDefault(),fcn_showLightbox(e)))})),document.querySelectorAll(".lightbox__close, .lightbox").forEach((t=>{t.addEventListener("click",(t=>{if("IMG"!=t.target.tagName){_$$$("fictioneer-lightbox").classList.remove("show");const t=_$(".lightbox-last-trigger");t?.focus(),t?.blur(),t?.classList.remove("lightbox-last-trigger")}}))})),_$$$("mobile-menu-toggle")?.addEventListener("change",(t=>{fcn_toggleMobileMenu(t.currentTarget.checked)})),fcn_theSite.addEventListener("click",(t=>{fcn_theBody.classList.contains("mobile-menu-open")&&(t.preventDefault(),fcn_toggleMobileMenu(!1))})),fcn_setupMobileJumpButton("#mobile-menu-comment-jump",(()=>_$$$("comments"))),fcn_setupMobileJumpButton("#mobile-menu-bookmark-jump",(()=>_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`))),_$$(".button-change-lightness").forEach((t=>{t.addEventListener("click",(t=>{fcn_updateDarken(fcn_siteSettings.darken+parseFloat(t.currentTarget.value))}))})),_$$(".mobile-menu__frame-button").forEach((t=>{t.addEventListener("click",(t=>{fcn_openMobileFrame(t.currentTarget.dataset.frameTarget)}))})),_$$(".mobile-menu__back-button").forEach((t=>{t.addEventListener("click",(()=>{fcn_openMobileFrame("main")}))})),_$('.mobile-menu__frame-button[data-frame-target="chapters"]')?.addEventListener("click",(()=>{fcn_appendChapterList()}),{once:!0}),_$$$("micro-menu-label-open-chapter-list")?.addEventListener("click",(()=>{fcn_appendChapterList(),fcn_openMobileFrame("chapters")})),_$$$("button-mobile-menu-toggle-bookmarks-edit")?.addEventListener("click",(t=>{const e=t.currentTarget.closest(".mobile-menu__bookmarks-panel");e.dataset.editing="false"==e.dataset.editing?"true":"false"})),_$('.mobile-menu__frame-button[data-frame-target="bookmarks"]')?.addEventListener("click",(()=>{fcn_setMobileMenuBookmarks()}),{once:!0});const fcn_consentBanner=_$$$("consent-banner");function fcn_loadConsentBanner(){fcn_consentBanner.classList.remove("hidden"),fcn_consentBanner.hidden=!1,_$$$("consent-accept-button")?.addEventListener("click",(()=>{fcn_setCookie("fcn_cookie_consent","full"),fcn_consentBanner.classList.add("hidden"),fcn_consentBanner.hidden=!0})),_$$$("consent-reject-button")?.addEventListener("click",(()=>{fcn_setCookie("fcn_cookie_consent","necessary"),fcn_consentBanner.classList.add("hidden"),fcn_consentBanner.hidden=!0}))}fcn_consentBanner&&""===(fcn_getCookie("fcn_cookie_consent")??"")&&!fcn_isSearchEngineCrawler()?setTimeout((()=>{fcn_loadConsentBanner()}),4e3):fcn_consentBanner.remove();const fcn_chapterFormatting=_$(".chapter-formatting");var fcn_formatting=fcn_getFormatting();const fcn_paragraphTools=_$$$("paragraph-tools");var fcn_lastSelectedParagraphId,fcn_bookmarkColor="none";function fcn_toggleParagraphTools(t=!1,e=null){e&&e.classList.contains("spoiler")&&!e.classList.contains("_open")||(_$$$(`paragraph-${fcn_lastSelectedParagraphId}`)?.classList.remove("selected-paragraph"),t&&fcn_formatting["show-paragraph-tools"]?(fcn_lastSelectedParagraphId=t,e.classList.add("selected-paragraph"),e.classList.contains("is-wrapped")||(e.innerHTML=`<span class="paragraph-inner">${e.innerHTML}</span>`,e.classList.add("is-wrapped")),e.append(fcn_paragraphTools)):fcn_lastSelectedParagraphId=null)}function fcn_touchParagraph(t){if(t.target.classList.contains("spoiler")||t.target.closest(".popup-menu-toggle, .skip-tools")||!t.target.closest("p")?.textContent.trim().length)return;if(!t.target.closest("p")?.parentElement?.classList.contains("chapter-formatting"))return;if(t.target.closest(".hidden, .inside-epub"))return;if(""!=window.getSelection().toString())return;const e=t.target.closest("p[data-paragraph-id]");if(t.target.closest(".tts-interface, .paragraph-tools__actions"))return;if(!e)return void fcn_toggleParagraphTools(!1);let n=!!e.dataset.paragraphId&&e.dataset.paragraphId;n=n!=fcn_lastSelectedParagraphId&&n;const a=(new Date).getTime();e.addEventListener("mouseup",(()=>{(new Date).getTime()<=a+300&&fcn_toggleParagraphTools(n,e)}),{once:!0})}function fcn_getQuote(t){const e=fcn_cleanTextSelectionFromButtons(window.getSelection().toString()),n=`[anchor]${t.target.closest("p[data-paragraph-id]").id}[/anchor]`;let a=t.target.closest("p[data-paragraph-id]").querySelector(".paragraph-inner").innerText,o="[…] ",c=" […]";if(a.length>16&&e.replace(/\s/g,"").length){const t=Math.ceil(.25*e.length),n=a.substring(0,t+1),s=a.substring(a.length-t,a.length);e.startsWith(n)&&(o=""),e.endsWith(s)&&(c=""),a=`${o}${e}${c}`}a=`${a} ${n}`,fcn_addQuoteToStack(a),fcn_showNotification(fictioneer_tl.notification.quoteAppendedToComment)}function fcn_addQuoteToStack(t){const e=_$(fictioneer_comments.form_selector??"#comment");e?"TEXTAREA"==e.tagName?(e.value+=`\n[quote]${t}[/quote]\n`,fcn_textareaAdjust(_$("textarea#comment"))):"DIV"==e.tagName&&(e.innerHTML+=`\n[quote]${t}[/quote]\n`):fcn_commentStack?.push(`\n[quote]${t}[/quote]\n`)}function fcn_openFullscreen(){document.documentElement.requestFullscreen?document.documentElement.requestFullscreen():document.documentElement.webkitRequestFullscreen&&document.documentElement.webkitRequestFullscreen()}function fcn_closeFullscreen(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}function fcn_getFormatting(){let t=fcn_parseJSON(localStorage.getItem("fcnChapterFormatting"))??fcn_defaultFormatting();return Object.keys(t).length<15&&(t=fcn_defaultFormatting()),t.timestamp<1651164557584&&(t=fcn_defaultFormatting(),t.timestamp=Date.now()),fcn_setFormatting(t),t}function fcn_defaultFormatting(){return{"font-saturation":0,"font-color":fictioneer_font_colors[0].css,"font-name":fictioneer_fonts[0].css,"font-size":100,"letter-spacing":0,"line-height":1.7,"paragraph-spacing":1.5,"site-width":fcn_theRoot.dataset.siteWidthDefault??"960",indent:!0,"show-sensitive-content":!0,"show-chapter-notes":!0,justify:!1,"show-comments":!0,"show-paragraph-tools":!0,timestamp:1664797604825,...JSON.parse(fcn_theRoot.dataset.defaultFormatting??"{}")}}function fcn_setFormatting(t){"object"==typeof t&&(fcn_formatting=t,localStorage.setItem("fcnChapterFormatting",JSON.stringify(t)))}function fcn_updateToggle(t,e,n,a={}){a={save:!0,...a};const o=fcn_evaluateAsBoolean(t,!0),c=_$(e);if(c&&(c.checked=o,c.closest("label").setAttribute("aria-checked",o)),a.toggleClass&&fcn_chapterFormatting.classList.toggle(a.toggleClass,a.invertClass?!o:o),a.sensitiveContent){const t=_$$$("inline-sensitive-content-toggle");t?.classList.toggle("hide-sensitive",!o),t?.setAttribute("aria-checked",!o)}a.notes&&_$$(".chapter-note-hideable").forEach((t=>{t.classList.toggle("hidden",!o)})),a.comments&&_$$(".chapter-comments-hideable").forEach((t=>{t.classList.toggle("hidden",!o)})),fcn_formatting[n]=o,a.save&&fcn_setFormatting(fcn_formatting)}document.addEventListener("click",(t=>{fcn_paragraphTools?.closest("p")?.contains(t.target)||fcn_toggleParagraphTools(!1)})),fcn_paragraphTools&&(document.addEventListener("mousedown",(t=>{fcn_touchParagraph(t)})),_$$$("button-close-paragraph-tools").onclick=t=>{fcn_toggleParagraphTools(!1)},_$$$("button-get-link").onclick=t=>{fcn_copyToClipboard(`${location.host}${location.pathname}#${t.target.closest("p[data-paragraph-id]").id}`,fictioneer_tl.notification.linkCopiedToClipboard)},_$$$("button-comment-stack")?.addEventListener("click",(t=>{fcn_getQuote(t)})),_$$(".paragraph-tools__bookmark-colors > div").forEach((t=>{t.onclick=t=>{fcn_bookmarkColor=t.target.dataset.color}})),_$$$("button-set-bookmark")?.addEventListener("click",(t=>{fcn_toggleBookmark(t.target.closest("p[data-paragraph-id]").dataset.paragraphId,fcn_bookmarkColor),window.matchMedia("(min-width: 1024px)").matches&&fcn_toggleParagraphTools(!1),fcn_bookmarkColor="none"}))),_$$(".open-fullscreen").forEach((t=>{t.addEventListener("click",(()=>{fcn_openFullscreen()}))})),_$$(".close-fullscreen").forEach((t=>{t.addEventListener("click",(()=>{fcn_closeFullscreen()}))})),(()=>{"use strict";const t=_$$$("reader-settings-font-size-text"),e=_$$$("reader-settings-font-size-range"),n=_$$$("reader-settings-font-size-reset");function a(a,o=!0){a=fcn_clamp(50,200,a??100),t.value=a,e.value=a,n.classList.toggle("_modified",100!=a),_$$(".resize-font").forEach((t=>{t.style.fontSize=`${a}%`})),fcn_formatting["font-size"]=a,o&&fcn_setFormatting(fcn_formatting)}function o(){a(this.value)}function c(){a(parseFloat(fcn_formatting["font-size"])+parseFloat(this.dataset.modifier))}n&&(_$$$("reset-font")?.addEventListener("click",(()=>{a(100)})),n?.addEventListener("click",(()=>{a(100)})),e?.addEventListener("input",fcn_throttle(o,1e3/24)),t?.addEventListener("input",o),_$$$("increase-font")?.addEventListener("click",c),_$$$("decrease-font")?.addEventListener("click",c),a(fcn_formatting["font-size"],!1))})(),(()=>{"use strict";const t=_$$$("reader-settings-font-color-reset"),e=_$$$("reader-settings-font-color-select");function n(n,a=!0){n=fcn_clamp(0,fictioneer_font_colors.length-1,n),t.classList.toggle("_modified",n>0),e.value=n,fcn_chapterFormatting.style.setProperty("--text-chapter",fictioneer_font_colors[n].css),fcn_formatting["font-color"]=fictioneer_font_colors[n].css,a&&fcn_setFormatting(fcn_formatting)}t&&(t.onclick=()=>{n(0)},e.onchange=t=>{n(t.target.value)},_$$(".font-color-stepper").forEach((t=>{t.addEventListener("click",(t=>{!function(t=1){let a=(e.selectedIndex+parseInt(t))%fictioneer_font_colors.length;a=a<0?fictioneer_font_colors.length-1:a,n(a)}(t.currentTarget.value)}))})),n(fictioneer_font_colors.findIndex((t=>t.css==fcn_formatting["font-color"])),!1))})(),(()=>{"use strict";const t=_$$$("reader-settings-font-reset"),e=_$$$("reader-settings-font-select");function n(a,o=!0){a=fcn_clamp(0,fictioneer_fonts.length-1,a);let c=fictioneer_fonts[a].css;fictioneer_fonts[a].alt&&(c=`${c}, ${fictioneer_fonts[a].alt}`),a<0?n(0):(t.classList.toggle("_modified",a>0),e.value=a,_$$(".chapter-font-family").forEach((t=>{t.style.fontFamily=""===c?"var(--ff-system)":c+", var(--ff-system)"})),fcn_formatting["font-name"]=fictioneer_fonts[a].css,o&&fcn_setFormatting(fcn_formatting))}t&&(t.onclick=()=>{n(0)},e.onchange=t=>{n(t.target.value)},_$$(".font-stepper").forEach((t=>{t.addEventListener("click",(t=>{!function(t=1){let a=(e.selectedIndex+parseInt(t))%fictioneer_fonts.length;a=a<0?fictioneer_fonts.length-1:a,n(a)}(t.currentTarget.value)}))})),n(fictioneer_fonts.findIndex((t=>t.css==fcn_formatting["font-name"])),!1))})(),(()=>{"use strict";const t=_$$$("reader-settings-font-saturation-text"),e=_$$$("reader-settings-font-saturation-range"),n=_$$$("reader-settings-font-saturation-reset");function a(a,o=!0){a=fcn_clamp(-1,1,a??0),t.value=parseInt(100*a),e.value=a,n.classList.toggle("_modified",0!=a),fcn_chapterFormatting.style.setProperty("--font-saturation",`(${a>=0?1+a**2:1-a**2} + var(--font-saturation-offset))`),fcn_formatting["font-saturation"]=a,o&&fcn_setFormatting(fcn_formatting)}n&&(n?.addEventListener("click",(()=>{a(0)})),e?.addEventListener("input",fcn_throttle((function(){a(this.value)}),1e3/24)),t?.addEventListener("input",(function(){a(parseInt(this.value)/100)})),a(fcn_formatting["font-saturation"],!1))})(),(()=>{"use strict";const t=_$$$("reader-settings-letter-spacing-text"),e=_$$$("reader-settings-letter-spacing-range"),n=_$$$("reader-settings-letter-spacing-reset"),a=fcn_defaultFormatting()["letter-spacing"];function o(o,c=!0){o=fcn_clamp(-.1,.2,o??a),t.value=o,e.value=o,n.classList.toggle("_modified",o!=a),fcn_chapterFormatting.style.letterSpacing=`calc(${o}em + var(--font-letter-spacing-base))`,fcn_formatting["letter-spacing"]=o,c&&fcn_setFormatting(fcn_formatting)}function c(){o(this.value)}n&&(n?.addEventListener("click",(()=>{o(a)})),e?.addEventListener("input",fcn_throttle(c,1e3/24)),t?.addEventListener("input",c),o(fcn_formatting["letter-spacing"],!1))})(),(()=>{"use strict";const t=_$$$("reader-settings-paragraph-spacing-text"),e=_$$$("reader-settings-paragraph-spacing-range"),n=_$$$("reader-settings-paragraph-spacing-reset"),a=fcn_defaultFormatting()["paragraph-spacing"];function o(o,c=!0){o=fcn_clamp(0,3,o??a),t.value=o,e.value=o,n.classList.toggle("_modified",o!=a),fcn_chapterFormatting.style.setProperty("--paragraph-spacing",`${o}em`),fcn_formatting["paragraph-spacing"]=o,c&&fcn_setFormatting(fcn_formatting)}function c(){o(this.value)}n&&(n?.addEventListener("click",(()=>{o(a)})),e?.addEventListener("input",fcn_throttle(c,1e3/24)),t?.addEventListener("input",c),o(fcn_formatting["paragraph-spacing"],!1))})(),(()=>{"use strict";const t=_$$$("reader-settings-line-height-text"),e=_$$$("reader-settings-line-height-range"),n=_$$$("reader-settings-line-height-reset"),a=fcn_defaultFormatting()["line-height"];function o(o,c=!0){o=fcn_clamp(.8,3,o??a),t.value=o,e.value=o,n.classList.toggle("_modified",o!=a),fcn_chapterFormatting.style.lineHeight=`${o}`,fcn_formatting["line-height"]=o,c&&fcn_setFormatting(fcn_formatting)}function c(){o(this.value)}n&&(n?.addEventListener("click",(()=>{o(a)})),e?.addEventListener("input",fcn_throttle(c,1e3/24)),t?.addEventListener("input",c),o(fcn_formatting["line-height"],!1))})(),(()=>{"use strict";const t=_$$$("reader-settings-site-width-text"),e=_$$$("reader-settings-site-width-range"),n=_$$$("reader-settings-site-width-reset"),a=fcn_defaultFormatting()["site-width"];function o(o,c=!0){const s=_$("main");o=fcn_clamp(640,1920,o??a),t.value=o,e.value=o,n.classList.toggle("_modified",o!=a),s.style.setProperty("--site-width",`${o}px`),s.classList.toggle("_default-width",o==fcn_theRoot.dataset.siteWidthDefault),s.classList.toggle("_below-1024",o<1024&&o>=768),s.classList.toggle("_below-768",o<768&&o>640),s.classList.toggle("_640-and-below",o<=640),fcn_formatting["site-width"]=o,c&&fcn_setFormatting(fcn_formatting)}function c(){o(this.value)}n&&(n?.addEventListener("click",(()=>{o(a)})),e?.addEventListener("input",fcn_throttle(c,1e3/24)),t?.addEventListener("input",c),o(fcn_formatting["site-width"],!1))})(),_$$("#reader-settings-indent-toggle").forEach((t=>{const e={invertClass:!0,toggleClass:"no-indent"},n="indent";t.onclick=a=>{fcn_updateToggle(a.currentTarget.checked,`#${t.id}`,n,e)},fcn_updateToggle(fcn_formatting[n],`#${t.id}`,n,{save:!1,...e})})),_$$("#reader-settings-justify-toggle").forEach((t=>{const e={toggleClass:"justify"},n="justify";t.onclick=a=>{fcn_updateToggle(a.currentTarget.checked,`#${t.id}`,n,e)},fcn_updateToggle(fcn_formatting[n],`#${t.id}`,n,{save:!1,...e})})),_$$("#reader-settings-paragraph-tools-toggle").forEach((t=>{const e="show-paragraph-tools";t.onclick=n=>{fcn_updateToggle(n.currentTarget.checked,`#${t.id}`,e)},fcn_updateToggle(fcn_formatting[e],`#${t.id}`,e,{save:!1})})),_$$("#reader-settings-chapter-notes-toggle").forEach((t=>{const e={notes:!0},n="show-chapter-notes";t.onclick=a=>{fcn_updateToggle(a.currentTarget.checked,`#${t.id}`,n,e)},fcn_updateToggle(fcn_formatting[n],`#${t.id}`,n,{save:!1,...e})})),_$$("#reader-settings-comments-toggle").forEach((t=>{const e={comments:!0},n="show-comments";t.onclick=a=>{fcn_updateToggle(a.currentTarget.checked,`#${t.id}`,n,e)},fcn_updateToggle(fcn_formatting[n],`#${t.id}`,n,{save:!1,...e})})),_$$("#reader-settings-sensitive-content-toggle").forEach((t=>{const e={toggleClass:"hide-sensitive",invertClass:!0,sensitiveContent:!0},n="show-sensitive-content";t.onclick=a=>{fcn_updateToggle(a.currentTarget.checked,`#${t.id}`,n,e)},fcn_updateToggle(fcn_formatting[n],`#${t.id}`,n,{save:!1,...e})}));const fcn_progressBar=_$(".progress__bar"),fcn_chapterContent=_$$$("chapter-content");var fcn_chapterCheckmarkUpdated=!1;function fcn_trackProgress(){fcn_chapterContent&&(fcn_readingProgress(),window.addEventListener("scroll.rAF",fcn_throttle(fcn_readingProgress,1e3/48)))}function fcn_readingProgress(){if(fcn_settingMinimal.checked||!fcn_settingChapterProgressBar.checked)return;const t=fcn_chapterContent.getBoundingClientRect(),e=t.height,n=window.innerHeight,a=e-t.bottom-Math.max(t.top,0)+n/2;let o=100*a/e;if(fcn_theBody.classList.toggle("hasProgressBar",!(o<0||a>e+500)),o=fcn_clamp(0,100,o),fcn_progressBar.style.width=`${o}%`,o>=100&&!fcn_chapterCheckmarkUpdated&&fcn_isLoggedIn){const t=_$$$("inline-storage")?.dataset.storyId;if(fcn_chapterCheckmarkUpdated=!0,!t||"function"!=typeof fcn_toggleCheckmark)return;fcn_toggleCheckmark(t,"progress",parseInt(fcn_inlineStorage.postId),null,"set")}}_$("article:not(._password)")&&fcn_trackProgress(),_$$(".chapter-list-popup-toggle").forEach((t=>{t.addEventListener("click",(()=>{t.querySelector('[data-target="popup-chapter-list"]')?.appendChild(fcn_chapterList.cloneNode(!0))}),{once:!0})}));const fcn_chapterKeyboardNavigation=t=>{if(["INPUT","TEXTAREA","SELECT","OPTION"].includes(t.target.tagName)||t.target.isContentEditable)return;let e=null;"ArrowLeft"===t.code?e=_$("a.button._navigation._prev"):"ArrowRight"===t.code&&(e=_$("a.button._navigation._next")),e&&e.href&&(window.location.href=e+"#start")};if(document.addEventListener("keydown",fcn_chapterKeyboardNavigation),"#start"===window.location.hash){history.replaceState(null,document.title,window.location.pathname);const t=_$(".chapter__article");t&&fcn_scrollTo(t,128)}var diff_match_patch=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},DIFF_DELETE=-1,DIFF_INSERT=1,DIFF_EQUAL=0;diff_match_patch.Diff=function(t,e){this[0]=t,this[1]=e},diff_match_patch.Diff.prototype.length=2,diff_match_patch.Diff.prototype.toString=function(){return this[0]+","+this[1]},diff_match_patch.prototype.diff_main=function(t,e,n,a){if(void 0===a&&(a=0>=this.Diff_Timeout?Number.MAX_VALUE:(new Date).getTime()+1e3*this.Diff_Timeout),null==t||null==e)throw Error("Null input. (diff_main)");if(t==e)return t?[new diff_match_patch.Diff(DIFF_EQUAL,t)]:[];void 0===n&&(n=!0);var o=n,c=this.diff_commonPrefix(t,e);n=t.substring(0,c),t=t.substring(c),e=e.substring(c),c=this.diff_commonSuffix(t,e);var s=t.substring(t.length-c);return t=t.substring(0,t.length-c),e=e.substring(0,e.length-c),t=this.diff_compute_(t,e,o,a),n&&t.unshift(new diff_match_patch.Diff(DIFF_EQUAL,n)),s&&t.push(new diff_match_patch.Diff(DIFF_EQUAL,s)),this.diff_cleanupMerge(t),t},diff_match_patch.prototype.diff_compute_=function(t,e,n,a){if(!t)return[new diff_match_patch.Diff(DIFF_INSERT,e)];if(!e)return[new diff_match_patch.Diff(DIFF_DELETE,t)];var o=t.length>e.length?t:e,c=t.length>e.length?e:t,s=o.indexOf(c);return-1!=s?(n=[new diff_match_patch.Diff(DIFF_INSERT,o.substring(0,s)),new diff_match_patch.Diff(DIFF_EQUAL,c),new diff_match_patch.Diff(DIFF_INSERT,o.substring(s+c.length))],t.length>e.length&&(n[0][0]=n[2][0]=DIFF_DELETE),n):1==c.length?[new diff_match_patch.Diff(DIFF_DELETE,t),new diff_match_patch.Diff(DIFF_INSERT,e)]:(o=this.diff_halfMatch_(t,e))?(e=o[1],c=o[3],t=o[4],o=this.diff_main(o[0],o[2],n,a),n=this.diff_main(e,c,n,a),o.concat([new diff_match_patch.Diff(DIFF_EQUAL,t)],n)):n&&100<t.length&&100<e.length?this.diff_lineMode_(t,e,a):this.diff_bisect_(t,e,a)},diff_match_patch.prototype.diff_lineMode_=function(t,e,n){var a=this.diff_linesToChars_(t,e);t=a.chars1,e=a.chars2,a=a.lineArray,t=this.diff_main(t,e,!1,n),this.diff_charsToLines_(t,a),this.diff_cleanupSemantic(t),t.push(new diff_match_patch.Diff(DIFF_EQUAL,""));for(var o=a=e=0,c="",s="";e<t.length;){switch(t[e][0]){case DIFF_INSERT:o++,s+=t[e][1];break;case DIFF_DELETE:a++,c+=t[e][1];break;case DIFF_EQUAL:if(1<=a&&1<=o){for(t.splice(e-a-o,a+o),e=e-a-o,o=(a=this.diff_main(c,s,!1,n)).length-1;0<=o;o--)t.splice(e,0,a[o]);e+=a.length}a=o=0,s=c=""}e++}return t.pop(),t},diff_match_patch.prototype.diff_bisect_=function(t,e,n){for(var a=t.length,o=e.length,c=Math.ceil((a+o)/2),s=2*c,i=Array(s),r=Array(s),l=0;l<s;l++)i[l]=-1,r[l]=-1;i[c+1]=0,r[c+1]=0;for(var f=0!=(l=a-o)%2,d=0,_=0,u=0,h=0,g=0;g<c&&!((new Date).getTime()>n);g++){for(var m=-g+d;m<=g-_;m+=2){for(var p=c+m,k=m==-g||m!=g&&i[p-1]<i[p+1]?i[p+1]:i[p-1]+1,b=k-m;k<a&&b<o&&t.charAt(k)==e.charAt(b);)k++,b++;if(i[p]=k,k>a)_+=2;else if(b>o)d+=2;else if(f&&(0<=(p=c+l-m)&&p<s&&-1!=r[p])){var v=a-r[p];if(k>=v)return this.diff_bisectSplit_(t,e,k,b,n)}}for(m=-g+u;m<=g-h;m+=2){for(p=c+m,k=(v=m==-g||m!=g&&r[p-1]<r[p+1]?r[p+1]:r[p-1]+1)-m;v<a&&k<o&&t.charAt(a-v-1)==e.charAt(o-k-1);)v++,k++;if(r[p]=v,v>a)h+=2;else if(k>o)u+=2;else if(!f&&(0<=(p=c+l-m)&&p<s&&-1!=i[p]&&(b=c+(k=i[p])-p,k>=(v=a-v))))return this.diff_bisectSplit_(t,e,k,b,n)}}return[new diff_match_patch.Diff(DIFF_DELETE,t),new diff_match_patch.Diff(DIFF_INSERT,e)]},diff_match_patch.prototype.diff_bisectSplit_=function(t,e,n,a,o){var c=t.substring(0,n),s=e.substring(0,a);return t=t.substring(n),e=e.substring(a),c=this.diff_main(c,s,!1,o),o=this.diff_main(t,e,!1,o),c.concat(o)},diff_match_patch.prototype.diff_linesToChars_=function(t,e){function n(t){for(var e="",n=0,s=-1,i=a.length;s<t.length-1;){-1==(s=t.indexOf("\n",n))&&(s=t.length-1);var r=t.substring(n,s+1);void 0!==o[r]?e+=String.fromCharCode(o[r]):(i==c&&(r=t.substring(n),s=t.length),e+=String.fromCharCode(i),o[r]=i,a[i++]=r),n=s+1}return e}var a=[],o={};a[0]="";var c=4e4,s=n(t);return c=65535,{chars1:s,chars2:n(e),lineArray:a}},diff_match_patch.prototype.diff_charsToLines_=function(t,e){for(var n=0;n<t.length;n++){for(var a=t[n][1],o=[],c=0;c<a.length;c++)o[c]=e[a.charCodeAt(c)];t[n][1]=o.join("")}},diff_match_patch.prototype.diff_commonPrefix=function(t,e){if(!t||!e||t.charAt(0)!=e.charAt(0))return 0;for(var n=0,a=Math.min(t.length,e.length),o=a,c=0;n<o;)t.substring(c,o)==e.substring(c,o)?c=n=o:a=o,o=Math.floor((a-n)/2+n);return o},diff_match_patch.prototype.diff_commonSuffix=function(t,e){if(!t||!e||t.charAt(t.length-1)!=e.charAt(e.length-1))return 0;for(var n=0,a=Math.min(t.length,e.length),o=a,c=0;n<o;)t.substring(t.length-o,t.length-c)==e.substring(e.length-o,e.length-c)?c=n=o:a=o,o=Math.floor((a-n)/2+n);return o},diff_match_patch.prototype.diff_commonOverlap_=function(t,e){var n=t.length,a=e.length;if(0==n||0==a)return 0;if(n>a?t=t.substring(n-a):n<a&&(e=e.substring(0,n)),n=Math.min(n,a),t==e)return n;a=0;for(var o=1;;){var c=t.substring(n-o);if(-1==(c=e.indexOf(c)))return a;o+=c,0!=c&&t.substring(n-o)!=e.substring(0,o)||(a=o,o++)}},diff_match_patch.prototype.diff_halfMatch_=function(t,e){function n(t,e,n){for(var a,o,s,i,r=t.substring(n,n+Math.floor(t.length/4)),l=-1,f="";-1!=(l=e.indexOf(r,l+1));){var d=c.diff_commonPrefix(t.substring(n),e.substring(l)),_=c.diff_commonSuffix(t.substring(0,n),e.substring(0,l));f.length<_+d&&(f=e.substring(l-_,l)+e.substring(l,l+d),a=t.substring(0,n-_),o=t.substring(n+d),s=e.substring(0,l-_),i=e.substring(l+d))}return 2*f.length>=t.length?[a,o,s,i,f]:null}if(0>=this.Diff_Timeout)return null;var a=t.length>e.length?t:e,o=t.length>e.length?e:t;if(4>a.length||2*o.length<a.length)return null;var c=this,s=n(a,o,Math.ceil(a.length/4));if(a=n(a,o,Math.ceil(a.length/2)),!s&&!a)return null;if(s=a?s&&s[4].length>a[4].length?s:a:s,t.length>e.length){a=s[0],o=s[1];var i=s[2],r=s[3]}else i=s[0],r=s[1],a=s[2],o=s[3];return[a,o,i,r,s[4]]},diff_match_patch.prototype.diff_cleanupSemantic=function(t){for(var e=!1,n=[],a=0,o=null,c=0,s=0,i=0,r=0,l=0;c<t.length;)t[c][0]==DIFF_EQUAL?(n[a++]=c,s=r,i=l,
l=r=0,o=t[c][1]):(t[c][0]==DIFF_INSERT?r+=t[c][1].length:l+=t[c][1].length,o&&o.length<=Math.max(s,i)&&o.length<=Math.max(r,l)&&(t.splice(n[a-1],0,new diff_match_patch.Diff(DIFF_DELETE,o)),t[n[a-1]+1][0]=DIFF_INSERT,a--,c=0<--a?n[a-1]:-1,l=r=i=s=0,o=null,e=!0)),c++;for(e&&this.diff_cleanupMerge(t),this.diff_cleanupSemanticLossless(t),c=1;c<t.length;)t[c-1][0]==DIFF_DELETE&&t[c][0]==DIFF_INSERT&&(e=t[c-1][1],n=t[c][1],(a=this.diff_commonOverlap_(e,n))>=(o=this.diff_commonOverlap_(n,e))?(a>=e.length/2||a>=n.length/2)&&(t.splice(c,0,new diff_match_patch.Diff(DIFF_EQUAL,n.substring(0,a))),t[c-1][1]=e.substring(0,e.length-a),t[c+1][1]=n.substring(a),c++):(o>=e.length/2||o>=n.length/2)&&(t.splice(c,0,new diff_match_patch.Diff(DIFF_EQUAL,e.substring(0,o))),t[c-1][0]=DIFF_INSERT,t[c-1][1]=n.substring(0,n.length-o),t[c+1][0]=DIFF_DELETE,t[c+1][1]=e.substring(o),c++),c++),c++},diff_match_patch.prototype.diff_cleanupSemanticLossless=function(t){function e(t,e){if(!t||!e)return 6;var n=t.charAt(t.length-1),a=e.charAt(0),o=n.match(diff_match_patch.nonAlphaNumericRegex_),c=a.match(diff_match_patch.nonAlphaNumericRegex_),s=o&&n.match(diff_match_patch.whitespaceRegex_),i=c&&a.match(diff_match_patch.whitespaceRegex_);n=s&&n.match(diff_match_patch.linebreakRegex_),a=i&&a.match(diff_match_patch.linebreakRegex_);var r=n&&t.match(diff_match_patch.blanklineEndRegex_),l=a&&e.match(diff_match_patch.blanklineStartRegex_);return r||l?5:n||a?4:o&&!s&&i?3:s||i?2:o||c?1:0}for(var n=1;n<t.length-1;){if(t[n-1][0]==DIFF_EQUAL&&t[n+1][0]==DIFF_EQUAL){var a=t[n-1][1],o=t[n][1],c=t[n+1][1],s=this.diff_commonSuffix(a,o);if(s){var i=o.substring(o.length-s);a=a.substring(0,a.length-s),o=i+o.substring(0,o.length-s),c=i+c}s=a,i=o;for(var r=c,l=e(a,o)+e(o,c);o.charAt(0)===c.charAt(0);){a+=o.charAt(0),o=o.substring(1)+c.charAt(0),c=c.substring(1);var f=e(a,o)+e(o,c);f>=l&&(l=f,s=a,i=o,r=c)}t[n-1][1]!=s&&(s?t[n-1][1]=s:(t.splice(n-1,1),n--),t[n][1]=i,r?t[n+1][1]=r:(t.splice(n+1,1),n--))}n++}},diff_match_patch.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,diff_match_patch.whitespaceRegex_=/\s/,diff_match_patch.linebreakRegex_=/[\r\n]/,diff_match_patch.blanklineEndRegex_=/\n\r?\n$/,diff_match_patch.blanklineStartRegex_=/^\r?\n\r?\n/,diff_match_patch.prototype.diff_cleanupEfficiency=function(t){for(var e=!1,n=[],a=0,o=null,c=0,s=!1,i=!1,r=!1,l=!1;c<t.length;)t[c][0]==DIFF_EQUAL?(t[c][1].length<this.Diff_EditCost&&(r||l)?(n[a++]=c,s=r,i=l,o=t[c][1]):(a=0,o=null),r=l=!1):(t[c][0]==DIFF_DELETE?l=!0:r=!0,o&&(s&&i&&r&&l||o.length<this.Diff_EditCost/2&&3==s+i+r+l)&&(t.splice(n[a-1],0,new diff_match_patch.Diff(DIFF_DELETE,o)),t[n[a-1]+1][0]=DIFF_INSERT,a--,o=null,s&&i?(r=l=!0,a=0):(c=0<--a?n[a-1]:-1,r=l=!1),e=!0)),c++;e&&this.diff_cleanupMerge(t)},diff_match_patch.prototype.diff_cleanupMerge=function(t){t.push(new diff_match_patch.Diff(DIFF_EQUAL,""));for(var e,n=0,a=0,o=0,c="",s="";n<t.length;)switch(t[n][0]){case DIFF_INSERT:o++,s+=t[n][1],n++;break;case DIFF_DELETE:a++,c+=t[n][1],n++;break;case DIFF_EQUAL:1<a+o?(0!==a&&0!==o&&(0!==(e=this.diff_commonPrefix(s,c))&&(0<n-a-o&&t[n-a-o-1][0]==DIFF_EQUAL?t[n-a-o-1][1]+=s.substring(0,e):(t.splice(0,0,new diff_match_patch.Diff(DIFF_EQUAL,s.substring(0,e))),n++),s=s.substring(e),c=c.substring(e)),0!==(e=this.diff_commonSuffix(s,c))&&(t[n][1]=s.substring(s.length-e)+t[n][1],s=s.substring(0,s.length-e),c=c.substring(0,c.length-e))),n-=a+o,t.splice(n,a+o),c.length&&(t.splice(n,0,new diff_match_patch.Diff(DIFF_DELETE,c)),n++),s.length&&(t.splice(n,0,new diff_match_patch.Diff(DIFF_INSERT,s)),n++),n++):0!==n&&t[n-1][0]==DIFF_EQUAL?(t[n-1][1]+=t[n][1],t.splice(n,1)):n++,a=o=0,s=c=""}for(""===t[t.length-1][1]&&t.pop(),a=!1,n=1;n<t.length-1;)t[n-1][0]==DIFF_EQUAL&&t[n+1][0]==DIFF_EQUAL&&(t[n][1].substring(t[n][1].length-t[n-1][1].length)==t[n-1][1]?(t[n][1]=t[n-1][1]+t[n][1].substring(0,t[n][1].length-t[n-1][1].length),t[n+1][1]=t[n-1][1]+t[n+1][1],t.splice(n-1,1),a=!0):t[n][1].substring(0,t[n+1][1].length)==t[n+1][1]&&(t[n-1][1]+=t[n+1][1],t[n][1]=t[n][1].substring(t[n+1][1].length)+t[n+1][1],t.splice(n+1,1),a=!0)),n++;a&&this.diff_cleanupMerge(t)},diff_match_patch.prototype.diff_xIndex=function(t,e){var n,a=0,o=0,c=0,s=0;for(n=0;n<t.length&&(t[n][0]!==DIFF_INSERT&&(a+=t[n][1].length),t[n][0]!==DIFF_DELETE&&(o+=t[n][1].length),!(a>e));n++)c=a,s=o;return t.length!=n&&t[n][0]===DIFF_DELETE?s:s+(e-c)},diff_match_patch.prototype.diff_prettyHtml=function(t){for(var e=[],n=/&/g,a=/</g,o=/>/g,c=/\n/g,s=0;s<t.length;s++){var i=t[s][0],r=t[s][1].replace(n,"&amp;").replace(a,"&lt;").replace(o,"&gt;").replace(c,"&para;<br>");switch(i){case DIFF_INSERT:e[s]='<ins style="background:#e6ffe6;">'+r+"</ins>";break;case DIFF_DELETE:e[s]='<del style="background:#ffe6e6;">'+r+"</del>";break;case DIFF_EQUAL:e[s]="<span>"+r+"</span>"}}return e.join("")},diff_match_patch.prototype.diff_text1=function(t){for(var e=[],n=0;n<t.length;n++)t[n][0]!==DIFF_INSERT&&(e[n]=t[n][1]);return e.join("")},diff_match_patch.prototype.diff_text2=function(t){for(var e=[],n=0;n<t.length;n++)t[n][0]!==DIFF_DELETE&&(e[n]=t[n][1]);return e.join("")},diff_match_patch.prototype.diff_levenshtein=function(t){for(var e=0,n=0,a=0,o=0;o<t.length;o++){var c=t[o][1];switch(t[o][0]){case DIFF_INSERT:n+=c.length;break;case DIFF_DELETE:a+=c.length;break;case DIFF_EQUAL:e+=Math.max(n,a),a=n=0}}return e+Math.max(n,a)},diff_match_patch.prototype.diff_toDelta=function(t){for(var e=[],n=0;n<t.length;n++)switch(t[n][0]){case DIFF_INSERT:e[n]="+"+encodeURI(t[n][1]);break;case DIFF_DELETE:e[n]="-"+t[n][1].length;break;case DIFF_EQUAL:e[n]="="+t[n][1].length}return e.join("\t").replace(/%20/g," ")},diff_match_patch.prototype.diff_fromDelta=function(t,e){for(var n=[],a=0,o=0,c=e.split(/\t/g),s=0;s<c.length;s++){var i=c[s].substring(1);switch(c[s].charAt(0)){case"+":try{n[a++]=new diff_match_patch.Diff(DIFF_INSERT,decodeURI(i))}catch(t){throw Error("Illegal escape in diff_fromDelta: "+i)}break;case"-":case"=":var r=parseInt(i,10);if(isNaN(r)||0>r)throw Error("Invalid number in diff_fromDelta: "+i);i=t.substring(o,o+=r),"="==c[s].charAt(0)?n[a++]=new diff_match_patch.Diff(DIFF_EQUAL,i):n[a++]=new diff_match_patch.Diff(DIFF_DELETE,i);break;default:if(c[s])throw Error("Invalid diff operation in diff_fromDelta: "+c[s])}}if(o!=t.length)throw Error("Delta length ("+o+") does not equal source text length ("+t.length+").");return n},diff_match_patch.prototype.match_main=function(t,e,n){if(null==t||null==e||null==n)throw Error("Null input. (match_main)");return n=Math.max(0,Math.min(n,t.length)),t==e?0:t.length?t.substring(n,n+e.length)==e?n:this.match_bitap_(t,e,n):-1},diff_match_patch.prototype.match_bitap_=function(t,e,n){function a(t,a){var o=t/e.length,s=Math.abs(n-a);return c.Match_Distance?o+s/c.Match_Distance:s?1:o}if(e.length>this.Match_MaxBits)throw Error("Pattern too long for this browser.");var o=this.match_alphabet_(e),c=this,s=this.Match_Threshold,i=t.indexOf(e,n);-1!=i&&(s=Math.min(a(0,i),s),-1!=(i=t.lastIndexOf(e,n+e.length))&&(s=Math.min(a(0,i),s)));var r=1<<e.length-1;i=-1;for(var l,f,d,_=e.length+t.length,u=0;u<e.length;u++){for(l=0,f=_;l<f;)a(u,n+f)<=s?l=f:_=f,f=Math.floor((_-l)/2+l);_=f,l=Math.max(1,n-f+1);var h=Math.min(n+f,t.length)+e.length;for((f=Array(h+2))[h+1]=(1<<u)-1;h>=l;h--){var g=o[t.charAt(h-1)];if(f[h]=0===u?(f[h+1]<<1|1)&g:(f[h+1]<<1|1)&g|(d[h+1]|d[h])<<1|1|d[h+1],f[h]&r&&(g=a(u,h-1))<=s){if(s=g,!((i=h-1)>n))break;l=Math.max(1,2*n-i)}}if(a(u+1,n)>s)break;d=f}return i},diff_match_patch.prototype.match_alphabet_=function(t){for(var e={},n=0;n<t.length;n++)e[t.charAt(n)]=0;for(n=0;n<t.length;n++)e[t.charAt(n)]|=1<<t.length-n-1;return e},diff_match_patch.prototype.patch_addContext_=function(t,e){if(0!=e.length){if(null===t.start2)throw Error("patch not initialized");for(var n=e.substring(t.start2,t.start2+t.length1),a=0;e.indexOf(n)!=e.lastIndexOf(n)&&n.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)a+=this.Patch_Margin,n=e.substring(t.start2-a,t.start2+t.length1+a);a+=this.Patch_Margin,(n=e.substring(t.start2-a,t.start2))&&t.diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL,n)),(a=e.substring(t.start2+t.length1,t.start2+t.length1+a))&&t.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,a)),t.start1-=n.length,t.start2-=n.length,t.length1+=n.length+a.length,t.length2+=n.length+a.length}},diff_match_patch.prototype.patch_make=function(t,e,n){if("string"==typeof t&&"string"==typeof e&&void 0===n){var a=t;2<(e=this.diff_main(a,e,!0)).length&&(this.diff_cleanupSemantic(e),this.diff_cleanupEfficiency(e))}else if(t&&"object"==typeof t&&void 0===e&&void 0===n)e=t,a=this.diff_text1(e);else if("string"==typeof t&&e&&"object"==typeof e&&void 0===n)a=t;else{if("string"!=typeof t||"string"!=typeof e||!n||"object"!=typeof n)throw Error("Unknown call format to patch_make.");a=t,e=n}if(0===e.length)return[];n=[],t=new diff_match_patch.patch_obj;for(var o=0,c=0,s=0,i=a,r=0;r<e.length;r++){var l=e[r][0],f=e[r][1];switch(o||l===DIFF_EQUAL||(t.start1=c,t.start2=s),l){case DIFF_INSERT:t.diffs[o++]=e[r],t.length2+=f.length,a=a.substring(0,s)+f+a.substring(s);break;case DIFF_DELETE:t.length1+=f.length,t.diffs[o++]=e[r],a=a.substring(0,s)+a.substring(s+f.length);break;case DIFF_EQUAL:f.length<=2*this.Patch_Margin&&o&&e.length!=r+1?(t.diffs[o++]=e[r],t.length1+=f.length,t.length2+=f.length):f.length>=2*this.Patch_Margin&&o&&(this.patch_addContext_(t,i),n.push(t),t=new diff_match_patch.patch_obj,o=0,i=a,c=s)}l!==DIFF_INSERT&&(c+=f.length),l!==DIFF_DELETE&&(s+=f.length)}return o&&(this.patch_addContext_(t,i),n.push(t)),n},diff_match_patch.prototype.patch_deepCopy=function(t){for(var e=[],n=0;n<t.length;n++){var a=t[n],o=new diff_match_patch.patch_obj;o.diffs=[];for(var c=0;c<a.diffs.length;c++)o.diffs[c]=new diff_match_patch.Diff(a.diffs[c][0],a.diffs[c][1]);o.start1=a.start1,o.start2=a.start2,o.length1=a.length1,o.length2=a.length2,e[n]=o}return e},diff_match_patch.prototype.patch_apply=function(t,e){if(0==t.length)return[e,[]];t=this.patch_deepCopy(t);var n=this.patch_addPadding(t);e=n+e+n,this.patch_splitMax(t);for(var a=0,o=[],c=0;c<t.length;c++){var s=t[c].start2+a,i=this.diff_text1(t[c].diffs),r=-1;if(i.length>this.Match_MaxBits){var l=this.match_main(e,i.substring(0,this.Match_MaxBits),s);-1!=l&&(-1==(r=this.match_main(e,i.substring(i.length-this.Match_MaxBits),s+i.length-this.Match_MaxBits))||l>=r)&&(l=-1)}else l=this.match_main(e,i,s);if(-1==l)o[c]=!1,a-=t[c].length2-t[c].length1;else if(o[c]=!0,a=l-s,i==(s=-1==r?e.substring(l,l+i.length):e.substring(l,r+this.Match_MaxBits)))e=e.substring(0,l)+this.diff_text2(t[c].diffs)+e.substring(l+i.length);else if(s=this.diff_main(i,s,!1),i.length>this.Match_MaxBits&&this.diff_levenshtein(s)/i.length>this.Patch_DeleteThreshold)o[c]=!1;else{var f;for(this.diff_cleanupSemanticLossless(s),i=0,r=0;r<t[c].diffs.length;r++){var d=t[c].diffs[r];d[0]!==DIFF_EQUAL&&(f=this.diff_xIndex(s,i)),d[0]===DIFF_INSERT?e=e.substring(0,l+f)+d[1]+e.substring(l+f):d[0]===DIFF_DELETE&&(e=e.substring(0,l+f)+e.substring(l+this.diff_xIndex(s,i+d[1].length))),d[0]!==DIFF_DELETE&&(i+=d[1].length)}}}return[e=e.substring(n.length,e.length-n.length),o]},diff_match_patch.prototype.patch_addPadding=function(t){for(var e=this.Patch_Margin,n="",a=1;a<=e;a++)n+=String.fromCharCode(a);for(a=0;a<t.length;a++)t[a].start1+=e,t[a].start2+=e;var o=(a=t[0]).diffs;if(0==o.length||o[0][0]!=DIFF_EQUAL)o.unshift(new diff_match_patch.Diff(DIFF_EQUAL,n)),a.start1-=e,a.start2-=e,a.length1+=e,a.length2+=e;else if(e>o[0][1].length){var c=e-o[0][1].length;o[0][1]=n.substring(o[0][1].length)+o[0][1],a.start1-=c,a.start2-=c,a.length1+=c,a.length2+=c}return 0==(o=(a=t[t.length-1]).diffs).length||o[o.length-1][0]!=DIFF_EQUAL?(o.push(new diff_match_patch.Diff(DIFF_EQUAL,n)),a.length1+=e,a.length2+=e):e>o[o.length-1][1].length&&(c=e-o[o.length-1][1].length,o[o.length-1][1]+=n.substring(0,c),a.length1+=c,a.length2+=c),n},diff_match_patch.prototype.patch_splitMax=function(t){for(var e=this.Match_MaxBits,n=0;n<t.length;n++)if(!(t[n].length1<=e)){var a=t[n];t.splice(n--,1);for(var o=a.start1,c=a.start2,s="";0!==a.diffs.length;){var i=new diff_match_patch.patch_obj,r=!0;for(i.start1=o-s.length,i.start2=c-s.length,""!==s&&(i.length1=i.length2=s.length,i.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,s)));0!==a.diffs.length&&i.length1<e-this.Patch_Margin;){s=a.diffs[0][0];var l=a.diffs[0][1];s===DIFF_INSERT?(i.length2+=l.length,c+=l.length,i.diffs.push(a.diffs.shift()),r=!1):s===DIFF_DELETE&&1==i.diffs.length&&i.diffs[0][0]==DIFF_EQUAL&&l.length>2*e?(i.length1+=l.length,o+=l.length,r=!1,i.diffs.push(new diff_match_patch.Diff(s,l)),a.diffs.shift()):(l=l.substring(0,e-i.length1-this.Patch_Margin),i.length1+=l.length,o+=l.length,s===DIFF_EQUAL?(i.length2+=l.length,c+=l.length):r=!1,i.diffs.push(new diff_match_patch.Diff(s,l)),l==a.diffs[0][1]?a.diffs.shift():a.diffs[0][1]=a.diffs[0][1].substring(l.length))}s=(s=this.diff_text2(i.diffs)).substring(s.length-this.Patch_Margin),""!==(l=this.diff_text1(a.diffs).substring(0,this.Patch_Margin))&&(i.length1+=l.length,i.length2+=l.length,0!==i.diffs.length&&i.diffs[i.diffs.length-1][0]===DIFF_EQUAL?i.diffs[i.diffs.length-1][1]+=l:i.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,l))),r||t.splice(++n,0,i)}}},diff_match_patch.prototype.patch_toText=function(t){for(var e=[],n=0;n<t.length;n++)e[n]=t[n];return e.join("")},diff_match_patch.prototype.patch_fromText=function(t){var e=[];if(!t)return e;t=t.split("\n");for(var n=0,a=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<t.length;){var o=t[n].match(a);if(!o)throw Error("Invalid patch string: "+t[n]);var c=new diff_match_patch.patch_obj;for(e.push(c),c.start1=parseInt(o[1],10),""===o[2]?(c.start1--,c.length1=1):"0"==o[2]?c.length1=0:(c.start1--,c.length1=parseInt(o[2],10)),c.start2=parseInt(o[3],10),""===o[4]?(c.start2--,c.length2=1):"0"==o[4]?c.length2=0:(c.start2--,c.length2=parseInt(o[4],10)),n++;n<t.length;){o=t[n].charAt(0);try{var s=decodeURI(t[n].substring(1))}catch(t){throw Error("Illegal escape in patch_fromText: "+s)}if("-"==o)c.diffs.push(new diff_match_patch.Diff(DIFF_DELETE,s));else if("+"==o)c.diffs.push(new diff_match_patch.Diff(DIFF_INSERT,s));else if(" "==o)c.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,s));else{if("@"==o)break;if(""!==o)throw Error('Invalid patch mode "'+o+'" in: '+s)}n++}}return e},diff_match_patch.patch_obj=function(){this.diffs=[],this.start2=this.start1=null,this.length2=this.length1=0},diff_match_patch.patch_obj.prototype.toString=function(){for(var t,e=["@@ -"+(0===this.length1?this.start1+",0":1==this.length1?this.start1+1:this.start1+1+","+this.length1)+" +"+(0===this.length2?this.start2+",0":1==this.length2?this.start2+1:this.start2+1+","+this.length2)+" @@\n"],n=0;n<this.diffs.length;n++){switch(this.diffs[n][0]){case DIFF_INSERT:t="+";break;case DIFF_DELETE:t="-";break;case DIFF_EQUAL:t=" "}e[n+1]=t+encodeURI(this.diffs[n][1])+"\n"}return e.join("").replace(/%20/g," ")},this.diff_match_patch=diff_match_patch,this.DIFF_DELETE=DIFF_DELETE,this.DIFF_INSERT=DIFF_INSERT,this.DIFF_EQUAL=DIFF_EQUAL,diff_match_patch.prototype.fcn_prettyHtml=function(t){for(var e=[],n=/&/g,a=/</g,o=/>/g,c=/\n/g,s=0;s<t.length;s++){var i=t[s][0],r=t[s][1].replace(n,"&amp;").replace(a,"&lt;").replace(o,"&gt;").replace(c,"&para;<br>");switch(i){case 1:e[s]=`<ins>${r}</ins>`;break;case-1:e[s]=`<del>${r}</del>`;break;case 0:e[s]=`${r}`}}return e.join("")};class FCN_Suggestion{constructor(){this.toggle=_$$$("suggestions-modal-toggle"),this.tools=_$$$("selection-tools"),this.button=_$$$("button-add-suggestion"),this.toolsButton=_$$$("button-tools-add-suggestion"),this.reset=_$$$("button-suggestion-reset"),this.submit=_$$$("button-suggestion-submit"),this.current=_$$$("suggestions-modal-original"),this.input=_$$$("suggestions-modal-input"),this.output=_$$$("suggestions-modal-diff"),this.chapter=_$(".chapter__article"),this.text="",this.original="",this.latest="",this.paragraph=null,this.dmp=new diff_match_patch,this.bindEvents()}getCaretCoordinates(){let t=0,e=0;if(void 0!==window.getSelection){const n=window.getSelection();if(0!==n.rangeCount){let a=n.getRangeAt(0).cloneRange().getClientRects();a=a[a.length-1],a&&(t=a.right+window.scrollX,e=a.bottom+window.scrollY)}}return{x:t,y:e}}getClosestParagraph(){const t=window.getSelection();return t.rangeCount?t.getRangeAt(0).startContainer.parentNode.closest("p"):null}showTools(t,e){const n=document.documentElement.offsetWidth/2+this.tools.offsetWidth,a=_$$$("wpadminbar")?_$$$("wpadminbar").offsetHeight:0;this.tools.style.transform=e>n?"translate(-100%)":"translate(0)",this.tools.style.top=t+4-a+"px",this.tools.style.left=`${e}px`,this.tools.classList.remove("invisible")}hideTools(){this.tools.style.top="0",this.tools.style.left="-1000px",this.tools.classList.add("invisible")}textSelection(){return fcn_cleanTextSelectionFromButtons(window.getSelection().toString())}clearSelection(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.selection&&document.selection.empty()}getDiff(t,e){const n=this.dmp.diff_main(t,e);return this.dmp.diff_cleanupEfficiency(n),this.dmp.fcn_prettyHtml(n)}toggleTools(t){fcn_theSite.classList.contains("transformed-site")||window.getSelection().rangeCount<1||!window.getSelection().getRangeAt(0).startContainer.parentNode.closest(".content-section")||setTimeout((()=>{if(t.text=t.textSelection().replaceAll("\n\n","\n"),""!==t.text){const e=t.getCaretCoordinates();t.showTools(e.y,e.x)}else t.hideTools()}),10)}toggleViaParagraphTools(t){fcn_theSite.classList.contains("transformed-site")||(t.text=_$(".selected-paragraph").querySelector(".paragraph-inner").innerText,t.showModal(t))}resizeInput(){this.input.style.height="auto",this.input.style.height=`${fcn_clamp(32,108,this.input.scrollHeight+4)}px`}showModal(t){fcn_lastSelectedParagraphId&&fcn_toggleParagraphTools(!1),t.original=t.text,t.current.innerHTML=t.text.replaceAll("\n","<br>"),t.input.value=t.text,t.output.innerHTML=t.getDiff(t.original,t.text),t.paragraph=t.getClosestParagraph(),t.toggle.click(),t.toggle.checked=!0,t.clearSelection(),t.hideTools(),t.resizeInput(),t.input.focus()}editSuggestion(t){t.resizeInput(),t.output.innerHTML=t.getDiff(t.original,t.input.value)}resetSuggestion(t){t.input.value=t.original,t.resizeInput(),t.output.innerHTML=t.getDiff(t.original,t.original)}submitSuggestion(t){const e=_$(fictioneer_comments.form_selector??"#comment"),n=t.paragraph?.id??null;let a=t.output.innerHTML;[["¶","&para;\n"],["<br>","\n"],["<ins>","[ins]"],["</ins>","[/ins]"],["<del>","[del]"],["</del>","[/del]"]].forEach((([t,e])=>{a=a.replaceAll(t,e)})),t.latest=`\n[quote]${a} [anchor]${n}[/anchor][/quote]\n`,e?"TEXTAREA"==e.tagName?(e.value+=t.latest,fcn_textareaAdjust(_$("textarea#comment"))):"DIV"==e.tagName&&(e.innerHTML+=t.latest):fcn_commentStack?.push(t.latest),t.toggle.click(),t.toggle.checked=!1,fcn_showNotification(fictioneer_tl.notification.suggestionAppendedToComment)}bindEvents(){this.chapter?.addEventListener("mouseup",this.toggleTools.bind(null,this)),this.button?.addEventListener("click",this.showModal.bind(null,this)),this.toolsButton?.addEventListener("click",this.toggleViaParagraphTools.bind(null,this)),this.input?.addEventListener("input",this.editSuggestion.bind(null,this)),this.reset?.addEventListener("click",this.resetSuggestion.bind(null,this)),this.submit?.addEventListener("click",this.submitSuggestion.bind(null,this))}}const fcn_suggestions=_$(".chapter__article")&&_$(".comment-section")&&_$$$("selection-tools")?new FCN_Suggestion:null;fcn_suggestions&&document.addEventListener("click",(function(t){t.target.closest(".content-section")||fcn_suggestions.hideTools()}));const fcn_ttsInterface=_$$$("tts-interface");var fcn_utter,fcn_synth,fcn_ttsStack=[],fcn_currentReadingId=-1,fcn_ttsPauseTimestamp=-1,fcn_ttsCurrentText="",fcn_ttsSettings=fcn_getTTSsettings(),fcn_voices=[];if("undefined"!=typeof speechSynthesis&&fcn_ttsInterface){fcn_synth=window.speechSynthesis,(fcn_utter=new SpeechSynthesisUtterance).lang=fcn_theRoot.lang;const t=setTimeout((()=>{fcn_setupTTS()}),2e3);"onvoiceschanged"in speechSynthesis&&fcn_synth.addEventListener("voiceschanged",(()=>{fcn_setupTTS(),clearTimeout(t)}),{once:!0})}function fcn_setupTTS(){fcn_voices.length>0||(fcn_setUpVoices(),fcn_updateVolume(fcn_ttsSettings.volume),fcn_updatePitch(fcn_ttsSettings.pitch),fcn_updateRate(fcn_ttsSettings.rate))}function fcn_setTTSsettings(t){fcn_ttsSettings=t,localStorage.setItem("ttsSettings",JSON.stringify(t))}function fcn_getTTSsettings(){const t=fcn_parseJSON(localStorage.getItem("ttsSettings"))??{};return fcn_setTTSsettings(t),t}function fcn_setUpVoices(){const t=fcn_synth.getVoices(),e=_$$$("tts-voice-select");if(!e)return;let n=0;for(let a=0;a<t.length;a++){const o=t[a];fcn_voices.push(o);const c=document.createElement("option");c.value=n,c.innerHTML=`${o.name} (${o.lang})`,e.appendChild(c),n++}fcn_voices.length<1?_$(".tts-settings__voice-selection")?.remove():(e.addEventListener("change",(t=>{fcn_updateVoice(t.currentTarget.value)})),fcn_updateVoice(fcn_ttsSettings.voice))}function fcn_updateVoice(t){if(isNaN(t)||void 0===fcn_voices[t]){let e=fcn_voices.findIndex((t=>"Samantha"===t.name&&("en-US"===t.lang||"en_US"===t.lang)));e<0&&(e=fcn_voices.findIndex((t=>"en-US"===t.lang||"en_US"===t.lang))),t=e>-1?e:0}fcn_utter.voice=fcn_voices[t],_$$$("tts-voice-select").value=t,fcn_ttsSettings.voice=t,fcn_setTTSsettings(fcn_ttsSettings)}function fcn_updateVolume(t){t=fcn_clamp(0,100,t=isNaN(t)?100:parseInt(t)),_$$$("tts-volume-range").value=t,_$$$("tts-volume-text").value=t,_$$$("tts-volume-reset").classList.toggle("_modified",100!=t),fcn_ttsSettings.volume=t,fcn_setTTSsettings(fcn_ttsSettings),fcn_utter.volume=t/100}function fcn_updatePitch(t){t=fcn_clamp(.2,1.8,t=isNaN(t)?1:parseFloat(t)),_$$$("tts-pitch-range").value=t,_$$$("tts-pitch-text").value=t,_$$$("tts-pitch-reset").classList.toggle("_modified",1!=t),fcn_ttsSettings.pitch=t,fcn_setTTSsettings(fcn_ttsSettings),fcn_utter.pitch=t}function fcn_updateRate(t){t=fcn_clamp(.2,1.8,t=isNaN(t)?1:parseFloat(t)),_$$$("tts-rate-range").value=t,_$$$("tts-rate-text").value=t,_$$$("tts-rate-reset").classList.toggle("_modified",1!=t),fcn_ttsSettings.rate=t,fcn_setTTSsettings(fcn_ttsSettings),fcn_utter.rate=t}function fcn_readTextStack(){const t=_$(".current-reading");if(0===fcn_ttsStack.length)return fcn_ttsInterface.classList.add("ended"),t&&t.classList.remove("current-reading"),fcn_currentReadingId=-1,void(fcn_ttsCurrentText="");const e=fcn_ttsStack.shift();fcn_ttsCurrentText=e[1],fcn_currentReadingId!=e[0]&&(fcn_currentReadingId=e[0],t&&t.classList.remove("current-reading"),_$$$(fcn_currentReadingId).classList.add("current-reading")),fcn_utter.text=fcn_ttsCurrentText,fcn_utter.addEventListener("end",fcn_readTextStack,{once:!0}),fcn_synth.speak(fcn_utter)}"undefined"!=typeof speechSynthesis&&fcn_ttsInterface&&(_$$$("button-tts-set").addEventListener("click",(t=>{fcn_ttsStack=[],fcn_currentReadingId=-1;const e=_$(".chapter-formatting")?.classList.contains("hide-sensitive")??!1?"sensitive-content":"sensitive-alternative",n=_$$$("button-tts-play"),a=new RegExp(fcn_ttsInterface.dataset.regex,"gm");fcn_synth.speaking&&fcn_utter.removeEventListener("end",fcn_readTextStack),fcn_synth.cancel();const o=new Set(["P","H1","H2","H3","H4","H5","H6"]),c=["skip-tts","inside-epub",e];let s=t.target.closest("p[data-paragraph-id]");for(fcn_ttsStack.push(s);s=s.nextElementSibling;)o.has(s.tagName)&&!c.some((t=>s.classList.contains(t)))&&fcn_ttsStack.push(s);fcn_ttsStack=fcn_ttsStack.flatMap((t=>{const e=[],n=t.querySelector(".paragraph-inner");return(n?n.textContent:t.textContent).replace(a,"$1|").split("|").forEach((n=>{const a=n.trim();a.length>0&&e.push([t.id,a])})),e})),fcn_readTextStack(),fcn_theBody.classList.add("tts-open"),fcn_ttsInterface.classList.remove("hidden","ended","paused"),fcn_ttsInterface.classList.add("playing"),n.focus(),n.blur()})),_$$$("button-tts-stop")?.addEventListener("click",(()=>{const t=_$(".current-reading");fcn_ttsInterface.classList.add("hidden","ended"),fcn_ttsInterface.classList.remove("playing","paused"),fcn_theBody.classList.remove("tts-open"),t&&t.classList.remove("current-reading"),fcn_ttsStack=[],fcn_currentReadingId=-1,fcn_utter.removeEventListener("end",fcn_readTextStack),fcn_synth.cancel()})),_$$$("button-tts-play")?.addEventListener("click",(()=>{fcn_synth.resume(),-1!==fcn_ttsPauseTimestamp&&Date.now()-fcn_ttsPauseTimestamp>1e4&&(fcn_ttsStack.unshift([fcn_currentReadingId,fcn_ttsCurrentText]),fcn_synth.cancel(),fcn_readTextStack(),fcn_ttsPauseTimestamp=-1),fcn_ttsInterface.classList.add("playing"),fcn_ttsInterface.classList.remove("paused")})),_$$$("button-tts-pause")?.addEventListener("click",(()=>{fcn_synth.pause(),fcn_ttsPauseTimestamp=Date.now(),fcn_ttsInterface.classList.remove("playing"),fcn_ttsInterface.classList.add("paused")})),_$$$("button-tts-skip")?.addEventListener("click",(()=>{fcn_utter.removeEventListener("end",fcn_readTextStack),fcn_synth.cancel(),fcn_readTextStack(),fcn_ttsInterface.classList.remove("paused"),fcn_ttsInterface.classList.add("playing")})),_$$$("button-tts-scroll")?.addEventListener("click",(()=>{fcn_scrollTo(_$(`p[id="${fcn_currentReadingId}"]`),128)})),_$$("#tts-volume-range, #tts-volume-text").forEach((t=>{t.addEventListener("input",(t=>{fcn_updateVolume(t.target.value)}))})),_$$$("tts-volume-reset")?.addEventListener("click",(()=>{fcn_updateVolume(100)})),_$$("#tts-pitch-range, #tts-pitch-text").forEach((t=>{t.addEventListener("input",(t=>{fcn_updatePitch(t.target.value)}))})),_$$$("tts-pitch-reset")?.addEventListener("click",(()=>{fcn_updatePitch(1)})),_$$("#tts-rate-range, #tts-rate-text").forEach((t=>{t.addEventListener("input",(t=>{fcn_updateRate(t.target.value)}))})),_$$$("tts-rate-reset")?.addEventListener("click",(()=>{fcn_updateRate(1)})),window.addEventListener("beforeunload",(()=>{fcn_synth.cancel()})));var fcn_storyCommentPage=1,fcn_storySettings=fcn_getStorySettings();function fcn_getStorySettings(){let t=fcn_parseJSON(localStorage.getItem("fcnStorySettings"))??fcn_defaultStorySettings();return t.timestamp<1674770712849&&(t=fcn_defaultStorySettings(),t.timestamp=Date.now()),fcn_setStorySettings(t),t}function fcn_defaultStorySettings(){return{view:"list",order:"asc",timestamp:1674770712849}}function fcn_setStorySettings(t){"object"==typeof t&&(fcn_storySettings=t,localStorage.setItem("fcnStorySettings",JSON.stringify(t)))}function fcn_applyStorySettings(){"object"==typeof fcn_storySettings&&(_$$("[data-view]").forEach((t=>{t.dataset.view="grid"==fcn_storySettings.view?"grid":"list"})),_$$("[data-order]").forEach((t=>{t.dataset.order="desc"==fcn_storySettings.order?"desc":"asc"})))}function fcn_toggleStoryTab(t){const e=t.closest(".story");e.querySelectorAll(".story__tab-target._current, .story__tabs ._current").forEach((t=>{t.classList.remove("_current")})),e.querySelectorAll(`[data-finder="${t.dataset.target}"]`).forEach((t=>{t.classList.add("_current")})),e.querySelector(".story__tabs").dataset.current=t.dataset.target,t.classList.add("_current")}function fcn_loadStoryComments(t){let e;_$(".load-more-list-item").remove(),_$(".comments-loading-placeholder").classList.remove("hidden"),fcn_ajaxGet({post_id:t.dataset.storyId??fcn_inlineStorage.postId,page:fcn_storyCommentPage},"get_story_comments").then((t=>{t.success?(_$(".fictioneer-comments__list > ul").innerHTML+=t.data.html,fcn_storyCommentPage++):t.data?.error&&(e=fcn_buildErrorNotice(t.data.error))})).catch((t=>{e=fcn_buildErrorNotice(t)})).then((()=>{_$(".comments-loading-placeholder").remove(),e&&_$(".fictioneer-comments__list > ul").appendChild(e)}))}function fcn_startEpubDownload(t,e=0){e>3?t.classList.remove("ajax-in-progress"):fcn_ajaxGet({action:"fictioneer_ajax_download_epub",story_id:t.dataset.storyId}).then((n=>{n.success?(window.location.href=t.href,setTimeout((()=>{t.classList.remove("ajax-in-progress")}),2e3)):setTimeout((()=>{fcn_startEpubDownload(t,e+1)}),2e3)})).catch((e=>{t.classList.remove("ajax-in-progress"),e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")}))}function fcn_replaceProfileImage(t,e){const n=t.querySelector(".user-icon");if(n){const a=document.createElement("img");a.classList.add("user-profile-image"),a.src=e,n.remove(),t.appendChild(a)}}function fcn_setProfileImage(t,e=!0){t&&fcn_isValidUrl(t)&&(e&&localStorage.setItem("fcnProfileAvatar",t),_$$("a.subscriber-profile")?.forEach((e=>{fcn_replaceProfileImage(e,t)})),!1===fcn_getUserData().loggedIn&&fcn_prepareLogin())}function fcn_getProfileImage(){let t=localStorage.getItem("fcnProfileAvatar");fcn_isLoggedIn?(fcn_isValidUrl(t)||(t=!1),t?fcn_setProfileImage(t):fcn_getUserAvatar()):localStorage.removeItem("fcnProfileAvatar")}function fcn_getUserAvatar(){fcn_ajaxGet({action:"fictioneer_ajax_get_avatar",fcn_fast_ajax:1}).then((t=>{t.success&&fcn_setProfileImage(t.data.url)})).catch((()=>{fcn_theRoot.dataset.defaultAvatar&&fcn_setProfileImage(fcn_theRoot.dataset.defaultAvatar,!1)}))}function fcn_getUserData(){return fcn_parseJSON(localStorage.getItem("fcnUserData"))??{lastLoaded:0,timestamp:0,loggedIn:"pending",follows:!1,reminders:!1,checkmarks:!1,bookmarks:{},fingerprint:!1}}function fcn_setUserData(t){localStorage.setItem("fcnUserData",JSON.stringify(t))}function fcn_fetchUserData(){let t=fcn_getUserData();if(fcn_isLoggedIn&&!1===t.loggedIn&&(fcn_prepareLogin(),t=fcn_getUserData()),fcn_ajaxLimitThreshold<t.lastLoaded||!1===t.loggedIn)if(t.loggedIn){const e=new CustomEvent("fcnUserDataReady",{detail:{data:t,time:new Date},bubbles:!1,cancelable:!0});document.dispatchEvent(e)}else{const e=new CustomEvent("fcnUserDataFailed",{detail:{response:t,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(e)}else fcn_ajaxGet({action:"fictioneer_ajax_get_user_data",fcn_fast_ajax:1}).then((t=>{if(t.success){let e=fcn_getUserData();e=t.data,e.lastLoaded=Date.now(),fcn_setUserData(e);const n=new CustomEvent("fcnUserDataReady",{detail:{data:t.data,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(n)}else{const e=fcn_getUserData();e.lastLoaded=Date.now(),e.loggedIn=!1,fcn_setUserData(e);const n=new CustomEvent("fcnUserDataFailed",{detail:{response:t,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(n)}})).catch((t=>{localStorage.removeItem("fcnUserData");const e=new CustomEvent("fcnUserDataError",{detail:{error:t,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(e)}))}function fcn_unsetOauth(t){const e=prompt(t.dataset.warning);if(!e||e.toLowerCase()!=t.dataset.confirm.toLowerCase())return;const n=_$$$(`oauth-${t.dataset.channel}`);n.classList.add("ajax-in-progress"),fcn_ajaxPost(payload={action:"fictioneer_ajax_unset_my_oauth",nonce:t.dataset.nonce,channel:t.dataset.channel,id:t.dataset.id}).then((t=>{t.success?(n.classList.remove("_connected"),n.classList.add("_disconnected"),n.querySelector("button").remove(),fcn_showNotification(n.dataset.unset)):(n.style.background="var(--notice-warning-background)",fcn_showNotification(t.data.error,5,"warning"))})).catch((t=>{t.status&&t.statusText&&(n.style.background="var(--notice-warning-background)",fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"))})).then((()=>{n.classList.remove("ajax-in-progress")}))}function fcn_deleteMyAccount(t){if(_$$$("button-delete-my-account").hasAttribute("disabled"))return;const e=prompt(t.dataset.warning);e&&e.toLowerCase()==t.dataset.confirm.toLowerCase()&&(_$$$("button-delete-my-account").setAttribute("disabled",!0),fcn_ajaxPost({action:"fictioneer_ajax_delete_my_account",nonce:t.dataset.nonce,id:t.dataset.id}).then((t=>{t.success?(localStorage.removeItem("fcnAuth"),localStorage.removeItem("fcnProfileAvatar"),location.reload()):(fcn_showNotification(t.data.error,5,"warning"),_$$$("button-delete-my-account").innerHTML=t.data.button)})).catch((t=>{t.status&&t.statusText&&(fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),
_$$$("button-delete-my-account").innerHTML=response.data.button)})))}fcn_applyStorySettings(),_$$('[data-click-action*="toggle-chapter-order"]').forEach((t=>{t.addEventListener("click",(t=>{fcn_storySettings.order="asc"===t.currentTarget.dataset.order?"desc":"asc",fcn_setStorySettings(fcn_storySettings),fcn_applyStorySettings()}))})),_$$('[data-click-action*="toggle-chapter-view"]').forEach((t=>{t.addEventListener("click",(t=>{fcn_storySettings.view="list"===t.currentTarget.dataset.view?"grid":"list",fcn_setStorySettings(fcn_storySettings),fcn_applyStorySettings()}))})),_$$(".chapter-group__folding-toggle").forEach((t=>{t.addEventListener("click",(t=>{const e=t.currentTarget.closest(".chapter-group[data-folded]");e&&(e.dataset.folded="true"==e.dataset.folded?"false":"true")}))})),_$$(".tabs__item").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleStoryTab(t.currentTarget)}))})),_$(".comment-section")?.addEventListener("click",(t=>{t.target?.classList.contains("load-more-comments-button")&&fcn_loadStoryComments(t.target)})),_$$('[data-action="download-epub"]').forEach((t=>{t.addEventListener("click",(t=>{t.preventDefault(),t.currentTarget.classList.contains("ajax-in-progress")||(t.currentTarget.classList.add("ajax-in-progress"),fcn_startEpubDownload(t.currentTarget))}))})),document.addEventListener("DOMContentLoaded",(()=>{fcn_isLoggedIn&&!fcn_theRoot.dataset.ajaxAuth&&fcn_getProfileImage()})),fcn_theRoot.dataset.ajaxAuth&&document.addEventListener("fcnAuthReady",(()=>{fcn_getProfileImage()})),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_fetchUserData()})):document.addEventListener("DOMContentLoaded",(()=>{fcn_isLoggedIn&&fcn_fetchUserData()})),_$$(".button-unset-oauth").forEach((t=>{t.addEventListener("click",(t=>{fcn_unsetOauth(t.currentTarget)}))})),_$$$("button-delete-my-account")?.addEventListener("click",(t=>{fcn_deleteMyAccount(t.currentTarget)}));const fcn_profileDataTranslations=_$$$("profile-data-translations")?.dataset;function fcn_dataDeletionPrompt(t){const e=prompt(t.dataset.warning);return!(!e||e.toLowerCase()!=t.dataset.confirm.toLowerCase())}function fcn_clearData(t,e){const n=t.closest(".card");localStorage.removeItem("fcnBookshelfContent"),n.classList.add("ajax-in-progress"),t.remove(),fcn_ajaxPost({action:e,fcn_fast_ajax:1,nonce:t.dataset.nonce}).then((t=>{t.success?n.querySelector(".card__content").innerHTML=t.data.success:fcn_showNotification(t.data.error,10,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,10,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")}))}_$(".button-clear-comments")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_comments")})),_$(".button-clear-comment-subscriptions")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_comment_subscriptions")})),_$(".button-clear-checkmarks")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.checkmarks={data:{},updated:Date.now()},fcn_setUserData(e),fcn_updateCheckmarksView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_checkmarks",!0)})),_$(".button-clear-reminders")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.reminders={data:{}},fcn_setUserData(e),fcn_updateRemindersView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_reminders",!0)})),_$(".button-clear-follows")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.follows={data:{}},fcn_setUserData(e),fcn_updateFollowsView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_follows",!0)})),_$(".button-clear-bookmarks")?.addEventListener("click",(t=>{if(!fcn_dataDeletionPrompt(t.currentTarget))return;const e=fcn_getUserData();e.bookmarks="{}",fcn_setUserData(e),fcn_bookmarks.data={},t.currentTarget.closest(".card").querySelector(".card__content").innerHTML=fcn_profileDataTranslations.clearedSuccess,fcn_setBookmarks(fcn_bookmarks)}));const fcn_jumpToBookmarkButtons=_$$(".button--bookmark"),fcn_mobileBookmarkJump=_$$$("mobile-menu-bookmark-jump"),fcn_mobileBookmarkList=_$(".mobile-menu__bookmark-list"),fcn_bookmarksSmallCardBlock=_$(".bookmarks-block"),fcn_bookmarksSmallCardTemplate=_$(".bookmark-small-card-template");var fcn_bookmarks,fcn_userBookmarksTimeout;function fcn_initializeLocalBookmarks(){fcn_setBookmarks(fcn_bookmarks=fcn_getBookmarks(),!0),fcn_updateBookmarksView()}function fcn_initializeUserBookmarks(t){fcn_setBookmarks(JSON.parse(t.detail.data.bookmarks),!0),fcn_updateBookmarksView()}function fcn_getBookmarks(){let t=fcn_parseJSON(localStorage.getItem("fcnChapterBookmarks"))??{data:{}};return Array.isArray(t.data)&&0===t.data.length&&(t.data={}),t=fcn_fixBookmarks(t),!t||Object.keys(t).length<1?{data:{}}:t}function fcn_fixBookmarks(t){const e={};for(const n in t.data)if(n.startsWith("ch-")){const a=fcn_fixBookmarksNode(t.data[n]);a&&(e[n]=a)}return{data:e}}function fcn_fixBookmarksNode(t){const e={},n={"paragraph-id":"",progress:0,date:"",color:"",chapter:"",link:"",thumb:"",image:"",story:"",content:""};for(const a in n){if(typeof t[a]!=typeof n[a])return null;e[a]=t[a]}const a=new Date(e.date);return a&&"[object Date]"===Object.prototype.toString.call(a)&&!isNaN(a)||(e.date=(new Date).toISOString()),("number"!=typeof e.progress||e.progress<0)&&(e.progress=0),e}function fcn_setBookmarks(t,e=!1){if("object"==typeof t){if(fcn_bookmarks=t,localStorage.setItem("fcnChapterBookmarks",JSON.stringify(t)),fcn_isLoggedIn){const e=fcn_getUserData();e&&(e.bookmarks=JSON.stringify(t),fcn_setUserData(e))}e||fcn_saveUserBookmarks(t)}}function fcn_updateBookmarksView(){if(!fcn_bookmarks||!fcn_bookmarks.data)return;const t=_$(".profile-bookmarks-stats"),e=Object.keys(fcn_bookmarks.data).length;t&&(t.innerHTML=t.innerHTML.replace("%s",e)),e>0&&_$$(".icon-menu-bookmarks").forEach((t=>{t.classList.remove("hidden")})),fcn_showBookmarkCards(),fcn_showChapterBookmark()}function fcn_saveUserBookmarks(t){fcn_isLoggedIn&&(clearTimeout(fcn_userBookmarksTimeout),t=fcn_fixBookmarks(t),fcn_userBookmarksTimeout=setTimeout((()=>{fcn_ajaxPost({action:"fictioneer_ajax_save_bookmarks",fcn_fast_ajax:1,bookmarks:JSON.stringify(t)}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,3,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,3,"warning")}))}),fictioneer_ajax.post_debounce_rate))}function fcn_toggleBookmark(t,e="none"){fcn_bookmarks=fcn_getBookmarks();const n=_$(".chapter__article"),a=_$(".current-bookmark");if(!n)return;const o=fcn_bookmarks.data[n.id];if(o&&o["paragraph-id"]==t&&a)"none"!=e&&e!=o.color?(_$(".current-bookmark").dataset.bookmarkColor=e,o.color=e):fcn_removeBookmark(n.id);else{Object.keys(fcn_bookmarks.data).length>=50&&fcn_removeBookmark(Object.keys(fcn_bookmarks.data)[0]);const o=_$(`[data-paragraph-id="${t}"]`),c=_$$$("chapter-bookmark-data").dataset;fcn_bookmarks.data[n.id]={"paragraph-id":t,progress:100*(fcn_offset(o).top-fcn_offset(o.parentElement).top)/o.parentElement.clientHeight,date:(new Date).toISOString(),color:e,chapter:c.title.trim(),link:c.link,thumb:c.thumb,image:c.image,story:c.storyTitle.trim(),content:o.querySelector("span").innerHTML.substring(0,128)+"…"},fcn_jumpToBookmarkButtons.forEach((t=>{t.classList.remove("hidden")})),fcn_mobileBookmarkJump?.removeAttribute("hidden"),a?.classList.remove("current-bookmark"),o.classList.add("current-bookmark"),o.setAttribute("data-bookmark-color",e)}fcn_setMobileMenuBookmarks(),fcn_setBookmarks(fcn_bookmarks)}function fcn_showChapterBookmark(){_$(".current-bookmark")?.classList.remove("current-bookmark");const t=_$(".chapter__article");if(!t||!fcn_bookmarks.data[t.id])return;const e=fcn_bookmarks.data[t.id]["paragraph-id"],n=_$(`[data-paragraph-id="${e}"]`),a=fcn_bookmarks.data[t.id].color??"none";e&&n&&(fcn_jumpToBookmarkButtons.forEach((t=>{t.classList.remove("hidden")})),fcn_mobileBookmarkJump?.removeAttribute("hidden"),n.classList.add("current-bookmark"),n.setAttribute("data-bookmark-color",a))}function fcn_setMobileMenuBookmarks(){fcn_mobileBookmarkList.innerHTML="";const t=Object.entries(fcn_bookmarks.data),e=_$("#mobile-bookmark-template");if(t.length>0){const n=document.createDocumentFragment();t.forEach((([t,{color:a,progress:o,link:c,chapter:s,"paragraph-id":i}])=>{const r=e.content.cloneNode(!0),l=r.querySelector(".mobile-menu__bookmark");l.classList.add(`bookmark-${t}`),l.dataset.color=a,r.querySelector(".mobile-menu__bookmark-progress > div > div").style.width=`${o.toFixed(1)}%`,r.querySelector(".mobile-menu__bookmark a").href=`${c}#paragraph-${i}`,r.querySelector(".mobile-menu__bookmark a span").innerText=s,r.querySelector(".mobile-menu-bookmark-delete-button").setAttribute("data-bookmark-id",t),n.appendChild(r)})),fcn_mobileBookmarkList.appendChild(n),fcn_bookmarkDeleteHandler(_$$(".mobile-menu-bookmark-delete-button"))}else{const t=document.createElement("li");t.classList.add("no-bookmarks"),t.textContent=fcn_mobileBookmarkList.dataset.empty,fcn_mobileBookmarkList.appendChild(t)}}function fcn_showBookmarkCards(){if(!fcn_bookmarks||!fcn_bookmarksSmallCardBlock||!fcn_bookmarksSmallCardTemplate||Object.keys(fcn_bookmarks.data).length<1||_$(".bookmark-card"))return;fcn_bookmarksSmallCardBlock.classList.remove("hidden"),_$(".bookmarks-block__no-bookmarks")?.remove(),_$$(".show-if-bookmarks").forEach((t=>t.classList.remove("hidden")));let t=parseInt(fcn_bookmarksSmallCardBlock.dataset.count);const e=document.createDocumentFragment();Object.entries(fcn_bookmarks.data).sort(((t,e)=>new Date(e[1].date)-new Date(t[1].date))).forEach((([n,{color:a,progress:o,link:c,chapter:s,"paragraph-id":i,date:r,image:l,thumb:f,content:d}])=>{if(0==t)return;t--;const _=fcn_bookmarksSmallCardTemplate.content.cloneNode(!0),u=new Date(r).toLocaleDateString(navigator.language??"en-US",{year:"2-digit",month:"short",day:"numeric"});l&&_.querySelector(".bookmark-card__image")?(_.querySelector(".bookmark-card__image").href=l,_.querySelector(".bookmark-card__image img").src=f):_.querySelector(".bookmark-card__image")?.remove(),_.querySelector(".bookmark-card__excerpt").innerHTML+=d,_.querySelector(".bookmark-card").classList.add(`bookmark-${n}`),_.querySelector(".bookmark-card").dataset.color=a,_.querySelector(".bookmark-card__title > a").href=`${c}#paragraph-${i}`,_.querySelector(".bookmark-card__title > a").innerText=s,_.querySelector(".bookmark-card__percentage").innerText=`${o.toFixed(1)} %`,_.querySelector(".bookmark-card__progress").style.width=`calc(${o.toFixed(1)}% - var(--bookmark-progress-offset, 0px))`,_.querySelector("time").innerText=u,_.querySelector(".button-delete-bookmark").setAttribute("data-bookmark-id",n),e.appendChild(_)})),fcn_bookmarksSmallCardBlock.querySelector("ul").appendChild(e),fcn_bookmarkDeleteHandler(_$$(".button-delete-bookmark"))}function fcn_bookmarkDeleteHandler(t){("object"==typeof t?t:[t]).forEach((t=>{t.addEventListener("click",(t=>{fcn_removeBookmark(t.currentTarget.dataset.bookmarkId),fcn_setBookmarks(fcn_bookmarks),Object.keys(fcn_bookmarks.data).length<1&&(_$(".bookmarks-block")?.classList.add("hidden"),_$$(".show-if-bookmarks").forEach((t=>{t.classList.add("hidden")})))}))}))}function fcn_removeBookmark(t){const e=_$(".chapter__article"),n=_$(".current-bookmark");delete fcn_bookmarks.data[t],e&&e.id==t&&(fcn_jumpToBookmarkButtons.forEach((t=>{t.classList.add("hidden")})),fcn_mobileBookmarkJump?.setAttribute("hidden",!0),n&&(n.classList.remove("current-bookmark"),n.removeAttribute("data-bookmark-color"))),_$$(`.bookmark-${t}`)?.forEach((t=>{t.remove()}))}fcn_initializeLocalBookmarks(),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeUserBookmarks(t)})),fcn_jumpToBookmarkButtons.forEach((t=>{t.addEventListener("click",(()=>{_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`).scrollIntoView({behavior:"smooth"})}))}));const fcn_followsMenuItem=_$$$("follow-menu-button");var fcn_userFollowsTimeout,fcn_follows,fcn_checkmarks,fcn_userCheckmarksTimeout,fcn_userRemindersTimeout,fcn_reminders;function fcn_initializeFollows(t){const e=t.detail.data.follows;!1!==e&&(Array.isArray(e.data)&&0===e.data.length&&(e.data={}),fcn_follows=e,fcn_updateFollowsView(),localStorage.removeItem("fcnBookshelfContent"))}function fcn_toggleFollow(t){const e=fcn_getUserData();if(fcn_follows&&e.follows){if(localStorage.removeItem("fcnBookshelfContent"),JSON.stringify(fcn_follows.data[t])!==JSON.stringify(e.follows.data[t]))return fcn_follows=e.follows,fcn_showNotification(fictioneer_tl.notification.followsResynchronized),void fcn_updateFollowsView();fcn_follows.data[t]?delete fcn_follows.data[t]:fcn_follows.data[t]={story_id:parseInt(t),timestamp:Date.now()},e.follows.data[t]=fcn_follows.data[t],e.lastLoaded=0,fcn_setUserData(e),fcn_updateFollowsView(),clearTimeout(fcn_userFollowsTimeout),fcn_userFollowsTimeout=setTimeout((()=>{fcn_ajaxPost({action:"fictioneer_ajax_toggle_follow",fcn_fast_ajax:1,story_id:t,set:!!fcn_follows.data[t]}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{429===t.status?fcn_showNotification(fictioneer_tl.notification.slowDown,3,"warning"):t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}),fictioneer_ajax.post_debounce_rate)}}function fcn_updateFollowsView(){const t=fcn_getUserData();if(!fcn_follows||!t.follows)return;_$$(".button-follow-story").forEach((t=>{t.classList.toggle("_followed",!!fcn_follows?.data[t.dataset.storyId])})),_$$(".card").forEach((t=>{t.classList.toggle("has-follow",!!fcn_follows?.data[t.dataset.storyId])}));const e=parseInt(fcn_follows.new)>0;_$$(".mark-follows-read, .follows-alert-number, .mobile-menu-button").forEach((t=>{t.classList.toggle("_new",e),e>0&&(t.dataset.newCount=fcn_follows.new)}))}function fcn_setupFollowsHTML(){fcn_followsMenuItem.classList.contains("_loaded")||fcn_ajaxGet({action:"fictioneer_ajax_get_follows_notifications",fcn_fast_ajax:1}).then((t=>{if(t.data.html){const e=_$$$("follow-menu-scroll");e&&(e.innerHTML=t.data.html);const n=_$$$("mobile-menu-follows-list");n&&(n.innerHTML=t.data.html),!1===fcn_getUserData().loggedIn&&(fcn_prepareLogin(),fcn_fetchUserData())}})).catch((t=>{429===t.status?fcn_showNotification(fictioneer_tl.notification.slowDown,3,"warning"):t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),_$$$("follow-menu-scroll")?.remove(),_$$$("mobile-menu-follows-list")?.remove()})).then((()=>{fcn_followsMenuItem.classList.add("_loaded")}))}function fcn_markFollowsRead(){if(!fcn_followsMenuItem.classList.contains("_new")||!fcn_followsMenuItem.classList.contains("_loaded"))return;_$$(".mark-follows-read, .follows-alert-number, .follow-item, .mobile-menu-button").forEach((t=>{t.classList.remove("_new")}));const t=fcn_getUserData();t.new=0,t.lastLoaded=0,fcn_setUserData(t),fcn_ajaxPost({action:"fictioneer_ajax_mark_follows_read",fcn_fast_ajax:1}).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}function fcn_initializeCheckmarks(t){const e=t.detail.data.checkmarks;!1!==e&&(Array.isArray(e.data)&&0===e.data.length&&(e.data={}),fcn_checkmarks=e,fcn_updateCheckmarksView(),localStorage.removeItem("fcnBookshelfContent"),_$$("button.checkmark").forEach((t=>{t.addEventListener("click",(t=>{fcn_clickCheckmark(t.currentTarget)}))})))}function fcn_toggleCheckmark(t,e,n=null,a=null,o="toggle"){const c=fcn_getUserData();if(fcn_checkmarks&&c.checkmarks){if(localStorage.removeItem("fcnBookshelfContent"),"toggle"===o&&JSON.stringify(fcn_checkmarks.data[t])!==JSON.stringify(c.checkmarks.data[t]))return fcn_checkmarks=c.checkmarks,fcn_showNotification(fictioneer_tl.notification.checkmarksResynchronized),void fcn_updateCheckmarksView();if(fcn_checkmarks.data[t]||(fcn_checkmarks.data[t]=[]),c.checkmarks.data[t]||(c.checkmarks.data[t]=[]),n&&"progress"===e&&!fcn_checkmarks.data[t].includes(n)&&fcn_checkmarks.data[t].push(n),n&&"chapter"===e)if(!fcn_checkmarks.data[t].includes(n)&&"unset"!==o||"set"===o)fcn_checkmarks.data[t].push(n),a&&(a.classList.add("marked"),a.setAttribute("aria-checked",!0));else{fcn_removeItemOnce(fcn_checkmarks.data[t],n),a&&(a.classList.remove("marked"),a.setAttribute("aria-checked",!1)),fcn_removeItemOnce(fcn_checkmarks.data[t],t);const e=_$('button[data-type="story"]');e&&(e.classList.remove("marked"),e.setAttribute("aria-checked",!1))}if("story"===e){const e=(fcn_checkmarks.data[t].includes(t)||"unset"===o)&&"set"!==o;fcn_checkmarks.data[t]=[],e||(_$$("button.checkmark").forEach((e=>{fcn_checkmarks.data[t].push(parseInt(e.dataset.id))})),fcn_checkmarks.data[t].includes(t)||fcn_checkmarks.data[t].push(t))}fcn_checkmarks.data[t]=fcn_checkmarks.data[t].filter(((t,e,n)=>n.indexOf(t)==e)),c.checkmarks.data[t]=fcn_checkmarks.data[t],c.lastLoaded=0,fcn_setUserData(c),fcn_updateCheckmarksView(),clearTimeout(fcn_userCheckmarksTimeout),fcn_userCheckmarksTimeout=setTimeout((()=>{fcn_updateCheckmarks(t,fcn_checkmarks.data[t])}),fictioneer_ajax.post_debounce_rate)}}function fcn_clickCheckmark(t){fcn_toggleCheckmark(parseInt(t.dataset.storyId),t.dataset.type,parseInt(t.dataset.id),t)}function fcn_updateCheckmarks(t,e=null){fcn_ajaxPost({action:"fictioneer_ajax_set_checkmark",fcn_fast_ajax:1,story_id:t,update:(e=e||fcn_getUserData().checkmarks.data[t]).join(" ")}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,3,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}function fcn_updateCheckmarksView(){const t=fcn_getUserData(),e=t.checkmarks;if(!e)return;const n=parseInt(fcn_inlineStorage.storyId);if(n){const a=e.data[n]&&e.data[n].includes(n);if(a){let a=!1;_$$("button.checkmark").forEach((t=>{const o=parseInt(t.dataset.id);e.data[n].includes(o)||(e.data[n].push(o),a=!0)})),a&&(t.checkmarks=e,fcn_setUserData(t),fcn_updateCheckmarks(n,e.data[n]))}_$$$("ribbon-read")?.classList.toggle("hidden",!a)}_$$("button.checkmark").forEach((t=>{const n=parseInt(t.dataset.storyId);if(e.data[n]){const a=e.data[n].includes(parseInt(t.dataset.id));t.classList.toggle("marked",a),t.setAttribute("aria-checked",a)}})),_$$(".card").forEach((t=>{const n=parseInt(t.dataset.storyId),a=e.data[n]&&(e.data[n].includes(parseInt(t.dataset.checkId))||e.data[n].includes(n));t.classList.toggle("has-checkmark",1==a)}))}function fcn_initializeReminders(t){const e=t.detail.data.reminders;!1!==e&&(Array.isArray(e.data)&&0===e.data.length&&(e.data={}),fcn_reminders=e,fcn_updateRemindersView(),localStorage.removeItem("fcnBookshelfContent"))}function fcn_toggleReminder(t){const e=fcn_getUserData();if(fcn_reminders&&e.reminders){if(localStorage.removeItem("fcnBookshelfContent"),JSON.stringify(fcn_reminders.data[t])!==JSON.stringify(e.reminders.data[t]))return fcn_reminders=e.reminders,fcn_showNotification(fictioneer_tl.notification.remindersResynchronized),void fcn_updateRemindersView();fcn_reminders.data[t]?delete fcn_reminders.data[t]:fcn_reminders.data[t]={story_id:parseInt(t),timestamp:Date.now()},e.reminders.data[t]=fcn_reminders.data[t],e.lastLoaded=0,fcn_setUserData(e),fcn_updateRemindersView(),clearTimeout(fcn_userRemindersTimeout),fcn_userRemindersTimeout=setTimeout((()=>{fcn_ajaxPost({action:"fictioneer_ajax_toggle_reminder",fcn_fast_ajax:1,story_id:t,set:!!fcn_reminders.data[t]}).then((t=>{t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{429===t.status?fcn_showNotification(fictioneer_tl.notification.slowDown,3,"warning"):t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")}))}),fictioneer_ajax.post_debounce_rate)}}function fcn_updateRemindersView(){const t=fcn_getUserData();fcn_reminders&&t.reminders&&(_$$(".button-read-later").forEach((t=>{t.classList.toggle("_remembered",!!fcn_reminders.data[t.dataset.storyId])})),_$$(".card").forEach((t=>{t.classList.toggle("has-reminder",!!fcn_reminders.data[t.dataset.storyId])})))}function fcn_addJSTrap(){const t=document.querySelector(".comment-form");t&&t.appendChild(fcn_html`
<input type="hidden" name="fictioneer_comment_validator" value="299792458">
`)}function fcn_moderateComment(t,e){const n=_$$$(`comment-${t}`),a=n.querySelector(".mod-menu-toggle-icon");n.classList.contains("ajax-in-progress")||(n.classList.add("ajax-in-progress"),"trash"!=e&&"spam"!=e||(n.style.height=n.clientHeight+"px"),fcn_ajaxPost({action:"fictioneer_ajax_moderate_comment",operation:e,id:t,fcn_fast_comment_ajax:1}).then((t=>{if(t.success)switch(t.data.operation){case"sticky":n.classList.add("_sticky");break;case"unsticky":n.classList.remove("_sticky");break;case"approve":n.classList.remove("_unapproved");break;case"unapprove":n.classList.add("_unapproved");break;case"open":n.classList.remove("_closed");break;case"close":n.classList.add("_closed");break;case"trash":case"spam":n.style.cssText="overflow: hidden; height: 0; margin: 0; opacity: 0;"}else a.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",a.style.color="var(--notice-warning-background)",n.querySelector(".popup-menu-toggle").style.opacity="1",t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{a.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",a.style.color="var(--notice-warning-background)",n.querySelector(".popup-menu-toggle").style.opacity="1",t.status&&t.statusText?fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"):t&&fcn_showNotification(t,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),fcn_lastClicked?.classList.remove("last-clicked"),fcn_lastClicked=null})))}function fcn_addCommentMouseleaveEvents(){_$$(".fictioneer-comment__container").forEach((t=>{t.addEventListener("mouseleave",(t=>{fcn_lastClicked?.classList.remove("last-clicked"),fcn_lastClicked=null,t.stopPropagation()}))}))}function fcn_flagComment(t){if(!fcn_isLoggedIn)return;const e=t.closest(".fictioneer-comment"),n=e.querySelector(".fictioneer-report-comment-button");e.classList.contains("ajax-in-progress")||(e.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_report_comment",id:e.dataset.id,dubious:n.classList.contains("_dubious"),fcn_fast_comment_ajax:1}).then((t=>{t.success?(n.classList.toggle("on",t.data.flagged),n.classList.remove("_dubious"),t.data.resync&&fcn_showNotification(t.data.resync)):t.data?.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{e.classList.remove("ajax-in-progress")})))}function fcn_revealCommentFormInputs(t){t.closest("form").querySelectorAll(".fictioneer-respond__form-actions, .fictioneer-respond__form-bottom").forEach((t=>{t.classList.remove("hidden")}))}function fcn_addCommentFormEvents(){_$(fictioneer_comments.form_selector??"#comment")?.addEventListener("focus",(t=>{fcn_revealCommentFormInputs(t.currentTarget)}),{once:!0})}function fcn_textareaAdjust(t){t&&(t.style.height="auto",t.style.height=`${t.scrollHeight}px`)}function fcn_wrapInTag(t,e,n={}){const a=n.href?' href="'+n.href+'" target="_blank" rel="nofollow noreferrer noopener"':"",o=n.shortcode?["[","]"]:["<",">"],c=t.selectionStart,s=t.selectionEnd,i=o[0]+e+a+o[1],r=o[0]+"/"+e+o[1],l=i+t.value.substring(c,s)+r;t.value=t.value.substring(0,c)+l+t.value.substring(s,t.value.length),t.setSelectionRange(c+i.length,s+i.length),t.focus()}function fcn_bindAJAXCommentSubmit(){fcn_theRoot.dataset.ajaxSubmit&&_$$$("commentform")?.addEventListener("submit",(t=>{if(t.preventDefault(),Date.now()<fcn_pageLoadTimestamp+3e3)return;const e=t.currentTarget,n=new FormData(e),a=Object.fromEntries(n.entries()),o=e.querySelector('[name="submit"]'),c=_$(fictioneer_comments.form_selector??"#comment"),s=e.querySelector('[name="author"]'),i=e.querySelector('[name="email"]'),r=e.querySelector('[name="fictioneer-privacy-policy-consent"]'),l=a.comment_parent??0,f=_$$$(`comment-${l}`),d=e.closest(".fictioneer-comments")?.dataset.order??"desc";let _=!0,u=!0,h=!0;if(u=c.value.length>1,c.classList.toggle("_error",!u),r&&(h=r.checked,r.classList.toggle("_error",!h)),i&&i.value.length>0&&(_=/\S+@\S+\.\S+/.test(i.value),i.classList.toggle("_error",!_)),!u||!h||!_)return!1;e.classList.add("ajax-in-progress"),o.disabled=!0,o.value=o.dataset.disabled;const g={action:"fictioneer_ajax_submit_comment",content:c.value,depth:f?parseInt(f.dataset.depth)+1:1,fcn_fast_comment_ajax:1,...a};i?.value&&(g.email=i?.value),s?.value&&(g.author=s?.value),fcn_ajaxPost(g).then((t=>{if(_$$$("comment-submit-error-notice")?.remove(),t.success&&t.data?.comment){let e=_$(".commentlist"),n="insertBefore";if(e&&!f&&e.firstElementChild){let t=null;if(e.firstElementChild.classList.contains("_sticky"))for(t=e.firstElementChild,e=t,n="insertAfter";t.nextElementSibling&&t.nextElementSibling.classList.contains("_sticky");)t=e.nextElementSibling,e=t}if(e||(e=document.createElement("ol"),e.classList="fictioneer-comments__list commentlist",_$$$("comments").appendChild(e),n="append"),f&&(e=f.querySelector(".children"),n="append",!e)){const t=document.createElement("ol");f.appendChild(t),e=t}let a=document.createElement("div");switch(a.innerHTML=t.data.comment,a=a.firstChild,n){case"append":e.appendChild(a);break;case"insertBefore":e.insertBefore(a,e.firstChild);break;case"insertAfter":e.nextSibling?e.parentNode.insertBefore(a,e.nextSibling):e.parentNode.appendChild(a)}fcn_addCommentMouseleaveEvents(),"0"!=_$$$("comment_parent").value&&_$$$("cancel-comment-reply-link").click(),c.value="",c.style.height="";const o=window.location.protocol+"//"+window.location.host+window.location.pathname;let s="";t.data.commentcode&&(s+=`?commentcode=${t.data.commentcode}`),"desc"!=d&&(s+=s.length>1?`&corder=${d}`:`?corder=${d}`),history.pushState({path:o},"",o+s+`#comment-${t.data.comment_id}`),a.scrollIntoView({behavior:"smooth"})}else e.insertBefore(fcn_buildErrorNotice(t.data?.error??fictioneer_tl.notification.error,"comment-submit-error-notice",!1),e.firstChild)})).catch((t=>{_$$$("comment-submit-error-notice")?.remove(),e.insertBefore(fcn_buildErrorNotice(`${t.status}: ${t.statusText}`,"comment-submit-error-notice"),e.firstChild)})).then((()=>{e.classList.remove("ajax-in-progress"),o.disabled=!1,o.value=o.dataset.enabled}))}))}document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeFollows(t)})),fcn_followsMenuItem?.addEventListener("mouseover",(()=>{fcn_setupFollowsHTML()}),{once:!0}),fcn_followsMenuItem?.addEventListener("focus",(()=>{fcn_setupFollowsHTML()}),{once:!0}),_$('.mobile-menu__frame-button[data-frame-target="follows"]')?.addEventListener("click",(()=>{fcn_setupFollowsHTML()}),{once:!0}),_$$(".button-follow-story").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleFollow(t.currentTarget.dataset.storyId)}))})),_$$(".mark-follows-read").forEach((t=>{t.addEventListener("click",(()=>{fcn_markFollowsRead()}))})),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeCheckmarks(t)})),document.addEventListener("fcnUserDataReady",(t=>{fcn_initializeReminders(t)})),_$$(".button-read-later").forEach((t=>{t.addEventListener("click",(t=>{fcn_toggleReminder(t.currentTarget.dataset.storyId)}))})),document.addEventListener("fcnUserDataReady",(()=>{fcn_getUserData().fingerprint==fcn_theRoot.dataset.authorFingerprint&&fcn_theBody.classList.add("is-post-author")})),fcn_addJSTrap(),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),_$(".comment-section")?.addEventListener("click",(t=>{const e=t.target.closest("[data-bbcode]");e&&fcn_wrapInTag(_$(fictioneer_comments.form_selector??"#comment"),e.dataset.bbcode,{shortcode:!0})})),_$(".comment-section")?.addEventListener("keydown",(t=>{if(_$(".fictioneer-comment-toolbar")&&"TEXTAREA"===document.activeElement.tagName&&(t.ctrlKey||t.metaKey)){const e=t.key.toLowerCase();if(["b","i","s","q","h","l"].includes(e)){t.preventDefault();const n={q:"quote",h:"spoiler",l:"link"};fcn_wrapInTag(document.activeElement,n[e]||e,{shortcode:!0})}}})),fcn_bindAJAXCommentSubmit();const fcn_commentEditActionsTemplate=_$(".comment-edit-actions-template");var fcn_commentEditUndos={};function fcn_triggerInlineCommentEdit(t){const e=t.closest(".fictioneer-comment");if(e){const t=e.querySelector(".fictioneer-comment__content"),n=e.querySelector(".fictioneer-comment__edit"),a=e.querySelector(".comment-inline-edit-content");n.appendChild(fcn_commentEditActionsTemplate.content.cloneNode(!0)),fcn_commentEditUndos[e.id]=a.value,e.classList.add("_editing"),t.hidden=!0,n.hidden=!1,a.style.height=`${a.scrollHeight}px`}}function fcn_submitInlineCommentEdit(t){const e=t.closest(".fictioneer-comment"),n=e.querySelector(".fictioneer-comment__edit"),a=e.querySelector(".comment-inline-edit-content").value;let o=e.querySelector(".fictioneer-comment__edit-note");a!=fcn_commentEditUndos[e.id]?e&&(n.classList.add("ajax-in-progress"),t.innerHTML=t.dataset.disabled,t.disabled=!0,fcn_ajaxPost({action:"fictioneer_ajax_edit_comment",comment_id:e.id.replace("comment-",""),content:a,fcn_fast_comment_ajax:1}).then((t=>{if(t.success){const n=e.querySelector(".fictioneer-comment__content");n.innerHTML=t.data.content,fcn_restoreComment(e,!1,t.data.raw),o||(o=document.createElement("div")),o.classList.add("fictioneer-comment__edit-note"),o.innerHTML=t.data.edited,n.parentNode.appendChild(o)}else fcn_restoreComment(e,!0),t.data?.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{fcn_restoreComment(e,!0),t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),t.innerHTML=t.dataset.enabled,t.disabled=!1}))):fcn_restoreComment(e,!0)}function fcn_cancelInlineCommentEdit(t){const e=t.closest(".fictioneer-comment");e&&fcn_restoreComment(e,!0)}function fcn_restoreComment(t,e=!1,n=null){t.querySelector(".fictioneer-comment__content").hidden=!1,t.querySelector(".fictioneer-comment__edit").hidden=!0,t.querySelector(".fictioneer-comment__edit-actions")?.remove(),t.classList.remove("_editing"),e&&fcn_commentEditUndos[t.id]?t.querySelector(".comment-inline-edit-content").value=fcn_commentEditUndos[t.id]:n&&(t.querySelector(".comment-inline-edit-content").value=n)}function fcn_revealEditButton(){let t=parseInt(fcn_theRoot.dataset.editTime);t&&(t=t>0?6e4*t:t,_$$(".fictioneer-comment[data-fingerprint]").forEach((e=>{if(fcn_matchFingerprint(e.dataset.fingerprint)){if(t>0&&parseInt(e.dataset.timestamp)+t<Date.now())return;const n=e.querySelector(".fictioneer-comment__edit-toggle");n&&(n.hidden=!1)}})))}function fcn_revealDeleteButton(){_$$(".fictioneer-comment[data-fingerprint]").forEach((t=>{if(fcn_matchFingerprint(t.dataset.fingerprint)){const e=t.querySelector(".fictioneer-comment__delete");e&&(e.hidden=!1)}}))}function fcn_deleteMyComment(t){if(!fcn_isLoggedIn)return;const e=prompt(t.dataset.dialogMessage);if(!e||e.toLowerCase()!=t.dataset.dialogConfirm.toLowerCase())return;const n=t.closest(".fictioneer-comment");n.classList.contains("ajax-in-progress")||(n.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_delete_my_comment",comment_id:n.dataset.id,fcn_fast_comment_ajax:1}).then((t=>{t.success?(n.classList.add("_deleted"),n.querySelector(".fictioneer-comment__container").innerHTML=t.data.html):t.data.error&&fcn_showNotification(t.data.error,5,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")})))}document.addEventListener("fcnUserDataReady",(()=>{fcn_revealEditButton()})),document.addEventListener("fcnUserDataReady",(()=>{fcn_revealDeleteButton()}));const fcn_ajaxCommentForm=_$$$("ajax-comment-form-target");function fcn_setupCommentFormObserver(){const t=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentForm(),t.disconnect())}),{rootMargin:"450px",threshold:1});t.observe(fcn_ajaxCommentForm)}function fcn_getCommentForm(){let t;fcn_ajaxGet({action:"fictioneer_ajax_get_comment_form",post_id:_$$$("comments").dataset.postId,fcn_fast_comment_ajax:1}).then((e=>{if(e.success){const t=document.createElement("div");t.innerHTML=e.data.html;const n=t.querySelector("#comment_post_ID"),a=t.querySelector("#cancel-comment-reply-link"),o=t.querySelector(".logout-link");n&&(n.value=e.data.postId),a&&(a.href="#respond"),o&&(o.href=_$$$("comments").dataset.logoutUrl),fcn_ajaxCommentForm.innerHTML=t.innerHTML,t.remove(),fcn_applyCommentStack(),fcn_addCommentFormEvents(),fcn_theRoot.dataset.ajaxSubmit&&fcn_bindAJAXCommentSubmit(),fcn_addNonceHTML(e.data.nonceHtml),fcn_addJSTrap()}else t=fcn_buildErrorNotice(e.data.error)})).catch((e=>{t=fcn_buildErrorNotice(e)})).then((()=>{fcn_ajaxCommentForm.classList.remove("comments-skeleton"),t&&(fcn_ajaxCommentForm.innerHTML="",fcn_ajaxCommentForm.appendChild(t))}))}fcn_ajaxCommentForm&&(fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentFormObserver()})):fcn_setupCommentFormObserver());var fcn_commentStack=[];function fcn_applyCommentStack(t=null){(t=t??_$(fictioneer_comments.form_selector??"#comment"))&&("TEXTAREA"==t.tagName?(fcn_commentStack.forEach((e=>{t.value+=e})),fcn_textareaAdjust(t)):"DIV"==t.tagName&&fcn_commentStack.forEach((e=>{t.innerHTML+=e})),fcn_commentStack=[])}_$(".fictioneer-comments")?.addEventListener("click",(t=>{const e=t.target.closest("[data-click]");if(e)switch(e?.dataset.click){case"submit-inline-comment-edit":fcn_submitInlineCommentEdit(e);break;case"cancel-inline-comment-edit":fcn_cancelInlineCommentEdit(e);break;case"trigger-inline-comment-edit":fcn_triggerInlineCommentEdit(e);break;case"delete-my-comment":fcn_deleteMyComment(e);break;case"flag-comment":fcn_flagComment(e);break;case"ajax-mod-action":fcn_moderateComment(e.dataset.id,e.dataset.action)}})),_$(".fictioneer-comments")?.addEventListener("input",(t=>{t.target.matches(".adaptive-textarea")&&fcn_textareaAdjust(t.target),t.target.closest('[name="fictioneer-private-comment-toggle"]')&&_$$$("respond")?.classList.toggle("_private",t.currentTarget.checked)}));const fcn_commentSection=_$("#comments[data-ajax-comments]");function fcn_getCommentSection(t=null,e=null,n=null,a=!1){if(!fcn_commentSection)return;let o,c="",s=_$(fictioneer_comments.form_selector??"#comment");if(s&&(c=s.value),fcn_commentSection.classList.contains("ajax-in-progress"))return;if(fcn_commentSection.classList.add("ajax-in-progress"),e||(e=fcn_urlParams.pg??1),n||(n=n??fcn_commentSection.dataset.order??"desc"),!fcn_commentSection)return;const i={action:"fictioneer_ajax_get_comment_section",post_id:t??fcn_commentSection.dataset.postId,page:parseInt(e),corder:n,fcn_fast_comment_ajax:1};fcn_urlParams.commentcode&&(i.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(i).then((t=>{if(t.success){e=t.data.page,fcn_commentSection.dataset.page=e;const o=document.createElement("div");if(o.innerHTML=t.data.html,o.querySelector("#comment_post_ID")){o.querySelector("#comment_post_ID").value=t.data.postId,o.querySelector("#cancel-comment-reply-link").href="#respond";const e=o.querySelector(".logout-link");e&&(e.href=fcn_commentSection.dataset.logoutUrl)}fcn_commentSection.innerHTML=o.innerHTML,o.remove(),s=_$(fictioneer_comments.form_selector??"#comment"),s&&!t.data.disabled&&(s.value=c,fcn_applyCommentStack(s)),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const i=location.hash.includes("#comment")?location.hash:".respond",r=document.querySelector(i)??_$$$("respond");a&&r.scrollIntoView({behavior:"smooth"});const l=window.location.protocol+"//"+window.location.host+window.location.pathname;let f="";fcn_urlParams.commentcode&&(f+=`?commentcode=${fcn_urlParams.commentcode}`),e>1&&(f+=f.length>1?`&pg=${e}`:`?pg=${e}`),"desc"!=n&&(f+=f.length>1?`&corder=${n}`:`?corder=${n}`),window.history.pushState({path:l},"",l+f+location.hash)}else o=fcn_buildErrorNotice(t.data.error)})).catch((t=>{o=fcn_buildErrorNotice(t)})).then((()=>{fcn_commentSection.classList.remove("ajax-in-progress"),o&&(fcn_commentSection.innerHTML="",fcn_commentSection.appendChild(o))}))}function fcn_reloadCommentsPage(t=null){fcn_getCommentSection(null,t,null,!0)}function fcn_jumpToCommentPage(){const t=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));t>0&&fcn_reloadCommentsPage(t)}var fct_commentSectionObserver;function fcn_setupCommentSectionObserver(){fct_commentSectionObserver=new IntersectionObserver((([t])=>{t.isIntersecting&&(fcn_getCommentSection(),fct_commentSectionObserver.disconnect())}),{rootMargin:"450px",threshold:1}),fcn_commentSection&&fct_commentSectionObserver.observe(fcn_commentSection)}function fcn_loadCommentEarly(){fcn_commentSection&&location.hash.includes("#comment")&&(_$(fictioneer_comments.form_selector??"#comment")||(fct_commentSectionObserver.disconnect(),fcn_reloadCommentsPage()))}function fcn_toggleCommentOrder(t){const e=t.closest(".fictioneer-comments"),n="desc"==e.dataset.order;e.dataset.order=n?"asc":"desc",t.classList.toggle("_on",!n),t.classList.toggle("_off",n),fcn_reloadCommentsPage(e.dataset.page)}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentSectionObserver()})):fcn_setupCommentSectionObserver(),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(t=>{if(t.target.closest("button[data-page-jump]"))return void fcn_jumpToCommentPage();const e=t.target.closest("button[data-page]");if(e)return void fcn_reloadCommentsPage(e.dataset.page);const n=t.target.closest("button[data-toggle-order]");n&&fcn_toggleCommentOrder(n)}));const fcn_bookshelfTarget=_$$$("ajax-bookshelf-target");function fcn_getBookshelfContent(){return fcn_parseJSON(localStorage.getItem("fcnBookshelfContent"))??{html:{},count:{}}}function fcn_updateBookshelfView(t=null,e=null,n=null,a=!1){let o=fcn_getBookshelfContent();const c=(t=t??fcn_bookshelfTarget.dataset.action)+(e=e??fcn_bookshelfTarget.dataset.page)+(n=n??fcn_bookshelfTarget.dataset.order);if(!o.timestamp||o.timestamp+6e4<Date.now())return localStorage.removeItem("fcnBookshelfContent"),o={html:{},count:{}},void fcn_fetchBookshelfPart(t,e,n,a);o.html&&o.html[c]?(fcn_bookshelfTarget.innerHTML=o.html[c],fcn_bookshelfTarget.classList.remove("ajax-in-progress"),fcn_bookshelfTarget.dataset.page=e,_$(".item-number").innerHTML=`(${o.count[t]})`,a&&_$$$("main").scrollIntoView({behavior:"smooth"})):fcn_fetchBookshelfPart(t,e,n,a)}function fcn_browseBookshelfPage(t){fcn_bookshelfTarget.classList.add("ajax-in-progress"),fcn_updateBookshelfView(null,t,null,!0),history.pushState({},"",fcn_buildUrl({tab:fcn_bookshelfTarget.dataset.tab,pg:t,order:fcn_bookshelfTarget.dataset.order}).href)}function fcn_fetchBookshelfPart(t,e,n,a=!1){const o=t+e+n,c=fcn_getBookshelfContent();fcn_ajaxGet({action:t,fcn_fast_ajax:1,page:e,order:n}).then((n=>{n.success?(c.timestamp=Date.now(),c.html[o]=n.data.html,c.count[t]=n.data.count,localStorage.setItem("fcnBookshelfContent",JSON.stringify(c)),fcn_bookshelfTarget.innerHTML=n.data.html,fcn_bookshelfTarget.dataset.page=e,_$(".item-number").innerHTML=`(${n.data.count})`):(fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(n.data.error)))})).catch((t=>{_$(".item-number").innerHTML="",fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(`${t.status}: ${t.statusText}`))})).then((()=>{fcn_bookshelfTarget.classList.remove("ajax-in-progress"),a&&_$$$("main").scrollIntoView({behavior:"smooth"})}))}fcn_bookshelfTarget&&(fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_updateBookshelfView()})):fcn_updateBookshelfView()),_$(".bookshelf__list")?.addEventListener("click",(t=>{const e=t.target.closest(".page-numbers[data-page]");e&&fcn_browseBookshelfPage(e.dataset.page)}));