1 line
18 KiB
JavaScript
1 line
18 KiB
JavaScript
"use strict";let swcfpc_toolbar_cache_status_tries=0,swcfpc_toolbar_cache_status_interval=null;function swcfpc_handle_conditional_settings(e){parseInt(e.value)>0?(document.querySelectorAll(`.${e.dataset.mainoption}`).length>0&&document.querySelectorAll(`.${e.dataset.mainoption}`).forEach((e=>{e.classList.contains("swcfpc_hide")&&e.classList.remove("swcfpc_hide")})),document.querySelectorAll(`.${e.dataset.mainoption}_not`).length>0&&document.querySelectorAll(`.${e.dataset.mainoption}_not`).forEach((e=>{e.classList.add("swcfpc_hide")}))):(document.querySelectorAll(`.${e.dataset.mainoption}`).length>0&&document.querySelectorAll(`.${e.dataset.mainoption}`).forEach((e=>{e.classList.add("swcfpc_hide")})),document.querySelectorAll(`.${e.dataset.mainoption}_not`).length>0&&document.querySelectorAll(`.${e.dataset.mainoption}_not`).forEach((e=>{e.classList.contains("swcfpc_hide")&&e.classList.remove("swcfpc_hide")})))}function swcfpc_lock_screen(){if(!document.querySelector(".swcfpc_please_wait")){const e=document.querySelectorAll("input[type=submit]"),c=document.querySelectorAll("input[type=submit]"),t=document.querySelectorAll("a");e.forEach((e=>{e.classList.add("swcfpc_hide")})),c.forEach((e=>{e.classList.add("swcfpc_hide")})),t.forEach((e=>{e.classList.add("swcfpc_hide")}));const s=document.createElement("div");s.classList.add("swcfpc_please_wait"),document.body.prepend(s)}}function swcfpc_unlock_screen(){const e=document.querySelectorAll("input[type=submit]"),c=document.querySelectorAll("input[type=submit]"),t=document.querySelectorAll("a");e.forEach((e=>{e.classList.remove("swcfpc_hide")})),c.forEach((e=>{e.classList.remove("swcfpc_hide")})),t.forEach((e=>{e.classList.remove("swcfpc_hide")})),document.querySelector(".swcfpc_please_wait").remove()}function swcfpc_redirect_to_page(e){window.location=e}function swcfpc_refresh_page(){window.location.reload()}function swcfpc_display_ok_dialog(e,c,t,s,n,a,o,r,l){t=void 0===t||null==t?350:parseInt(t),s=void 0===s||null==s?300:parseInt(s),a=void 0===a?null:a,o=void 0===o?"Close":o,l=void 0===l?null:l;let _="success";"warning"===(n=void 0===n?null:n)?_="warning":"error"===n?_="error":"info"===n?_="info":"question"===n&&(_="question"),null==(r=void 0===r?null:r)?Swal.fire({title:null!==a?a:"",html:c,icon:_,confirmButtonText:o}):Swal.fire({title:null!==a?a:"",html:c,icon:_,confirmButtonText:o,willClose:()=>{null!=l?r(l):r()}}).then((e=>{e.isConfirmed&&(null!=l?r(l):r())}))}async function swcfpc_purge_varnish_cache(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_purge_varnish_cache&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_purge_fallback_page_cache(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_purge_fallback_page_cache&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_force_purge_everything(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_purge_everything&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_purge_whole_cache(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_purge_whole_cache&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_import_config_file(e){try{const c=document.getElementById("swcfpc-ajax-nonce").innerText,t=encodeURIComponent(JSON.stringify({config_file:e}));swcfpc_lock_screen();const s=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_import_config_file&security=${c}&data=${t}`,credentials:"same-origin",timeout:1e4});if(s.ok){const e=await s.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success",null,"Ok",swcfpc_refresh_page):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_purge_single_post_cache(e){try{const c=document.getElementById("swcfpc-ajax-nonce").innerText,t=encodeURIComponent(JSON.stringify({post_id:e}));swcfpc_lock_screen();const s=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_purge_single_post_cache&security=${c}&data=${t}`,credentials:"same-origin",timeout:1e4});if(s.ok){const e=await s.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_test_page_cache(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_test_page_cache&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_enable_page_cache(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_enable_page_cache&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success",null,"Ok",swcfpc_refresh_page):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_disable_page_cache(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_disable_page_cache&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success",null,"Ok",swcfpc_refresh_page):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_reset_all(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_reset_all&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success",null,"Ok",swcfpc_refresh_page):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_clear_logs(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_clear_logs&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_start_preloader(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_preloader_start&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}async function swcfpc_unlock_preloader(){try{const e=document.getElementById("swcfpc-ajax-nonce").innerText;swcfpc_lock_screen();const c=await fetch(swcfpc_ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},body:`action=swcfpc_preloader_unlock&security=${e}`,credentials:"same-origin",timeout:1e4});if(c.ok){const e=await c.json();swcfpc_unlock_screen(),"ok"===e.status?swcfpc_display_ok_dialog("Success",`${e.success_msg}`,null,null,"success"):swcfpc_display_ok_dialog("Error",`${e.error}`,null,null,"error")}else swcfpc_unlock_screen()}catch(e){alert(`Error: ${e.status} ${e.message}`),swcfpc_unlock_screen()}}if(document.querySelector("#swcfpc_tab_links .nav-tab:not(.swcfpc-external)")){const e=document.querySelectorAll("#swcfpc_tab_links .nav-tab:not(.swcfpc-external)");e.forEach((c=>{c.addEventListener("click",(c=>{c.preventDefault();const t=c.target.dataset.tab;if(void 0===typeof t)return!0;e.forEach((e=>{e.classList.contains("nav-tab-active")&&e.classList.remove("nav-tab-active")})),c.target.classList.add("nav-tab-active"),document.querySelectorAll(".swcfpc_tab").forEach((e=>{e.classList.contains("active")&&e.classList.remove("active")})),document.getElementById(t).classList.add("active");const s=document.querySelector("input[name=swcfpc_submit_general]");"faq"===t?s.classList.add("swcfpc_hide"):s.classList.contains("swcfpc_hide")&&s.classList.remove("swcfpc_hide"),document.querySelector("input[name=swcfpc_tab]").value=t}))}))}function swcfpc_init_accordions(){const e=document.getElementsByClassName("swcfpc_faq_question");for(let c=0;c<e.length;c++)e[c].addEventListener("click",(function(){this.classList.toggle("active");const e=this.nextElementSibling;"block"===e.style.display?e.style.display="none":e.style.display="block"}))}function swcfpc_update_toolbar_cache_status(){null!=document.getElementById("wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container")?(0==swcfpc_cache_enabled?(document.getElementById("wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container").classList.remove("bullet-green"),document.getElementById("wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container").classList.add("bullet-red")):(document.getElementById("wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container").classList.remove("bullet-red"),document.getElementById("wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container").classList.add("bullet-green")),clearInterval(swcfpc_toolbar_cache_status_interval)):swcfpc_toolbar_cache_status_tries++}document.addEventListener("DOMContentLoaded",(e=>{if("undefined"==typeof swcfpc_cache_enabled){}if(null!==document.getElementById("swcfpc_main_content")&&(swcfpc_cache_enabled=parseInt(document.getElementById("swcfpc_main_content").getAttribute("data-cache_enabled")),(null==swcfpc_cache_enabled||isNaN(swcfpc_cache_enabled))&&(swcfpc_cache_enabled=0)),document.getElementById("swcfpc_clear_logs")&&document.getElementById("swcfpc_clear_logs").addEventListener("click",(e=>{e.preventDefault(),swcfpc_clear_logs()})),document.getElementById("swcfpc_start_preloader")&&document.getElementById("swcfpc_start_preloader").addEventListener("click",(e=>{e.preventDefault(),swcfpc_start_preloader()})),document.getElementById("swcfpc_unlock_preloader")&&document.getElementById("swcfpc_unlock_preloader").addEventListener("click",(e=>{e.preventDefault(),swcfpc_unlock_preloader()})),document.querySelector("#swcfpc_import_config_start")&&document.querySelector("#swcfpc_import_config_start").addEventListener("click",(e=>{e.preventDefault();swcfpc_import_config_file(document.querySelector("#swcfpc_import_config_content").value)})),document.getElementById("swcfpc_fallback_page_cache_purge")&&document.getElementById("swcfpc_fallback_page_cache_purge").addEventListener("click",(e=>{e.preventDefault(),swcfpc_purge_fallback_page_cache()})),document.querySelector("#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-all a")&&document.querySelector("#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-all a").addEventListener("click",(e=>{e.preventDefault(),swcfpc_purge_whole_cache()})),document.querySelector("#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-single a")&&document.querySelector("#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-single a").addEventListener("click",(e=>{e.preventDefault();swcfpc_purge_single_post_cache(e.target.hash.replace("#",""))})),document.querySelector(".swcfpc_action_row_single_post_cache_purge")&&document.querySelectorAll(".swcfpc_action_row_single_post_cache_purge").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault();swcfpc_purge_single_post_cache(e.target.dataset.post_id)}))})),document.getElementById("swcfpc_varnish_cache_purge")&&document.getElementById("swcfpc_varnish_cache_purge").addEventListener("click",(e=>{e.preventDefault(),swcfpc_purge_varnish_cache()})),document.getElementById("swcfpc_form_purge_cache")&&document.getElementById("swcfpc_form_purge_cache").addEventListener("submit",(e=>{e.preventDefault(),swcfpc_purge_whole_cache()})),document.getElementById("swcfpc_purge_cache_everything")&&document.getElementById("swcfpc_purge_cache_everything").addEventListener("click",(e=>{e.preventDefault(),swcfpc_force_purge_everything()})),document.querySelector("#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-force-purge-everything a")&&document.querySelector("#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-force-purge-everything a").addEventListener("click",(e=>{e.preventDefault(),swcfpc_force_purge_everything()})),document.getElementById("swcfpc_form_test_cache")&&document.getElementById("swcfpc_form_test_cache").addEventListener("submit",(e=>{e.preventDefault(),swcfpc_test_page_cache()})),document.getElementById("swcfpc_form_enable_cache")&&document.getElementById("swcfpc_form_enable_cache").addEventListener("submit",(e=>{e.preventDefault(),swcfpc_enable_page_cache()})),document.getElementById("swcfpc_form_disable_cache")&&document.getElementById("swcfpc_form_disable_cache").addEventListener("submit",(e=>{e.preventDefault(),swcfpc_disable_page_cache()})),document.getElementById("swcfpc_form_reset_all")&&document.getElementById("swcfpc_form_reset_all").addEventListener("submit",(e=>{e.preventDefault(),confirm("Are you sure you want reset all?")&&swcfpc_reset_all()})),document.querySelector("select[name=swcfpc_cf_auth_mode]")&&document.querySelector("select[name=swcfpc_cf_auth_mode]").addEventListener("change",(e=>{e.preventDefault();"0"===e.target.value?(document.querySelectorAll(".api_token_method").forEach((e=>{e.classList.add("swcfpc_hide")})),document.querySelectorAll(".api_key_method").forEach((e=>{e.classList.remove("swcfpc_hide")}))):(document.querySelectorAll(".api_token_method").forEach((e=>{e.classList.remove("swcfpc_hide")})),document.querySelectorAll(".api_key_method").forEach((e=>{e.classList.add("swcfpc_hide")})))})),document.querySelectorAll(".conditional_item").length>0&&document.querySelectorAll(".conditional_item").forEach((e=>{e.checked&&swcfpc_handle_conditional_settings(e),e.addEventListener("click",(e=>{swcfpc_handle_conditional_settings(e.target)}))})),document.querySelector(".swcfpc_faq_accordion")&&swcfpc_init_accordions(),document.querySelector("#swcfpc_tab_links .nav-tab-active")){const e=document.querySelector("#swcfpc_tab_links .nav-tab-active").dataset.tab;void 0!==typeof e&&(document.querySelector("input[name=swcfpc_tab]").value=e)}swcfpc_toolbar_cache_status_interval=window.setInterval(swcfpc_update_toolbar_cache_status,2e3)})); |