Files
wingedit.pl/wp-content/plugins/mailchimp-for-wp/assets/js/email-typo-checker.js
2026-03-11 15:57:27 +01:00

1 line
2.2 KiB
JavaScript

(()=>{const e=window.mc4wp_email_typo_checker&&window.mc4wp_email_typo_checker.domains?window.mc4wp_email_typo_checker.domains:[];function t(e,t){if(e===t)return 0;if(e.length>t.length){const n=e;e=t,t=n}let o=e.length,c=t.length;for(;o>0&&e.charCodeAt(o-1)===t.charCodeAt(c-1);)o--,c--;let r=0;for(;r<o&&e.charCodeAt(r)===t.charCodeAt(r);)r++;if(o-=r,c-=r,0===o||c<3)return c;let i,l,u,a,s,d,f,h,m,p,w,_,g=0;const C=[];for(i=0;i<o;i++)C.push(i+1),C.push(e.charCodeAt(r+i));const y=C.length-1;for(;g<c-3;)for(m=t.charCodeAt(r+(l=g)),p=t.charCodeAt(r+(u=g+1)),w=t.charCodeAt(r+(a=g+2)),_=t.charCodeAt(r+(s=g+3)),d=g+=4,i=0;i<y;i+=2)f=C[i],h=C[i+1],l=n(f,l,u,m,h),u=n(l,u,a,p,h),a=n(u,a,s,w,h),d=n(a,s,d,_,h),C[i]=d,s=a,a=u,u=l,l=f;for(;g<c;)for(m=t.charCodeAt(r+(l=g)),d=++g,i=0;i<y;i+=2)f=C[i],C[i]=d=n(f,l,d,m,C[i+1]),l=f;return d}function n(e,t,n,o,c){return e<t||n<t?e>n?n+1:e+1:o===c?t:t+1}function o(e){const t=e.parentElement.querySelector(".mc4wp-email-suggestion");t&&t.remove()}function c(n){const c=n.value.trim();if(o(n),!c||-1===c.indexOf("@"))return;const r=function(e){const t=e.split("@");return 2===t.length?t[1]:null}(c);if(!r)return;const i=function(n){if(!n)return null;const o=n.toLowerCase();let c=1/0,r=null;if(e.includes(o))return null;for(let n=0;n<e.length;n++){const i=e[n],l=t(o,i);l>0&&l<=2&&l<c&&(c=l,r=i)}return r}(r);if(i){const e=function(e,t){const n=document.createElement("div");n.className="mc4wp-email-suggestion";const c=document.createElement("a");c.setAttribute("href","#");const r=window.mc4wp_email_typo_checker&&window.mc4wp_email_typo_checker.suggestion_text?window.mc4wp_email_typo_checker.suggestion_text:"Did you mean %s?";return c.textContent=r.replace("%s",e),c.addEventListener("click",function(n){n.preventDefault(),t.value=e,o(t);const c=new Event("change",{bubbles:!0});t.dispatchEvent(c)}),n.appendChild(c),n}(c.split("@")[0]+"@"+i,n);n.after(e)}}function r(e){e.querySelectorAll('input[type="email"]').forEach(function(e){e.addEventListener("keyup",function(){c(e)}),e.addEventListener("blur",function(){c(e)})})}document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll('.mc4wp-form[data-typo-check="1"]').forEach(r)})})();