|
1
|
|
-jQuery(document).ready(function(t){function e(){switch(ps_ajax.cookie_duration_unit){case"days":default:return parseInt(ps_ajax.cookie_duration);case"hours":return new Date(new Date().getTime()+6e5*ps_ajax.cookie_duration);case"minutes":return new Date(new Date().getTime()+6e4*ps_ajax.cookie_duration)}}function a(){return location.origin.concat(location.pathname).concat(location.hash)+"?pts="+Math.floor(Date.now()/1e3)}function s(a){t.ajax({type:"post",dataType:"json",url:ps_ajax.ajax_url,data:{action:"hash_password",hash_nonce:ps_ajax.hash_nonce,password:a},success:function(t){Cookies.set("passster",t.password,{expires:e(),sameSite:"strict"})},async:!1})}ps_ajax.link_pass&&!ps_ajax.disable_cookie&&(ps_ajax.link_pass.length<25?s(atob(ps_ajax.link_pass)):Cookies.set("passster",ps_ajax.link_pass,{expires:e(),sameSite:"strict"}),window.location.replace(ps_ajax.permalink)),t(".passster-submit").on("click",function(e){e.preventDefault();var r=t(this).parent().parent();t(r)[0].checkValidity()||t(r)[0].reportValidity(),ps_id=t(this).attr("data-psid"),r=t("#"+ps_id),password=t("#"+ps_id+" .passster-password").attr("data-password"),type=t("#"+ps_id+" .passster-password").attr("data-protection-type"),list=t("#"+ps_id+" .passster-password").attr("data-list"),area=t("#"+ps_id+" .passster-password").attr("data-area"),protection=t("#"+ps_id+" .passster-password").attr("data-protection"),redirect=t(this).attr("data-redirect"),input=t("#"+ps_id+" .passster-password").val(),acf=t(this).attr("data-acf"),t.ajax({type:"post",dataType:"json",url:ps_ajax.ajax_url,data:{action:"validate_input",nonce:ps_ajax.nonce,input:input,password:password,post_id:ps_ajax.post_id,type:type,list:list,area:area,protection:protection,acf:acf,redirect:redirect},beforeSend:function(){r.find(".ps-loader").css("display","block")},success:function(e){if(r.find(".ps-loader").css("display","none"),!0===e.success){if(ps_ajax.unlock_mode){ps_ajax.disable_cookie||s(input),r.find(".passster-error").hide();let c=e.content;c&&(t.each(ps_ajax.shortcodes,function(t,e){c=c.replace(t,e)}),t("#"+ps_id).replaceWith(c)),e.redirect&&window.location.replace(redirect)}else s(input),e.redirect?window.location.replace(redirect):window.location.href=a()}else r.find(".passster-error").text(e.error),r.find(".passster-error").show().fadeOut(3500),t("#"+ps_id+" .passster-password").val("")}})}),t(".recaptcha-form-v2").length>0&&grecaptcha.ready(function(){grecaptcha.render("ps-recaptcha-v2",{sitekey:ps_ajax.recaptcha_key,callback:function(s){ps_id=t(".recaptcha-v2-submit").attr("data-psid"),form=t("#"+ps_id),protection=t(".recaptcha-v2-submit").attr("data-protection"),acf=t(".recaptcha-v2-submit").attr("data-acf"),area=t("#"+ps_id).find(".recaptcha-v2-submit").attr("data-area"),redirect=t("#"+ps_id).find(".recaptcha-v2-submit").attr("data-redirect"),t.ajax({type:"post",dataType:"json",url:ps_ajax.ajax_url,data:{action:"validate_input",nonce:ps_ajax.nonce,token:s,post_id:ps_ajax.post_id,type:"recaptcha",protection:protection,captcha_id:ps_id,acf:acf,area:area,redirect:redirect},success:function(s){if(!0===s.success){if(ps_ajax.unlock_mode){ps_ajax.disable_cookie||Cookies.set("passster","recaptcha",{expires:e(),sameSite:"strict"}),form.find(".passster-error").hide();let r=s.content;r&&(t.each(ps_ajax.shortcodes,function(t,e){r=r.replace(t,e)}),t("#"+ps_id).replaceWith(r)),s.redirect&&window.location.replace(redirect)}else Cookies.set("passster","recaptcha",{expires:e(),sameSite:"strict"}),s.redirect?window.location.replace(redirect):window.location.href=a()}else form.find(".passster-error").text(s.error),form.find(".passster-error").show().fadeOut(3500)}})}})}),t(".recaptcha-form").on("submit",function(s){s.preventDefault(),ps_id=t(this).find(".passster-submit-recaptcha").attr("data-psid"),form=t("#"+ps_id),protection=t(this).find(".passster-submit-recaptcha").attr("data-protection"),acf=t(this).find(".passster-submit-recaptcha").attr("data-acf"),area=t(this).find(".passster-submit-recaptcha").attr("data-area"),redirect=t(this).find(".passster-submit-recaptcha").attr("data-redirect"),grecaptcha.ready(function(){grecaptcha.execute(ps_ajax.recaptcha_key,{action:"validate_input"}).then(function(s){form.prepend('<input type="hidden" name="token" value="'+s+'">'),form.prepend('<input type="hidden" name="action" value="validate_input">'),t.ajax({type:"post",dataType:"json",url:ps_ajax.ajax_url,data:{action:"validate_input",nonce:ps_ajax.nonce,token:s,post_id:ps_ajax.post_id,type:"recaptcha",protection:protection,captcha_id:ps_id,acf:acf,area:area,redirect:redirect},success:function(s){if(!0===s.success){if(ps_ajax.unlock_mode){ps_ajax.disable_cookie||Cookies.set("passster","recaptcha",{expires:e(),sameSite:"strict"}),form.find(".passster-error").hide();let r=s.content;r&&(t.each(ps_ajax.shortcodes,function(t,e){r=r.replace(t,e)}),form.replaceWith(r)),s.redirect&&window.location.replace(redirect)}else Cookies.set("passster","recaptcha",{expires:e(),sameSite:"strict"}),s.redirect?window.location.replace(redirect):window.location.href=a()}else form.find(".passster-error").text(s.error),form.find(".passster-error").show().fadeOut(3500)}})})})}),t(document).on("click","#ps-logout",function(){t.ajax({type:"post",dataType:"json",url:ps_ajax.ajax_url,data:{action:"handle_logout",logout_nonce:ps_ajax.logout_nonce},success:function(t){!0===t.success&&(Cookies.set("passster","",{expires:0,sameSite:"strict"}),window.location.href=a())}})})}); |
|
1
|
+jQuery(document).ready(function(t){const a=ps_ajax.rest_url+"passster/v1";function e(){switch(ps_ajax.cookie_duration_unit){case"days":default:return parseInt(ps_ajax.cookie_duration);case"hours":return new Date((new Date).getTime()+60*ps_ajax.cookie_duration*60*1e3);case"minutes":return new Date((new Date).getTime()+60*ps_ajax.cookie_duration*1e3)}}function s(){const t="pts="+Math.floor(Date.now()/1e3);return location.origin+location.pathname+(location.search?location.search+"&"+t:"?"+t)+(location.hash||"")}function r(){const t=Cookies.get("passster");return t?t.split("|").filter(t=>t.length>0):[]}function n(a,e,r){if(a.redirect)window.location.replace(a.redirect);else if(ps_ajax.unlock_mode){if(e.find(".passster-error").hide(),a.requires_reload)return void(window.location.href=s());if(a.content){let s=a.content;ps_ajax.shortcodes&&t.each(ps_ajax.shortcodes,function(t,a){s=s.replace(t,a)}),e.replaceWith(s)}r&&window.location.replace(r)}else window.location.href=s()}function i(t,a){const e=t.find(".passster-error");e.text(a||"An error occurred."),e.show().fadeOut(3500)}async function o(t,e,s,r,o,c,p){try{const r=await fetch(a+"/captcha",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,type:e,post_id:ps_ajax.post_id,area_id:o,redirect:c,protection:p||""})}),d=await r.json();d.success?n(d,s,c):i(s,d.error)}catch(t){i(s,"Captcha validation failed.")}}ps_ajax.link_pass&&(ps_ajax.disable_cookie||(ps_ajax.link_pass.length<25?async function(t,s){const n=await async function(t,e){try{const s=await fetch(a+"/hash",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:t,post_id:e})});return(await s.json()).hash||""}catch(t){return""}}(t,s);if(n){const t=r();t.includes(n)||t.push(n),Cookies.set("passster",t.join("|"),{expires:e(),sameSite:"strict"})}}(atob(ps_ajax.link_pass),ps_ajax.post_id).then(()=>{window.location.replace(ps_ajax.permalink+"?pts="+Math.floor(Date.now()/1e3))}):(!function(t){const a=r();a.includes(t)||a.push(t),Cookies.set("passster",a.join("|"),{expires:e(),sameSite:"strict"})}(ps_ajax.link_pass),window.location.replace(ps_ajax.permalink+"?pts="+Math.floor(Date.now()/1e3))))),t(".passster-submit").on("click",async function(e){e.preventDefault();const s=t(this),r=s.attr("data-psid"),o=t("#"+r),c=o.find(".passster-password"),p=parseInt(s.attr("data-post-id"))||ps_ajax.post_id,d=o.find("form")[0];if(d&&!d.checkValidity())return void d.reportValidity();const l=c.val(),h=(c.attr("data-protection-type")||"password").replace(/-/g,"_"),u=parseInt(c.attr("data-area"))||0,f=parseInt(c.attr("data-list"))||0,_=c.attr("data-lists")||"",w=c.attr("data-protection")||"",y=s.attr("data-acf")||"",m=s.attr("data-redirect")||"",j=parseInt(s.attr("data-term-id"))||0,k=s.attr("data-post-type")||"",g=o.closest(".passster-protected-content"),x=g.length?g.attr("data-block-id"):"";o.find(".ps-loader").css("display","block");try{const t=await fetch(a+"/unlock",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:l,type:h,post_id:p,area_id:u,block_id:x,list_id:f,lists:_,protection:w,acf:y,redirect:m,term_id:j,post_type:k})}),e=await t.json();o.find(".ps-loader").css("display","none"),e.success?n(e,o,m):(i(o,e.error),c.val(""))}catch(t){o.find(".ps-loader").css("display","none"),i(o,"An error occurred. Please try again.")}}),t(".recaptcha-form-v2").length>0&&window.grecaptcha&&grecaptcha.ready(function(){grecaptcha.render("ps-recaptcha-v2",{sitekey:ps_ajax.recaptcha_key,callback(a){const e=t(".recaptcha-v2-submit").attr("data-psid"),s=t("#"+e),r=s.find(".recaptcha-v2-submit");o(a,"recaptcha_v2",s,0,parseInt(r.attr("data-area"))||0,r.attr("data-redirect")||"",r.attr("data-protection")||"")}})}),t(".recaptcha-form").on("submit",function(a){a.preventDefault();const e=t(this).find(".passster-submit-recaptcha"),s=e.attr("data-psid"),r=t("#"+s),n=parseInt(e.attr("data-area"))||0,i=e.attr("data-redirect")||"",c=e.attr("data-protection")||"";window.grecaptcha&&grecaptcha.ready(function(){grecaptcha.execute(ps_ajax.recaptcha_key,{action:"validate_input"}).then(function(t){o(t,"recaptcha_v3",r,0,n,i,c)})})}),t(".hcaptcha-form").on("submit",function(a){a.preventDefault();const e=t(this).find(".passster-submit-recaptcha"),s=e.attr("data-psid"),r=t("#"+s),n=parseInt(e.attr("data-area"))||0,c=e.attr("data-redirect")||"",p=e.attr("data-protection")||"";window.hcaptcha&&hcaptcha.execute({async:!0}).then(({response:t})=>{o(t,"hcaptcha",r,0,n,c,p)}).catch(t=>{i(r,t.message||"hCaptcha error")})});let c="";t(".turnstile-form").length>0&&window.turnstile&&(window.turnstile.ready(function(){window.turnstile.render(".passster-turnstile",{sitekey:ps_ajax.turnstile_key,callback(t){c=t}})}),t(".turnstile-form").on("submit",function(a){a.preventDefault();const e=t(this).find(".passster-submit-turnstile"),s=e.attr("data-psid"),r=t("#"+s),n=parseInt(e.attr("data-area"))||0,p=e.attr("data-redirect")||"",d=e.attr("data-protection")||"";c?o(c,"turnstile",r,0,n,p,d):i(r,"Please complete the verification.")})),t(document).on("click","#ps-logout",async function(){try{const t=await fetch(a+"/logout",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"}});(await t.json()).success&&(Cookies.set("passster","",{expires:0,sameSite:"strict"}),window.location.href=s())}catch(t){window.location.href=s()}})}); |