fictioneer/js/application.min.js

1 line
23 KiB
JavaScript
Raw Normal View History

2023-01-24 11:46:00 +01:00
const fcn_theSite=_$$$("site"),fcn_theBody=_$("body"),fcn_theRoot=document.documentElement,fcn_inlineStorage=_$$$("inline-storage").dataset,fcn_mainNavigation=_$$$("full-navigation"),fcn_urlSearchParams=new URLSearchParams(window.location.search),fcn_urlParams=Object.fromEntries(fcn_urlSearchParams.entries()),fcn_pageLoadTimestamp=Date.now(),fcn_ajaxLimitThreshold=Date.now()-parseInt(fictioneer_ajax.ttl),fcn_eventNonceReady=new Event("nonceReady"),fcn_isAjaxAuth=fcn_theRoot.dataset.ajaxAuth;var fcn_viewportWidth,fcn_mediaMinTablet,fcn_cssVars=getComputedStyle(document.documentElement),fcn_isLoggedIn=fcn_theBody.classList.contains("logged-in");const{__:__,_x:_x,_n:_n,sprintf:sprintf}=wp.i18n;function fcn_cleanupLocalStorage(e=!1){localStorage.removeItem("fcnProfileAvatar"),localStorage.removeItem("fcnStoryFollows"),localStorage.removeItem("fcnStoryReminders"),localStorage.removeItem("fcnCheckmarks"),localStorage.removeItem("fcnLoginState"),localStorage.removeItem("fcnNonce"),localStorage.removeItem("fcnFingerprint"),localStorage.removeItem("fcnBookshelfContent"),e||localStorage.removeItem("fcnChapterBookmarks")}function fcn_cleanupGuestView(){fcn_isLoggedIn=!1,fcn_theBody.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$(".only-moderators, .only-admins, .only-authors, .only-editors").forEach((e=>{e.remove()}))}function fcn_fetchNonce(){let e=localStorage.getItem("fcnNonce");e=!(!e||!fcn_isValidJSONString(e))&&JSON.parse(e),e&&(fcn_addNonceAndAuth(e.nonceHtml),fcn_ajaxLimitThreshold<e.lastLoaded)||fcn_ajaxGet({action:"fictioneer_ajax_get_nonce"}).then((e=>{_$$$("fictioneer-ajax-nonce")?.remove(),e.success?(fcn_addNonceAndAuth(e.data.nonceHtml),localStorage.setItem("fcnNonce",JSON.stringify({lastLoaded:Date.now(),nonceHtml:e.data.nonceHtml}))):(_$$$("fictioneer-ajax-nonce")?.remove(),fcn_cleanupGuestView())})).catch((()=>{localStorage.removeItem("fcnNonce"),_$$$("fictioneer-ajax-nonce")?.remove(),fcn_cleanupGuestView()}))}function fcn_addNonceAndAuth(e){let t=document.createElement("div");t.innerHTML+=e,fcn_theBody.appendChild(t.firstChild),fcn_theRoot.dispatchEvent(fcn_eventNonceReady),!fcn_isLoggedIn&&fcn_isAjaxAuth&&fcn_fetchLoginState()}function fcn_fetchLoginState(){let e=localStorage.getItem("fcnLoginState");e=!(!e||!fcn_isValidJSONString(e))&&JSON.parse(e),e&&e.loggedIn&&(fcn_setLoggedInState(e,!1),Date.now()-fictioneer_ajax.login_ttl<e.lastLoaded)||fcn_ajaxGet({action:"fictioneer_ajax_is_user_logged_in"}).then((t=>{t.success&&t.data.loggedIn?(fcn_setLoggedInState(t.data,!e.loggedIn),localStorage.setItem("fcnLoginState",JSON.stringify({lastLoaded:Date.now(),loggedIn:t.data.loggedIn,isAdmin:t.data.isAdmin,isModerator:t.data.isModerator,isAuthor:t.data.isAuthor,isEditor:t.data.isEditor}))):(fcn_cleanupLocalStorage(!0),fcn_cleanupGuestView())})).catch((()=>{fcn_cleanupLocalStorage(),fcn_cleanupGuestView()}))}function fcn_setLoggedInState(e,t=!0){fcn_isLoggedIn=e.loggedIn,fcn_theBody.classList.add("logged-in"),fcn_theBody.classList.toggle("is-admin",e.isAdmin),fcn_theBody.classList.toggle("is-moderator",e.isModerator),fcn_theBody.classList.toggle("is-author",e.isAuthor),fcn_theBody.classList.toggle("is-editor",e.isEditor),e.isAdmin||_$$(".only-admins").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-moderators").forEach((e=>{e.remove()})),e.isAuthor||e.isAdmin||_$$(".only-authors").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-editors").forEach((e=>{e.remove()})),t&&("function"==typeof fcn_initializeCheckmarks&&fcn_initializeCheckmarks(),"function"==typeof fcn_initializeFollows&&fcn_initializeFollows(),"function"==typeof fcn_initializeReminders&&fcn_initializeReminders(),"function"==typeof fcn_getBookmarksForUser&&fcn_getBookmarksForUser(),"function"==typeof fcn_showChapterBookmark&&fcn_showChapterBookmark(),fcn_initializeFingerprint(),fcn_getProfileImage())}function fcn_updateViewportVariables(){fcn_viewportWidth=Math.max(document.documentElement.clientWidth??0,window.innerWidth??0),fcn_mediaMinTablet=fcn_viewportWidth>=768}function fcn_loadEmbed(e){le