fictioneer/js/user.min.js
2023-07-09 18:16:55 +02:00

1 line
1.7 KiB
JavaScript

function fcn_replaceProfileImage(e,n){const t=e.querySelector(".user-icon");if(t){const r=document.createElement("img");r.classList.add("user-profile-image"),r.src=n,t.remove(),e.appendChild(r)}}function fcn_setProfileImage(e,n=!0){e&&fcn_isValidUrl(e)&&(n&&localStorage.setItem("fcnProfileAvatar",e),_$$("a.subscriber-profile")?.forEach((n=>{fcn_replaceProfileImage(n,e)})))}function fcn_getProfileImage(){let e=localStorage.getItem("fcnProfileAvatar");fcn_isLoggedIn?(fcn_isValidUrl(e)||(e=!1),e?fcn_setProfileImage(e):fcn_getUserAvatar()):localStorage.removeItem("fcnProfileAvatar")}function fcn_getUserAvatar(){fcn_ajaxGet({action:"fictioneer_ajax_get_avatar"}).then((e=>{e.success&&fcn_setProfileImage(e.data.url)})).catch((()=>{fcn_theRoot.dataset.defaultAvatar&&fcn_setProfileImage(fcn_theRoot.dataset.defaultAvatar,!1)}))}var fcn_fingerprint;function fcn_initializeFingerprint(){fcn_fingerprint=fcn_getFingerprint(),fcn_fetchFingerprint()}function fcn_getFingerprint(){const e=localStorage.getItem("fcnFingerprint");return e&&fcn_isValidJSONString(e)?JSON.parse(e):{lastLoaded:0,fingerprint:!1}}function fcn_fetchFingerprint(){fcn_ajaxLimitThreshold<fcn_fingerprint.lastLoaded||fcn_ajaxGet({action:"fictioneer_ajax_get_fingerprint"}).then((e=>{if(e.success){const n=e.data.fingerprint;(fcn_fingerprint={fingerprint:n}).lastLoaded=Date.now(),localStorage.setItem("fcnFingerprint",JSON.stringify(fcn_fingerprint)),"function"==typeof fcn_revealEditButton&&fcn_revealEditButton(),"function"==typeof fcn_revealDeleteButton&&fcn_revealDeleteButton()}else localStorage.removeItem("fcnFingerprint"),fcn_fingerprint=!1})).catch((()=>{localStorage.removeItem("fcnFingerprint"),fcn_fingerprint=!1}))}fcn_getProfileImage(),fcn_isLoggedIn&&fcn_initializeFingerprint();