1 line
2.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
function fcn_replaceProfileImage(e,a){const t=e.querySelector(".user-icon");if(t){const n=document.createElement("img");n.classList.add("user-profile-image"),n.src=a,t.remove(),e.appendChild(n)}}function fcn_setProfileImage(e,a=!0){e&&fcn_isValidUrl(e)&&(a&&localStorage.setItem("fcnProfileAvatar",e),_$$("a.subscriber-profile")?.forEach((a=>{fcn_replaceProfileImage(a,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",fcn_fast_ajax:1}).then((e=>{e.success&&fcn_setProfileImage(e.data.url)})).catch((()=>{fcn_theRoot.dataset.defaultAvatar&&fcn_setProfileImage(fcn_theRoot.dataset.defaultAvatar,!1)}))}var fcn_userData;function fcn_initializeUserData(){fcn_userData=fcn_getUserData(),fcn_fetchUserData()}function fcn_getUserData(){const e=localStorage.getItem("fcnUserData");return e&&fcn_isValidJSONString(e)?JSON.parse(e):{lastLoaded:0,timestamp:0,follows:!1,reminders:!1,checkmarks:!1,bookmarks:{},fingerprint:!1}}function fcn_setUserData(e){localStorage.setItem("fcnUserData",JSON.stringify(e))}function fcn_fetchUserData(){if(fcn_ajaxLimitThreshold<fcn_userData.lastLoaded){const e=new CustomEvent("fcnUserDataReady",{detail:{data:fcn_userData,time:new Date},bubbles:!1,cancelable:!0});document.dispatchEvent(e)}else fcn_ajaxGet({action:"fictioneer_ajax_get_user_data",fcn_fast_ajax:1}).then((e=>{if(e.success){(fcn_userData=e.data).lastLoaded=Date.now();const a=new CustomEvent("fcnUserDataReady",{detail:{data:e.data,time:new Date},bubbles:!0,cancelable:!1});fcn_setUserData(fcn_userData),document.dispatchEvent(a)}else{localStorage.removeItem("fcnUserData"),fcn_userData=!1;const a=new CustomEvent("fcnUserDataFailed",{detail:{response:e,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(a)}})).catch((e=>{localStorage.removeItem("fcnUserData"),fcn_userData=!1;const a=new CustomEvent("fcnUserDataError",{detail:{error:e,time:new Date},bubbles:!0,cancelable:!1});document.dispatchEvent(a)}))}fcn_getProfileImage(),document.addEventListener("DOMContentLoaded",(()=>{fcn_isLoggedIn&&!fcn_userData&&fcn_initializeUserData()})); |