In case of images with transparency. Either it is loaded at this point or not, the loader has no relation to the image status anyway.
2 lines
39 KiB
JavaScript
2 lines
39 KiB
JavaScript
const FcnGlobals={eSite:_$$$("site"),urlParams:Object.fromEntries(new URLSearchParams(window.location.search).entries()),pageLoadTimestamp:Date.now(),ajaxLimitThreshold:Date.now()-parseInt(fictioneer_ajax.ttl),ajaxURL:fictioneer_ajax.ajax_url,restURL:fictioneer_ajax.rest_url,ffcnrURL:fictioneer_ajax.ffcnr_url,ffcnrAuth:fictioneer_ajax.ffcnr_auth,debounceRate:fictioneer_ajax.post_debounce_rate,ajaxAuth:document.documentElement.dataset.fictioneerAjaxAuthValue??!1,fonts:fictioneer_fonts??[],fontColors:fictioneer_font_colors??[],commentFormSelector:fictioneer_comments?.selector??"#comment",commentStack:[]};function fcn(){const e=window.FictioneerApp?.Controllers?.fictioneer;return e||{userData:FcnUtils.userData,setUserData:FcnUtils.setUserData,resetUserData:FcnUtils.resetUserData,removeUserData:FcnUtils.removeUserData}}function fcn_getUserData(){return FcnUtils.userData()}function fcn_setUserData(e){return FcnUtils.setUserData(e)}function fcn_cleanUpWebStorage(){["fcnBookshelfContent"].forEach((e=>localStorage.removeItem(e))),fcn().resetUserData()}function fcn_cleanUpGuestView(){document.body.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$$("fictioneer-ajax-nonce")?.remove(),_$$(".only-moderators, .only-admins, .only-authors, .only-editors, .only-logged-in").forEach((e=>{e.remove()}))}function fcn_setLoggedInState(){const e=fcn().userData(),t=!0===e.loggedIn;document.body.classList.toggle("logged-in",t),document.body.classList.toggle("is-admin",e.isAdmin),document.body.classList.toggle("is-moderator",e.isModerator),document.body.classList.toggle("is-author",e.isAuthor),document.body.classList.toggle("is-editor",e.isEditor);const n=[];t&&(n.push('[data-fictioneer-id-param="login-modal"]'),n.push("#login-modal")),e.isAdmin||(n.push(".only-admins"),e.isModerator||n.push(".only-moderators"),e.isAuthor||n.push(".only-authors"),e.isEditor||n.push(".only-editors")),_$$(n.join(", ")).forEach((e=>e.remove()))}function fcn_setAvatar(){const e=fcn().userData()?.avatarUrl;e&&_$$('[data-fictioneer-target="avatarWrapper"]').forEach((t=>{const n=document.createElement("img");n.classList.add("user-profile-image"),n.src=e,t.firstChild.remove(),t.appendChild(n)}))}Object.freeze(FcnGlobals),window.FictioneerApp=window.FictioneerApp||{},window.FictioneerApp.Controllers=window.FictioneerApp.Controllers||{},application.register("fictioneer",class extends Stimulus.Controller{static get targets(){return["avatarWrapper","modal","mobileMenuToggle","dcjProtected"]}static values={fingerprint:String,ageConfirmation:{type:Boolean,default:!1},ajaxAuth:{type:Boolean,default:!1},ajaxSubmit:{type:Boolean,default:!1},cachingActive:{type:Boolean,default:!1},publicCaching:{type:Boolean,default:!1},forceChildTheme:{type:Boolean,default:!1},editTime:{type:Number,default:15}};userReady=!1;lastModalToggle=null;currentModal=null;dcjProtection=!0;initialize(){if(FcnUtils.loggedIn()||this.ajaxAuthValue)this.fetchUserData();else{fcn_cleanUpWebStorage();const e=new CustomEvent("fcnUserDataReady",{detail:{data:this.userData(),time:new Date,loggedOut:!0},bubbles:!0,cancelable:!1});document.dispatchEvent(e)}this.hasDcjProtectedTarget&&["mousemove","touchstart","keydown"].forEach((e=>{window.addEventListener(e,this.liftProtection.bind(this),{once:!0})}))}liftProtection(){this.dcjProtection&&this.hasDcjProtectedTarget&&(this.dcjProtectedTargets.forEach((e=>e.disabled=!1)),this.dcjProtection=!1)}connect(){window.FictioneerApp.Controllers.fictioneer=this}userData(){return FcnUtils.userData()}setUserData(e){FcnUtils.setUserData(e)}resetUserData(){FcnUtils.resetUserData()}removeUserData(){FcnUtils.removeUserData()}fetchUserData(){let e=this.userData();if(FcnUtils.loggedIn()&&!1===e.loggedIn&&(this.removeUserData(),e=this.userData()),(FcnGlobals.ajaxLimitThreshold<e.lastLoaded||!1===e.loggedIn)&&("pending"!==e.loggedIn||this.ajaxAuthValue)){const t=new CustomEvent("fcnUserDataReady",{detail:{data:e,time:new Date,cached:!0},bubbles:!e.loggedIn,cancelable:e.loggedIn});return fcn_setAvatar(),e.nonceHtml&&this.#e(e.nonceHtml),document.dispatchEvent(t),void(this.userReady=!0)}FcnUtils.aGet({action:FcnGlobals.ffcnrAuth?"auth":"fictioneer_ajax_get_user_data",fcn_fast_ajax:1},FcnGlobals.ffcnrAuth?FcnGlobals.ffcnrURL:null).then((t=>{if(t.success){let n=this.userData();n=t.data,n.lastLoaded=Date.now(),this.setUserData(n),fcn_setAvatar(),e.nonceHtml&&this.#e(e.nonceHtml);const s=new CustomEvent("fcnUserDataReady",{detail:{data:t.data,time:new Date,cached:!1},bubbles:!0,cancelable:!1});document.dispatchEvent(s)}else{const e=this.userData();e.lastLoaded=Date.now(),e.loggedIn=!1,this.setUserData(e);const n=new CustomEvent("fcnUserDataFailed",{detail:{data:t,time:new Date,cached:!1},bubbles:!0,cancelable:!1});document.dispatchEvent(n)}this.userReady=!0})).catch((e=>{localStorage.removeItem("fcnUserData");const t=new CustomEvent("fcnUserDataError",{detail:{error:e,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(t)}))}copyInput(e){e.currentTarget.select(),FcnUtils.copyToClipboard(e.currentTarget.value,e.currentTarget.dataset.message)}clearConsent(e){FcnUtils.toggleInProgress(e.currentTarget),FcnUtils.deleteCookie("fcn_cookie_consent"),location.reload()}clearCookies(e){const t=e.currentTarget;if(!FcnUtils.loggedIn())return fcn_cleanUpWebStorage(),FcnUtils.deleteAllCookies(),void alert(t.dataset.message);FcnUtils.toggleInProgress(t),FcnUtils.aGet({action:"fictioneer_ajax_clear_cookies",nonce:FcnUtils.nonce()}).then((e=>{e.success?(fcn_cleanUpWebStorage(),FcnUtils.deleteAllCookies(),alert(e.data.success)):e.data.error&&(alert(e.data.failure),console.error("Error:",e.data.error))})).catch((e=>{alert(e),console.error(e)})).then((()=>{FcnUtils.toggleInProgress(t)}))}logout(){fcn_cleanUpWebStorage()}toggleObfuscation(e){e.target.closest('[data-fictioneer-target="obfuscated"]').classList.toggle("_obfuscated")}bodyClick(e){let t;this.dispatch("bodyClick",{detail:{event:e,target:e.target}}),(t=e.target.closest(".page-numbers.dots:not(button)"))?this.#t(t):(t=e.target.closest(".spoiler"))&&t.classList.toggle("_open")}toggleChapterGroup(e){const t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list"),s=!t.classList.contains("_closed");n.addEventListener("transitionend",(()=>{n.style.height="",n.querySelectorAll("a, button, label, input:not([hidden])").forEach((e=>{e.tabIndex=n.parentElement.classList.contains("_closed")?"-1":"0"})),_$(".main__background")?.classList.remove("will-change")}),{once:!0}),_$(".main__background")?.classList.add("will-change"),n.style.height=`${n.scrollHeight}px`,requestAnimationFrame((()=>{requestAnimationFrame((()=>{t.classList.toggle("_closed",s),n.style.height=s?"0":`${n.scrollHeight}px`}))}))}toggleModal(e){e.preventDefault(),this.toggleModalVisibility(e.currentTarget,e.params.id)}toggleModalVisibility(e,t){const n=_$$$(t);if(n)if(this.currentModal!==n&&this.closeModals(),this.lastModalToggle=e,n.hidden=!n.hidden,n.hidden)this.closeModals();else{const e=n.querySelector(".close");e?.focus(),e?.blur()}}closeModals(){this.hasModalTarget&&this.modalTargets.forEach((e=>{e.hidden=!0})),this.lastModalToggle&&(this.lastModalToggle?.focus(),this.lastModalToggle?.blur(),this.lastModalToggle.null)}backgroundCloseModals({target:e}){e.classList.contains("modal")&&this.closeModals()}toggleMobileMenu(e){e.preventDefault();const t=window.FictioneerApp.Controllers.fictioneerMobileMenu;t&&t.toggle()}#e(e){_$$$("fictioneer-ajax-nonce")?.remove(),document.body.appendChild(FcnUtils.html`${e}`)}#t(e){if(document.documentElement.dataset.disablePageJump)return;const t=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));if(t>0){const n=e.nextElementSibling.getAttribute("href"),s=["page=","paged=","comment-page-","pg="];for(const e of s)if(n.includes(e))return void(window.location.href=n.replace(new RegExp(`${e}\\d+`),e+t));window.location.href=n.replace(/page\/\d+/,`page/${t}`)}}}),"function"==typeof fcn_removeQueryArgs&&fcn_removeQueryArgs(),document.addEventListener("fcnUserDataReady",(()=>{fcn().userData().loggedIn||(fcn_cleanUpWebStorage(),fcn_cleanUpGuestView())})),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{fcn_cleanUpWebStorage()})),_$$(".subscriber-login, .oauth-login-link, [data-prepare-login]").forEach((e=>{e.addEventListener("click",(()=>{fcn().removeUserData()}))})),document.addEventListener("fcnUserDataReady",(()=>{fcn_setLoggedInState()})),document.addEventListener("fcnUserDataReady",(()=>{fcn_setAvatar()}));var fcn_animFrameEvents=new Map;function fcn_bindEventToAnimationFrame(e,t,n=window){n.addEventListener(e,(function(){fcn_animFrameEvents.get(t)||(fcn_animFrameEvents.set(t,!0),requestAnimationFrame((()=>{n.dispatchEvent(new CustomEvent(t)),fcn_animFrameEvents.set(t,!1)})))}))}function fcn_loadEmbed(e){e.target.parentNode.querySelectorAll("iframe, script")[0].src=e.target.dataset.src,e.target.parentElement.querySelector(".embed-logo")?.remove(),e.target.remove()}function fcn_appendTermMenu(e,t){const n=_$$$(`term-submenu-${e}`);if(!n)return;const s=n.content.cloneNode(!0);t.classList.add("menu-item-has-children"),t.querySelector('[href="#"]').addEventListener("click",(e=>{e.preventDefault()})),t.appendChild(s)}fcn_bindEventToAnimationFrame("scroll","scroll.rAF"),fcn_bindEventToAnimationFrame("resize","resize.rAF"),document.body.addEventListener("change",(e=>{const t=e.target.closest('[type="checkbox"]');if(!t)return;const n=t.name,s=n?_$$(`label[for="${n}"]`):[],i=t.checked;t.closest("[aria-checked]")?.setAttribute("aria-checked",i),s.forEach((e=>{e.closest("[aria-checked]")?.setAttribute("aria-checked",i)}))})),_$$(".iframe-consent, .twitter-consent").forEach((e=>{e.onclick=e=>{fcn_loadEmbed(e)}})),document.addEventListener("DOMContentLoaded",(()=>{const e=_$("#menu-navigation > .menu-item"),t=_$$$("full-navigation");e&&t&&e.offsetHeight<t.offsetHeight&&t.classList.add("_oversized-navigation"),_$$(".main-navigation .trigger-term-menu-categories").forEach((e=>{fcn_appendTermMenu("category",e)})),_$$(".main-navigation .trigger-term-menu-tags").forEach((e=>{fcn_appendTermMenu("post_tag",e)})),_$$(".main-navigation .trigger-term-menu-genres").forEach((e=>{fcn_appendTermMenu("fcn_genre",e)})),_$$(".main-navigation .trigger-term-menu-fandoms").forEach((e=>{fcn_appendTermMenu("fcn_fandom",e)})),_$$(".main-navigation .trigger-term-menu-characters").forEach((e=>{fcn_appendTermMenu("fcn_character",e)})),_$$(".main-navigation .trigger-term-menu-warnings").forEach((e=>{fcn_appendTermMenu("fcn_content_warning",e)}))})),_$$$("full-navigation")?.addEventListener("mouseover",(()=>{document.dispatchEvent(new CustomEvent("fcnRemoveLastClicked"))}));var fcn_lastScrollTop=0;function fcn_scrollDirection(){if(FcnGlobals.eSite.classList.contains("transformed-scroll"))return;const e="hidden"!==window.getComputedStyle(document.documentElement).overflow?window.scrollY??document.documentElement.scrollTop:document.body.scrollTop??1;document.body.classList.toggle("scrolled-to-top",0===e),e>fcn_lastScrollTop&&Math.abs(fcn_lastScrollTop-e)>=10?(document.body.classList.add("scrolling-down"),document.body.classList.remove("scrolling-up"),fcn_lastScrollTop=Math.max(e,0)):e<fcn_lastScrollTop&&Math.abs(fcn_lastScrollTop-e)>=50&&(document.body.classList.add("scrolling-up"),document.body.classList.remove("scrolling-down"),fcn_lastScrollTop=Math.max(e,0))}function fcn_observe(e,t,n={}){const s=_$(e);if(!s)return null;new IntersectionObserver((e=>t(e[0])),n).observe(s)}function fcn_dragElement(e){const t=e.querySelector(".drag-anchor")??e;let n,s;function i(t){t.preventDefault(),e.style.top=e.offsetTop-(s-t.clientY)+"px",e.style.left=e.offsetLeft-(n-t.clientX)+"px",n=t.clientX,s=t.clientY}function a(){t.onmouseup=null,t.onmousemove=null}t.onmousedown=function(e){e.preventDefault(),n=e.clientX,s=e.clientY,t.onmousemove=i,t.onmouseup=a}}function fcn_showNotification(e,t=3,n="base"){const s=_$("#notifications"),i=document.createElement("div");i.innerHTML=e,i.classList.add("notifications__message",`_${n}`),i.style.opacity=1,i.style.transitionDelay=`${t}s`,s.prepend(i),i.addEventListener("transitionend",(e=>{"opacity"===e.propertyName&&s.removeChild(e.target)})),i.addEventListener("click",(e=>{s.removeChild(e.currentTarget)})),setTimeout((()=>{i.style.opacity=0}),100)}if(window.addEventListener("scroll.rAF",FcnUtils.throttle(fcn_scrollDirection,200)),fcn_scrollDirection(),document.addEventListener("DOMContentLoaded",(()=>{fcn_observe(".main-observer",(e=>{document.body.classList.toggle("is-inside-main",e.intersectionRatio<1&&e.boundingClientRect.top<=0)}),{threshold:[1]}),fcn_observe(".chapter-end",(e=>{document.body.classList.toggle("is-end-of-chapter",e.isIntersecting||e.boundingClientRect.top<0)}),{root:null,threshold:0}),fcn_observe("#nav-observer-sticky",(e=>{_$$$("full-navigation").classList.toggle("is-sticky",e.intersectionRatio<1)}),{threshold:[1]})})),_$$(".modal__header.drag-anchor").forEach((e=>{fcn_dragElement(e.closest(".modal__wrapper"))})),FcnGlobals.urlParams){switch(FcnGlobals.urlParams.failure&&console.error("Failure:",FcnGlobals.urlParams.failure),FcnGlobals.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"===FcnGlobals.urlParams.success)fcn_showNotification(fictioneer_tl.notification.oauthNew,10);else FcnGlobals.urlParams.success?.startsWith("oauth_merged_")&&fcn_showNotification(fictioneer_tl.notification.oauthAccountLinked,3,"success");if(FcnGlobals.urlParams["fictioneer-notice"]){let e="1"===FcnGlobals.urlParams.failure?"warning":"base";e="1"===FcnGlobals.urlParams.success?"success":e,fcn_showNotification(FcnUtils.sanitizeHTML(FcnGlobals.urlParams["fictioneer-notice"]),3,e)}}function fcn_updateThemeColor(e=null){const t=fcn_siteSettings.darken?fcn_siteSettings.darken:0,n=fcn_siteSettings.saturation?fcn_siteSettings.saturation:0,s=fcn_siteSettings["hue-rotate"]?fcn_siteSettings["hue-rotate"]:0,i=t>=0?1+t**2:1-t**2,a=n>=0?1+n**2:1-n**2;let o=getComputedStyle(document.documentElement).getPropertyValue("--theme-color-base").trim().split(" ");o=`hsl(${(parseInt(o[0])+s)%360}deg ${(parseInt(o[1])*a).toFixed(2)}% ${(parseInt(o[2])*i).toFixed(2)}%)`,_$("meta[name=theme-color]").setAttribute("content",e??o)}const 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","taxonomies","text-shadows","minimal","chapter-progress-bar"];var fcn_siteSettings=fcn_getSiteSettings();function fcn_updateSiteSetting(e,t,n){e.checked=n,fcn_siteSettings[t]=n,fcn_applySiteSettings(fcn_siteSettings)}function fcn_toggleLightMode(){fcn_setLightMode(!(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==document.documentElement.dataset.modeDefault))}function fcn_setLightMode(e,t=!1){localStorage.setItem("fcnLightmode",e),document.documentElement.dataset.mode=e?"light":"dark",_$$(".toggle-light-mode").forEach((t=>{t.closest("[aria-checked]")?.setAttribute("aria-checked",e)})),t||fcn_updateThemeColor()}function fcn_updateFontWeight(){const e="default"!=fcn_siteSettings["font-weight"];_$$(".site-setting-font-weight").forEach((e=>{e.value=fcn_siteSettings["font-weight"]})),_$$(".font-weight-reset").forEach((t=>{t.classList.toggle("_modified",e)}))}function fcn_resetFontWeight(){fcn_siteSettings["font-weight"]="default",document.documentElement.dataset.fontWeight="default",fcn_applySiteSettings(fcn_siteSettings)}function fcn_updateHueRotate(e){e=FcnUtils.clamp(0,360,e??0),fcn_settingHueRotateText.value=e,fcn_settingHueRotateRange.value=e,fcn_settingHueRotateReset.classList.toggle("_modified",0!=e),document.documentElement.style.setProperty("--hue-rotate",`(${e}deg + var(--hue-offset))`),fcn_siteSettings["hue-rotate"]=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setHueRotate(){fcn_updateHueRotate(this.value)}function fcn_updateDarken(e=null){e=FcnUtils.clamp(-1,1,e??fcn_siteSettings.darken),e=Math.round(100*(e+Number.EPSILON))/100,fcn_settingDarkenResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingDarkenRanges.forEach((t=>{t.value=e})),fcn_settingDarkenTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+e**2:1-e**2;document.documentElement.style.setProperty("--darken",`(${t} + var(--lightness-offset))`),fcn_siteSettings.darken=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setDarkenFromRange(){fcn_updateDarken(this.value)}function fcn_setDarkenFromText(){"-"!=this.value&&""!=this.value&&fcn_updateDarken((parseInt(this.value)??0)/100)}function fcn_updateSaturation(e=null){e=FcnUtils.clamp(-1,1,e??fcn_siteSettings.saturation),fcn_settingSaturationResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingSaturationRanges.forEach((t=>{t.value=e})),fcn_settingSaturationTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+e**2:1-e**2;document.documentElement.style.setProperty("--saturation",`(${t} + var(--saturation-offset))`),fcn_siteSettings.saturation=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setSaturationFromRange(){fcn_updateSaturation(this.value)}function fcn_setSaturationFromText(){"-"!=this.value&&""!=this.value&&fcn_updateSaturation((parseInt(this.value)??0)/100)}function fcn_updateFontLightness(e=null){e=FcnUtils.clamp(-1,1,e??fcn_siteSettings["font-lightness"]??1),fcn_settingFontLightnessResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingFontLightnessRanges.forEach((t=>{t.value=e})),fcn_settingFontLightnessTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+e**2:1-e**2;document.documentElement.style.setProperty("--font-lightness",`(${t} + var(--font-lightness-offset))`),fcn_siteSettings["font-lightness"]=e,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,taxonomies:!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 e=FcnUtils.parseJSON(localStorage.getItem("fcnSiteSettings"))??fcn_defaultSiteSettings();return fcn_setSiteSettings(e),e}function fcn_setSiteSettings(e=null){"object"==typeof(e=e||fcn_siteSettings)&&(fcn_siteSettings=e,localStorage.setItem("fcnSiteSettings",JSON.stringify(e)))}function fcn_applySiteSettings(e){e="object"!=typeof e?fcn_defaultSiteSettings():e,Object.entries(e).forEach((e=>{const t=_$$$(`site-setting-${e[0]}`);switch(t&&(t.checked=e[1]),e[0]){case"minimal":document.documentElement.classList.toggle("minimal",e[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(e[1]);break;case"font-weight":fcn_updateFontWeight();break;default:document.documentElement.classList.toggle(`no-${e[0]}`,!e[1])}})),fcn_setSiteSettings(e)}function fcn_updateSiteTheme(e){fcn_siteSettings["site-theme"]=e,document.documentElement.dataset.theme=e,_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e),fcn_applySiteSettings(fcn_siteSettings),fcn_updateThemeColor()}function fcn_resetSiteTheme(){fcn_updateSiteTheme("default"),_$$(".site-setting-site-theme").forEach((e=>{e.value="default"}))}function fcn_revealCommentImage(e){const t=e.parentElement.querySelector("img");t.src=t.dataset.src,e.remove()}function fcn_contactFormSubmit(e){const t=e.closest("form"),n=new FormData(t);if(!t.reportValidity())return;if(e.disabled=!0,e.innerHTML=e.dataset.disabled,Date.now()<FcnGlobals.pageLoadTimestamp+3e3)return;const s={};for(const[e,t]of n)s[e]=t;FcnUtils.remoteAction("fictioneer_ajax_submit_contact_form",{element:t,payload:s,callback:n=>{n.success?(t.querySelector("textarea").value="",e.innerHTML=e.dataset.done,fcn_showNotification(n.data.success,3,"success")):n.data.failure&&(e.disabled=!1,e.innerHTML=e.dataset.enabled)},errorCallback:()=>{e.disabled=!1,e.innerHTML=e.dataset.enabled}})}fcn_settingEvents.forEach((e=>{_$$$(`site-setting-${e}`)?.addEventListener("change",(t=>{fcn_updateSiteSetting(t.currentTarget,e,t.currentTarget.checked)}))})),fcn_setLightMode(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==document.documentElement.dataset.modeDefault,!0),_$$(".toggle-light-mode").forEach((e=>{e.onclick=()=>fcn_toggleLightMode()})),_$$(".font-weight-reset").forEach((e=>{e.addEventListener("click",fcn_resetFontWeight)})),_$$(".site-setting-font-weight").forEach((e=>{e.onchange=e=>{fcn_siteSettings["font-weight"]=e.target.value,document.documentElement.dataset.fontWeight=e.target.value,fcn_applySiteSettings(fcn_siteSettings),fcn_updateFontWeight()}})),fcn_settingHueRotateReset?.addEventListener("click",(()=>{fcn_updateHueRotate(0)})),fcn_settingHueRotateRange?.addEventListener("input",FcnUtils.throttle(fcn_setHueRotate,1e3/24)),fcn_settingHueRotateText?.addEventListener("input",fcn_setHueRotate),fcn_settingDarkenResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateDarken(0)}))})),fcn_settingDarkenRanges.forEach((e=>{e.addEventListener("input",FcnUtils.throttle(fcn_setDarkenFromRange,1e3/24))})),fcn_settingDarkenTexts.forEach((e=>{e.addEventListener("input",fcn_setDarkenFromText)})),fcn_settingSaturationResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateSaturation(0)}))})),fcn_settingSaturationRanges.forEach((e=>{e.addEventListener("input",FcnUtils.throttle(fcn_setSaturationFromRange,1e3/24))})),fcn_settingSaturationTexts.forEach((e=>{e.addEventListener("input",fcn_setSaturationFromText)})),fcn_settingFontLightnessResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateFontLightness(0)}))})),fcn_settingFontLightnessRanges.forEach((e=>{e.addEventListener("input",FcnUtils.throttle(fcn_setFontLightnessFromRange,1e3/24))})),fcn_settingFontLightnessTexts.forEach((e=>{e.addEventListener("input",fcn_setFontLightnessFromText)})),fcn_applySiteSettings(fcn_siteSettings),_$$(".site-setting-site-theme").forEach((e=>{e.value=fcn_siteSettings["site-theme"]?fcn_siteSettings["site-theme"]:"default",_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e.value),e.addEventListener("change",(e=>{fcn_updateSiteTheme(e.target.value)}))})),_$$$("site-setting-theme-reset")?.addEventListener("click",fcn_resetSiteTheme),fcn_updateThemeColor(),_$(".fictioneer-comments")?.addEventListener("click",(e=>{e.target?.classList.contains("consent-button")&&fcn_revealCommentImage(e.target)})),_$$(".fcn-contact-form").forEach((e=>{e.querySelector(".fcn-contact-form__submit").addEventListener("click",(e=>{fcn_contactFormSubmit(e.currentTarget)}))})),_$$('[data-click-action*="open-dialog-modal"]').forEach((e=>{e.addEventListener("click",(e=>{document.querySelector(e.currentTarget.dataset.clickTarget).showModal()}))})),_$$('[data-click-action*="close-dialog-modal"], button[formmethod="dialog"][value="cancel"]').forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),e.target.closest("dialog").close()}))})),_$$("dialog").forEach((e=>{e.addEventListener("mousedown",(t=>{if(t.target===t.currentTarget){const n=e.getBoundingClientRect();(t.clientX<n.left||t.clientX>n.right||t.clientY<n.top||t.clientY>n.bottom)&&(t.preventDefault(),t.target.close())}}))})),_$$(".content-section").forEach((e=>{e.addEventListener("click",(e=>{if(e.target.closest('[data-click-action*="open-tooltip-modal"]')&&!window.getSelection().toString()){const t=_$$$("fictioneer-tooltip-dialog"),n=e.target.dataset.dialogHeader,s=e.target.dataset.dialogContent;s.length>200?t.style.setProperty("--modal-width","400px"):t.style.removeProperty("--modal-width"),n&&(t.querySelector('[data-finder="tooltip-dialog-header"]').innerHTML=n),t.querySelector('[data-finder="tooltip-dialog-content"]').innerHTML=s,t.showModal()}}))})),document.body.addEventListener("keydown",(e=>{let t=document.activeElement.closest('[tabindex="0"]:not(a, input, button, select)');if(["BUTTON","A","INPUT","SELECT"].includes(document.activeElement.tagName)&&(t=null),t&&(" "!==e.key&&"Enter"!==e.key||(e.preventDefault(),t.click())),"Escape"===e.key){_$$(".modal-toggle:checked").forEach((e=>{e.checked=!1,e.dispatchEvent(new Event("change"))}));const e=_$(".lightbox.show");if(e)return void e.querySelector(".lightbox__close").click();const t=_$(".selected-paragraph #button-close-paragraph-tools");if(t)return void t.click();const n=_$("#tts-interface:not(.hidden)");if(n){if(n.classList.contains("playing")){const e=_$$$("button-tts-pause");e?.click(),e?.focus(),e?.blur()}else _$$$("button-tts-stop").click();return}}}));class FCN_KeywordInput{constructor(e){this.input=e,this.type=e.dataset.type,this.operator=e.closest(".keyword-input").querySelector(".keyword-input__operator input"),this.inputWrapper=e.closest(".keyword-input__input-wrapper"),this.block=e.closest(".keyword-input"),this.form=this.block.closest(".search-form"),this.collection=this.block.querySelector(".keyword-input__collection"),this.suggestionList=this.block.querySelector(".keyword-input__suggestion-list"),this.tabSuggestion=this.block.querySelector(".keyword-input__tab-suggestion"),this.allowText=this.form.querySelector(".allow-list")?.innerText??"{}",this.allowList=FcnUtils.parseJSON(this.allowText),this.hints=this.block.querySelector(".keyword-input__hints"),this.noHint=this.block.querySelector(".keyword-input__no-suggestions"),this.keywords=this.collection.value.length>0?this.collection.value.split(","):[],this.bindEvents(),this.resize(),this.filterSuggestions()}resize(){const e=this.tabSuggestion.innerText.length>0?this.tabSuggestion.innerText.length:this.input.value.length;this.input.style.width=.88*e+2+"ch"}reset(){this.keywords=[],this.block.querySelectorAll(".node").forEach((e=>{e.remove()})),this.block.querySelectorAll(".keyword-input__operator > input").forEach((e=>{e.checked=!1})),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}encode(e){const t=(new TextEncoder).encode(e.toLowerCase());return btoa(String.fromCharCode.apply(null,t))}filterSuggestions(){const e=this.input.value.toLowerCase();let t=0,n="";""==e?this.suggestionList.querySelectorAll(".keyword-button").forEach((e=>{e.hidden=!0})):this.suggestionList.querySelectorAll(".keyword-button").forEach((s=>{const i=s.innerText.toLowerCase();i.includes(e)&&this.keywords.indexOf(i)<0?(s.hidden=!1,t++,""==n&&i.startsWith(e)&&(n=i)):s.hidden=!0})),this.hints.querySelectorAll(".keyword-button").forEach((e=>{this.keywords.indexOf(e.value.toLowerCase())>-1?e.hidden=!0:e.hidden=!1})),this.tabSuggestion.innerHTML=n,this.hints.hidden=!(""==e),this.noHint.hidden=!(""!=e&&t<1)}addNode(e=null,t=null){const n=e??this.input.value.replace(",","");let s=this.allowList[`${this.type}_${this.encode(n)}`];if("authors"!=this.collection.name&&"ex_authors"!=this.collection.name||!t||(s=this.allowList[`${this.type}_${this.encode(n)}_${t.value}`]),!s||this.keywords.indexOf(s)>-1)return;this.keywords.push(s);const i=document.createElement("div");i.innerHTML=`<span class="node-name">${n}</span><span class="node-delete"><i class="fa-solid fa-xmark"></i></span>`,i.classList.add("node"),i.dataset.value=s,this.inputWrapper.parentNode.insertBefore(i,this.inputWrapper),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}removeNodeByValue(e){this.block.querySelector(`[data-value="${e}"]`)?.remove(),this.keywords=this.keywords.filter((t=>t!=e)),this.updateCollection(),this.filterSuggestions(),this.resize()}updateCollection(){this.collection.value=this.keywords.join(","),this.block.classList.toggle("_empty",""===this.collection.value),this.form.querySelector(".search-form__current").innerHTML=""}bindEvents(){this.input.addEventListener("input",(e=>{e.currentTarget.value.includes(",")&&this.addNode(),this.block.classList.toggle("_empty",""===e.currentTarget.value&&""===this.collection.value),this.filterSuggestions(),this.resize()})),this.input.addEventListener("keydown",(e=>{"Tab"!==e.key&&"Enter"!==e.key||""!=this.tabSuggestion.innerText&&(e.preventDefault(),this.input.value=this.tabSuggestion.innerText,this.addNode()),"Escape"===e.key&&(this.input.value="",this.tabSuggestion.innerHTML="",document.activeElement.blur()),"Backspace"===e.key&&""==this.input.value&&this.keywords.length>0&&this.removeNodeByValue(this.keywords.slice(-1))})),this.input.addEventListener("blur",(()=>{const e=this.allowList[this.encode(this.input.value)];this.blurTimeout=e?setTimeout((()=>{this.addNode()}),150):setTimeout((()=>{this.input.value="",this.tabSuggestion.innerHTML="",this.filterSuggestions(),this.resize()}),150)})),this.block.addEventListener("click",(e=>{e.target.closest(".node-delete")&&(e.preventDefault(),this.removeNodeByValue(e.target.closest(".node").dataset.value))})),this.block.querySelectorAll(".keyword-button").forEach((e=>{e.addEventListener("click",(e=>{clearTimeout(this.blurTimeout),this.addNode(e.currentTarget.innerText,e.currentTarget)}))}))}}function fcn_resetSearchForm(e,t,n){n.forEach((e=>e.reset())),t.querySelectorAll("input, select").forEach((e=>{e.value=e.dataset.default??e.value})),t.querySelector(".search-form__current").innerHTML="",fcn_showNotification(e.dataset.reset,2)}function fcn_handleTabInput(e){"Tab"==e.key&&(document.body.classList.add("user-is-tabbing"),window.removeEventListener("keydown",fcn_handleTabInput),window.addEventListener("mousedown",fcn_handleMouseInput))}function fcn_handleMouseInput(){document.body.classList.remove("user-is-tabbing"),window.removeEventListener("mousedown",fcn_handleMouseInput),window.addEventListener("keydown",fcn_handleTabInput)}function fcn_popupPosition(){_$$(".popup-menu-toggle.last-clicked .popup-menu:not(._fixed-position)").forEach((e=>{if("none"===window.getComputedStyle(e).display)return;const t=FcnUtils.detectScreenCollision(e);t&&0===t.length||(t.includes("top")?(e.classList.remove("_top"),e.classList.add("_bottom")):t.includes("bottom")&&(e.classList.remove("_bottom"),e.classList.add("_top")),e.closest("._fixed-horizontal")||(t.includes("left")?(e.classList.remove("_center","_justify-right"),e.classList.add("_justify-left")):t.includes("right")&&(e.classList.remove("_center","_justify-left"),e.classList.add("_justify-right"))))}))}function fcn_markCurrentMenuItem(){_$$(`.menu-item > [data-nav-object-id="${document.body.dataset.postId}"]`).forEach((e=>{e.setAttribute("aria-current","page"),e.closest(".menu-item").classList.add("current-menu-item")}))}function fcn_showAgeConfirmationModal(){const e=_$(".story__article, .chapter__article")?.dataset.ageRating;if(!document.documentElement.dataset.ageConfirmation&&e&&"adult"!==e)return void _$$$("age-confirmation-modal")?.remove();const t=_$$$("age-confirmation-leave");document.documentElement.classList.add("age-modal-open"),_$$$("age-confirmation-modal").hidden=!1,
|
|
_$$$("age-confirmation-confirm")?.addEventListener("click",(e=>{document.documentElement.classList.remove("age-modal-open"),e.currentTarget.closest(".modal").remove(),localStorage.setItem("fcnAgeConfirmation","1")})),t?.addEventListener("click",(()=>{window.location.href=t.dataset.redirect??"https://search.brave.com/",localStorage.removeItem("fcnAgeConfirmation")}))}_$$(".search-form").forEach((e=>{if(e.classList.contains("_simple"))return;const t=[];e.querySelectorAll(".keyword-input__input").forEach((e=>{t.push(new FCN_KeywordInput(e))})),e.querySelector(".allow-list")?.remove(),e.addEventListener("change",(t=>{t.target.classList.contains("search-form__advanced-control")||t.target.classList.contains("search-form__string")||(e.querySelector(".search-form__current").innerHTML="")})),e.querySelectorAll(".reset").forEach((n=>{n.addEventListener("click",(()=>{fcn_resetSearchForm(n,e,t)}))}))})),_$$(".search-form__advanced-toggle").forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.closest("form");t.dataset.advanced="true"==t.dataset.advanced?"false":"true"}))})),window.addEventListener("keydown",fcn_handleTabInput),window.addEventListener("scroll.rAF",FcnUtils.throttle(fcn_popupPosition,250)),document.body.addEventListener("click",(e=>{const t=e.target.closest("[href]"),n=t?.getAttribute("href");if(!t||"A"===!t.tagName||!n.startsWith("#")||n.length<2||"#respond"===n)return;const s=n.replace("#",""),i=_$$(`[name="${s}"], [id="${s}"]`)[0],a=t.closest(".comment._story-comment");a&&(window.location.href=a.querySelector(".fictioneer-comment__link").href+n),i&&(e.preventDefault(),i.scrollIntoView({behavior:"smooth",block:t.dataset?.block??"start"}))})),fcn_markCurrentMenuItem(),_$$$("age-confirmation-modal")&&"1"!==localStorage.getItem("fcnAgeConfirmation")&&!FcnUtils.isSearchEngineCrawler()?fcn_showAgeConfirmationModal():_$$$("age-confirmation-modal")?.remove(),document.addEventListener("DOMContentLoaded",(()=>{_$$(".splide:not(.no-auto-splide, .is-initialized)").forEach((e=>{e.querySelector(".splide__list")&&"undefined"!=typeof Splide&&(e.classList.remove("_splide-placeholder"),new Splide(e).mount())})),_$$(".temp-script, .splide-placeholder-styles").forEach((e=>{e.remove()}))})),application.register("fictioneer-large-card",class extends Stimulus.Controller{static get targets(){return["controls","menu"]}static values={postId:Number,storyId:Number,chapterId:Number};initialize(){fcn()?.userReady?this.#n=!0:document.addEventListener("fcnUserDataReady",(()=>{this.#s(),this.#n=!0,this.#i()}))}connect(){if(window.FictioneerApp.Controllers.fictioneerLargeCard=this,this.#n&&(this.#s(),this.#i()),document.addEventListener("click",(e=>{e.target.closest(`.card.post-${this.postIdValue}`)||this.#a()})),document.addEventListener("toggledLastClick",(e=>{this.#o(e.detail.target,e.detail.force)})),this.hasMenuTarget)for(this.menuFragment=document.createDocumentFragment();this.menuTarget.firstChild;)this.menuFragment.appendChild(this.menuTarget.firstChild)}disconnect(){this.#c()}isFollowed(){return!(!this.#r()||!this.#l()?.follows?.data?.[this.storyIdValue])}isRemembered(){return!(!this.#r()||!this.#l()?.reminders?.data?.[this.storyIdValue])}isRead(){if(!this.#r())return!1;const e=this.#l()?.checkmarks?.data?.[this.storyIdValue];return!!e&&(e.includes(this.chapterIdValue)||e.includes(this.storyIdValue))}cardClick(e){e.target.closest(".card__controls")||this.#d()}toggleMenu(){this.menuTarget.querySelector("*")?this.#d():this.#u()}toggleFollow(){this.#r()?(fcn_toggleFollow(this.storyIdValue,!this.isFollowed()),this.#h()):_$('[data-fictioneer-id-param="login-modal"]')?.click()}toggleReminder(){this.#r()?(fcn_toggleReminder(this.storyIdValue,!this.isRemembered()),this.#g()):_$('[data-fictioneer-id-param="login-modal"]')?.click()}toggleCheckmarks(){this.#r()?(fcn_toggleCheckmark(this.storyIdValue,this.chapterIdValue),this.#f()):_$('[data-fictioneer-id-param="login-modal"]')?.click()}setCheckmarks(e){this.toggleCheckmarks("set",e.params?.type??"story")}unsetCheckmarks(e){this.toggleCheckmarks("unset",e.params?.type??"story")}#m=!1;#n=!1;#_=!1;#r(){const e=FcnUtils.loggedIn();return e||(this.#c(),this.#n=!1,this.#_=!0),e}#l(){return this.userData=fcn().userData(),this.userData}#p(){return this.#r()&&JSON.stringify(this.userData??0)!==JSON.stringify(this.#l())}#v(){this.refreshInterval||(this.refreshInterval=setInterval((()=>{!this.#_&&this.#p()&&this.#s()}),3e4+1e3*Math.random()))}#i(){this.#v(),this.visibilityStateCheck=()=>{this.#r()&&("visible"===document.visibilityState?(this.#_=!1,this.#s(),this.#v()):(this.#_=!0,clearInterval(this.refreshInterval),this.refreshInterval=null))},document.addEventListener("visibilitychange",this.visibilityStateCheck)}#c(){clearInterval(this.refreshInterval),document.removeEventListener("visibilitychange",this.visibilityStateCheck)}#s(){this.#h(),this.#g(),this.#f()}#h(){this.element.classList.toggle("has-follow",this.isFollowed())}#g(){this.element.classList.toggle("has-reminder",this.isRemembered())}#f(){this.element.classList.toggle("has-checkmark",this.isRead())}#a(){this.#d()}#u(){this.#m=!0,this.menuTarget.appendChild(this.menuFragment.cloneNode(!0))}#d(){if(this.#m)for(this.#m=!1;this.menuTarget.firstChild;)this.menuTarget.removeChild(this.menuTarget.firstChild)}#o(e,t){t?e&&!e.closest(`.card.post-${this.postIdValue}`)&&this.#m&&this.#d():this.#d()}}),application.register("fictioneer-last-click",class extends Stimulus.Controller{static get targets(){return["toggle"]}last=null;connect(){window.FictioneerApp.Controllers.fictioneerLastClick=this,document.addEventListener("fcnRemoveLastClicked",(()=>{this.last&&this.removeLastClick()}))}removeAll(){this.last&&(this.#b(this.last,!1),this.removeLastClick())}toggle(e){const t=e.target.closest('[data-fictioneer-last-click-target="toggle"]');if(!t||["BUTTON","A","INPUT","SELECT"].includes(e.target.tagName)&&!e.target.hasAttribute("data-fictioneer-last-click-target"))return;const n=!t.classList.contains("last-clicked");"function"==typeof fcn_popupPosition&&fcn_popupPosition(),t.classList.toggle("last-clicked",n),t.closest(".watch-last-clicked")?.classList.toggle("has-last-clicked",n),this.last&&this.last!=t&&this.removeLastClick(),this.last=t,this.#b(t,n),e.stopPropagation()}removeLastClick(){this.last&&(this.last.closest(".watch-last-clicked")?.classList.remove("has-last-clicked"),this.last.classList.remove("last-clicked"),this.last=null,document.activeElement?.blur())}#b(e,t){document.dispatchEvent(new CustomEvent("toggledLastClick",{detail:{target:e,force:t}}))}});const fcn_consentBanner=_$$$("consent-banner");function fcn_loadConsentBanner(){fcn_consentBanner.classList.remove("hidden"),fcn_consentBanner.hidden=!1,_$$$("consent-accept-button")?.addEventListener("click",(()=>{FcnUtils.setCookie("fcn_cookie_consent","full"),fcn_consentBanner.classList.add("hidden"),fcn_consentBanner.hidden=!0})),_$$$("consent-reject-button")?.addEventListener("click",(()=>{FcnUtils.setCookie("fcn_cookie_consent","necessary"),fcn_consentBanner.classList.add("hidden"),fcn_consentBanner.hidden=!0}))}function fcn_showLightbox(e){const t=_$$$("fictioneer-lightbox"),n=t.querySelector(".loader"),s=_$(".lightbox__content");let i=!1,a=null;if(s.innerHTML="",n.style.opacity=1,e.classList.add("lightbox-last-trigger"),"IMG"==e.tagName?(a=e.cloneNode(),i=!0):e.href&&(a=document.createElement("img"),a.src=e.href,i=!0),i&&a){["class","style","height","width"].forEach((e=>a.removeAttribute(e))),s.appendChild(a),t.classList.add("show"),setTimeout((()=>{n.style.opacity=0}),1e3);const e=t.querySelector(".lightbox__close");e?.focus(),e?.blur()}}fcn_consentBanner&&""===(FcnUtils.getCookie("fcn_cookie_consent")??"")&&!FcnUtils.isSearchEngineCrawler()?setTimeout((()=>{fcn_loadConsentBanner()}),4e3):fcn_consentBanner?.remove(),document.body.addEventListener("click",(e=>{const t=e.target.closest("[data-lightbox]:not(.no-auto-lightbox)");t&&(e.preventDefault(),fcn_showLightbox(t))})),document.body.addEventListener("keydown",(e=>{const t=e.target.closest("[data-lightbox]:not(.no-auto-lightbox)");t&&(" "!==e.key&&"Enter"!==e.key||(e.preventDefault(),fcn_showLightbox(t)))})),document.querySelectorAll(".lightbox__close, .lightbox").forEach((e=>{e.addEventListener("click",(e=>{if("IMG"!=e.target.tagName){_$$$("fictioneer-lightbox").classList.remove("show");const e=_$(".lightbox-last-trigger");e?.focus(),e?.blur(),e?.classList.remove("lightbox-last-trigger")}}))}));
|