1 line
4.2 KiB
JavaScript
1 line
4.2 KiB
JavaScript
function fcn_unsetOauth(t,e,n){let a=prompt(sprintf(_x("Are you sure? Note that if you disconnect all accounts, you may no longer be able to log back in once you log out. Enter %s to confirm.","Unset OAuth prompt.","fictioneer"),_x("delete","Prompt deletion confirmation string.","fictioneer").toUpperCase()));if(!a||a.toLowerCase()!=_x("delete","Prompt deletion confirmation string.","fictioneer").toLowerCase())return;let r=_$$$(`oauth-${e}`);r.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_unset_my_oauth",nonce:t,channel:e,id:n}).then((t=>{t.success?(r.classList.remove("_connected"),r.classList.add("_disconnected"),r.querySelector("label").remove(),fcn_showNotification(r.dataset.unset)):(r.style.background="var(--warning)",fcn_showNotification(t.data.error,5,"warning"))})).catch((t=>{t.status&&t.statusText&&(r.style.background="var(--warning)",fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"))})).then((()=>{r.classList.remove("ajax-in-progress")}))}function fcn_deleteMyAccount(t){if(_$$$("button-delete-my-account").hasAttribute("disabled"))return;let e=prompt(sprintf(t.dataset.warning,_x("delete","Prompt deletion confirmation string.","fictioneer").toUpperCase()));if(!e||e.toLowerCase()!=_x("delete","Prompt deletion confirmation string.","fictioneer").toLowerCase())return;_$$$("button-delete-my-account").setAttribute("disabled",!0);let n={action:"fictioneer_ajax_delete_my_account",nonce:t.dataset.nonce,id:t.dataset.id};fcn_ajaxPost(n).then((t=>{t.success?location.reload():(fcn_showNotification(t.data.error,5,"warning"),_$$$("button-delete-my-account").innerHTML=t.data.button)})).catch((t=>{t.status&&t.statusText&&(fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),_$$$("button-delete-my-account").innerHTML=response.data.button)}))}_$$(".button-unset-oauth").forEach((t=>{t.addEventListener("click",(t=>{fcn_unsetOauth(t.currentTarget.dataset.nonce,t.currentTarget.dataset.channel,t.currentTarget.dataset.id)}))})),_$$$("button-delete-my-account")?.addEventListener("click",(t=>{fcn_deleteMyAccount(t.currentTarget)}));const fcn_profileDataTranslations=_$$$("profile-data-translations")?.dataset;function fcn_dataDeletionPrompt(t){let e=prompt(sprintf(t.dataset.warning,_x("delete","Prompt deletion confirmation string.","fictioneer").toUpperCase()));return!(!e||e.toLowerCase()!=_x("delete","Prompt deletion confirmation string.","fictioneer").toLowerCase())}function fcn_clearData(t,e){let n=t.closest(".card");localStorage.removeItem("fcnBookshelfContent"),n.classList.add("ajax-in-progress"),t.remove();let a={action:e,nonce:t.dataset.nonce};fcn_ajaxPost(a).then((t=>{t.success?n.querySelector(".card__content").innerHTML=t.data.success:fcn_showNotification(t.data.error,10,"warning")})).catch((t=>{t.status&&t.statusText&&fcn_showNotification(`${t.status}: ${t.statusText}`,10,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")}))}_$(".button-clear-comments")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_comments")})),_$(".button-clear-comment-subscriptions")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_comment_subscriptions")})),_$(".button-clear-checkmarks")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&(fcn_checkmarks={data:{},timestamp:Date.now()},fcn_updateCheckmarksView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_checkmarks",!0))})),_$(".button-clear-reminders")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&(fcn_reminders={data:{}},fcn_updateRemindersView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_reminders",!0))})),_$(".button-clear-follows")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&(fcn_follows={data:{}},fcn_updateFollowsView(),fcn_clearData(t.currentTarget,"fictioneer_ajax_clear_my_follows",!0))})),_$(".button-clear-bookmarks")?.addEventListener("click",(t=>{fcn_dataDeletionPrompt(t.currentTarget)&&(fcn_bookmarks.data&&Object.keys(fcn_bookmarks.data).forEach((t=>fcn_removeBookmark(t))),t.currentTarget.closest(".card").querySelector(".card__content").innerHTML=fcn_profileDataTranslations.clearedSuccess,fcn_setBookmarks(fcn_bookmarks))})); |