Session storage just cannot be properly cleared site-wide, which is actually worse in terms of security if you log out and leave another tab open.
1 line
2.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
var fcn_userRemindersTimeout,fcn_reminders;function fcn_initializeReminders(){fcn_reminders=fcn_getReminders(),fcn_fetchRemindersFromDatabase()}function fcn_getReminders(){const e=localStorage.getItem("fcnStoryReminders");return e&&fcn_isValidJSONString(e)?JSON.parse(e):{lastLoaded:0,data:{}}}function fcn_fetchRemindersFromDatabase(){fcn_ajaxLimitThreshold<fcn_reminders.lastLoaded?fcn_updateRemindersView():fcn_ajaxGet({action:"fictioneer_ajax_get_reminders"}).then((e=>{if(e.success){let t=e.data.reminders;t=fcn_isValidJSONString(t)?t:"{}",t=JSON.parse(t),(fcn_reminders="object"==typeof t&&t.data&&Object.keys(t.data).length>0?t:{data:{}}).lastLoaded=Date.now()}})).catch((()=>{localStorage.removeItem("fcnStoryReminders"),fcn_reminders=!1})).then((()=>{fcn_updateRemindersView(),localStorage.removeItem("fcnBookshelfContent")}))}function fcn_toggleReminder(e){const t=fcn_getReminders();if(localStorage.removeItem("fcnBookshelfContent"),JSON.stringify(fcn_reminders.data[e])!==JSON.stringify(t.data[e]))return fcn_reminders=t,fcn_showNotification(__("Reminders re-synchronized.","fictioneer")),void fcn_updateRemindersView();(fcn_reminders=t).data.hasOwnProperty(e)?delete fcn_reminders.data[e]:fcn_reminders.data[e]={timestamp:Date.now()},fcn_reminders.lastLoaded=0,fcn_updateRemindersView(),clearTimeout(fcn_userRemindersTimeout),fcn_userRemindersTimeout=setTimeout((()=>{fcn_ajaxPost(payload={action:"fictioneer_ajax_toggle_reminder",story_id:e,set:fcn_reminders.data.hasOwnProperty(e)}).then((e=>{e.data.error&&fcn_showNotification(e.data.error,5,"warning")})).catch((e=>{e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")}))}),fictioneer_ajax.post_debounce_rate)}function fcn_updateRemindersView(){fcn_reminders&&(_$$(".button-read-later").forEach((e=>{e.classList.toggle("_remembered",fcn_reminders.data.hasOwnProperty(e.dataset.storyId))})),_$$(".card").forEach((e=>{e.classList.toggle("has-reminder",fcn_reminders?.data.hasOwnProperty(e.dataset.storyId))})),localStorage.setItem("fcnStoryReminders",JSON.stringify(fcn_reminders)))}fcn_isLoggedIn&&fcn_initializeReminders(),_$$(".button-read-later").forEach((e=>{e.addEventListener("click",(e=>{fcn_toggleReminder(e.currentTarget.dataset.storyId)}))})); |