2024-10-25 00:17:50 +02:00
|
|
|
const fcn_theSite=_$$$("site"),fcn_theBody=_$("body"),fcn_theRoot=document.documentElement,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");function fcn_cleanupWebStorage(e=!1){const t=["fcnProfileAvatar","fcnBookshelfContent"];e||t.push("fcnChapterBookmarks"),t.forEach((e=>localStorage.removeItem(e)));const n=["loggedIn","follows","reminders","checkmarks","bookmarks","fingerprint"],o=fcn_parseJSON(localStorage.getItem("fcnUserData"));o&&(n.forEach((e=>o[e]=!1)),localStorage.setItem("fcnUserData",JSON.stringify(o)));const s=fcn_parseJSON(localStorage.getItem("fcnAuth"));s?.loggedIn&&localStorage.removeItem("fcnAuth")}function fcn_prepareLogin(){localStorage.removeItem("fcnUserData"),localStorage.removeItem("fcnAuth")}function fcn_cleanupGuestView(){fcn_isLoggedIn=!1,fcn_theBody.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$$("fictioneer-ajax-nonce")?.remove(),_$$(".only-moderators, .only-admins, .only-authors, .only-editors, .chapter-group__list-item-checkmark").forEach((e=>{e.remove()}))}function fcn_ajaxAuth(){let e=!1,t=fcn_parseJSON(localStorage.getItem("fcnAuth"))??!1;if(fcn_isLoggedIn&&!t?.loggedIn&&(localStorage.removeItem("fcnAuth"),t=!1),t){fcn_addNonceHTML(t.nonceHtml);const n=new CustomEvent("fcnAuthReady",{detail:{nonceHtml:t.nonceHtml,nonce:t.nonce,loggedIn:t.loggedIn,isAdmin:t.isAdmin,isModerator:t.isModerator,isAuthor:t.isAuthor,isEditor:t.isEditor},bubbles:!0,cancelable:!1});if(document.dispatchEvent(n),e=!0,fcn_ajaxLimitThreshold<t.lastLoaded)return}fcn_ajaxGet({action:"fictioneer_ajax_get_auth",fcn_fast_ajax:1}).then((t=>{if(t.success){fcn_addNonceHTML(t.data.nonceHtml);const n={lastLoaded:Date.now(),nonceHtml:t.data.nonceHtml,nonce:t.data.nonce,loggedIn:t.data.loggedIn,isAdmin:t.data.isAdmin,isModerator:t.data.isModerator,isAuthor:t.data.isAuthor,isEditor:t.data.isEditor};if(!e){const e=new CustomEvent("fcnAuthReady",{detail:n,bubbles:!0,cancelable:!1});document.dispatchEvent(e)}localStorage.setItem("fcnAuth",JSON.stringify(n))}else{fcn_cleanupGuestView();const e=new Event("fcnAuthFailed");document.dispatchEvent(e)}})).catch((()=>{localStorage.removeItem("fcnAuth"),fcn_cleanupGuestView();const e=new Event("fcnAuthError");document.dispatchEvent(e)}))}function fcn_addNonceHTML(e){_$$$("fictioneer-ajax-nonce")?.remove(),fcn_theBody.appendChild(fcn_html`${e}`)}function fcn_setLoggedInState(e){fcn_isLoggedIn=e.loggedIn,fcn_theBody.classList.add("logged-in"),fcn_theBody.classList.toggle("is-admin",e.isAdmin),fcn_theBody.classList.toggle("is-moderator",e.isModerator),fcn_theBody.classList.toggle("is-author",e.isAuthor),fcn_theBody.classList.toggle("is-editor",e.isEditor);const t=['label[for="modal-login-toggle"]',"#modal-login-toggle","#login-modal"];e.isAdmin||(t.push(".only-admins"),e.isModerator||t.push(".only-moderators"),e.isAuthor||t.push(".only-authors"),e.isEditor||t.push(".only-editors")),_$$(t.join(", ")).forEach((e=>e.remove())),fcn_getProfileImage(),fcn_fetchUserData()}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 o=n.content.cloneNode(!0);t.classList.add("menu-item-has-children"),t.querySelector('[href="#"]').addEventListener("click",(e=>{e.preventDefault()})),t.appendChild(o)}fcn_isLoggedIn||fcn_theRoot.dataset.ajaxAuth||(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView()),"function"==typeof fcn_removeQueryArgs&&fcn_removeQueryArgs(),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{fcn_cleanupWebStorage()})),_$$(".subscriber-login, .oauth-login-link, [data-prepare-login]").forEach((e=>{e.addEventListener("click",(()=>{fcn_prepareLogin()}))})),document.addEventListener("DOMContentLoaded",(()=>{fcn_theRoot.dataset.ajaxAuth&&fcn_aj
|