PageSourceSearch

https://orases.com/wp-content/cache/min/1/wp-content/themes/orases…/js/hubspot-modifiers.js?ver=1789074674

js orases.com collected 2026-09-24 22:52:14 UTC 7,826 bytes, 33 lines download raw bytes

1if(!sessionStorage.getItem("original_referrer")){sessionStorage.setItem("original_referrer",document.referrer||"direct")}
2function getHubspotForms(){return document.querySelectorAll(".hbspt-form form, .hs-form-html form")}
3function getCookie(name){const match=document.cookie.match(new RegExp("(^| )"+name+"=([^;]+)"));return match?match[2]:null}
4let resolvedGeo=null;function parseGeoCookie(raw){try{const decoded=decodeURIComponent(raw);const geoObj=JSON.parse(decoded);const str=typeof geoObj==="object"?`${geoObj.city}, ${geoObj.region}, ${geoObj.country}`:String(geoObj);return str.includes("undefined")?null:str}catch{const cleaned=decodeURIComponent(raw).replace(/"/g,"");return cleaned.includes("undefined")?null:cleaned}}
5function waitForGeoCookie(callback,attempts=20){const raw=getCookie("orases_geoip_data");if(raw){callback(parseGeoCookie(raw))}else if(attempts>0){setTimeout(()=>waitForGeoCookie(callback,attempts-1),500)}}
6const RECAPTCHA_SITE_KEY=orasesConfig.recaptchaSiteKey;const RECAPTCHA_VERIFY_ENDPOINT=orasesConfig.recaptchaEndpoint;function getRecaptchaToken(){return new Promise(function(resolve){function execute(){grecaptcha.ready(function(){grecaptcha.execute(RECAPTCHA_SITE_KEY,{action:"submit"}).then(function(token){resolve(token)}).catch(function(){resolve(null)})})}
7if(typeof grecaptcha!=="undefined"){execute();return}
8var waitedMs=0;var MAX_WAIT_MS=10000;var interval=setInterval(function(){waitedMs+=250;if(typeof grecaptcha!=="undefined"){clearInterval(interval);execute()}else if(waitedMs>=MAX_WAIT_MS){clearInterval(interval);resolve(null)}},250)})}
9function verifyRecaptchaToken(){return getRecaptchaToken().then(function(token){if(!token)return!1;return fetch(RECAPTCHA_VERIFY_ENDPOINT,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:token}),}).then(function(res){return res.json()}).then(function(data){return data.success===!0}).catch(function(){return!1})})}
10function blockRestrictedCountries(locationStr){const blockedCountries=["ME","ZA","IN","NG","BG","PK","BD","TR","SG","LK","PH","VN","OM","IQ","ZM"];const parts=locationStr.split(",");const countryCode=parts.length?parts[parts.length-1].trim():"";if(blockedCountries.includes(countryCode)){getHubspotForms().forEac
10h(form=>{const submitBtn=form.querySelector("input[type='submit'], button[type='submit']");if(submitBtn){submitBtn.disabled=!0;submitBtn.style.opacity="0.5";submitBtn.style.cursor="not-allowed"}
11if(!form.querySelector(".geo-block-msg")){const msg=document.createElement("p");msg.className="geo-block-msg";msg.innerText="Sorry, we do not accept submissions from your location.";form.appendChild(msg)}})}}
12function applyPhoneMask(){document.querySelectorAll("input[name$='phone']").forEach(function(phoneInput){if(phoneInput.dataset.maskApplied)return;phoneInput.dataset.maskApplied="true";phoneInput.setAttribute("placeholder","(___) ___-____");phoneInput.setAttribute("maxlength","14");phoneInput.addEventListener("input",function(e){let value=e.target.value.replace(/\D/g,"").substring(0,10);let formatted="";if(value.length>0)formatted="("+value.substring(0,3);if(value.length>=3)formatted="("+value.substring(0,3)+") ";if(value.length>=4)formatted+=value.substring(3,6);if(value.length>=7)formatted+="-"+value.substring(6,10);e.target.value=formatted})})}
13function markFieldsActive(){const form=document.querySelector('.hs-form-html form');if(!form)return;const containers=form.querySelectorAll('.hsfc-Row > div');Array.prototype.forEach.call(containers,function(container){const isPhoneField=container.classList.contains('hsfc-PhoneField');if(isPhoneField){const phoneInput=container.querySelector('.hsfc-PhoneInput');phoneInput.addEventListener('click',function(){container.classList.add('active')});return}
14const field=container.querySelector(':scope > .hsfc-TextInput, :scope > .hsfc-DropdownInput, :scope > .hsfc-TextareaInput, :scope > .hsfc-PhoneField');if(!field)return;const input=field.matches('.hsfc-DropdownInput')?field.querySelector('input, select'):field.querySelector('input, textarea')||field;container.addEventListener('focusin',function(){container.classList.add('active')});container.addEventListener('focusout',function(e){if(container.contains(e.relatedTarget))return;if(!input||!input.value){container.classList.remove('active')}});if(input&&input.value){container.classList.add('active')}})}
15function getTrackingValues(){return{landing_page:sessionStorage.getItem("landing_url")||window.location.pathname+window.location.search,conversion_page:window.location.pathname,orases_referrer:sessionStorage.getItem("original_referrer")==="direct"?"":(sessionStorage.getItem("original_referrer")||""),geolocated:resolvedGeo||"",}}
16function stampDOMFields(){const tracking=getTrackingValues();
16getHubspotForms().forEach(form=>{Object.entries(tracking).forEach(([name,value])=>{form.querySelectorAll(`[name$="${name}"]`).forEach(el=>{el.value=value??""})})})}
17function isHubSpotRequest(body){if(typeof body==="string"){return body.includes("hs_context")||body.includes("submittedAt")}
18if(body instanceof FormData){return body.has("hs_context")||body.has("submittedAt")}
19return!1}
20function injectTrackingIntoBody(body){const tracking=getTrackingValues();if(typeof body==="string"){const extra=Object.entries(tracking).map(([k,v])=>`${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");return body+(body?"&":"")+extra}
21if(body instanceof FormData){Object.entries(tracking).forEach(([k,v])=>body.set(k,v));return body}
22return body}
23function showRecaptchaError(){getHubspotForms().forEach(function(form){if(form.querySelector(".recaptcha-error-msg"))return;const msg=document.createElement("p");msg.className="recaptcha-error-msg";msg.style.color="red";msg.innerText="Your submission could not be verified. Please try again.";form.appendChild(msg);setTimeout(function(){msg.remove()},5000)})}
24function patchXHR(){const OriginalXHR=window.XMLHttpRequest;function PatchedXHR(){const xhr=new OriginalXHR();const originalSend=xhr.send.bind(xhr);xhr.send=function(body){if(!isHubSpotRequest(body)){originalSend(body);return}
25verifyRecaptchaToken().then(function(passed){if(!passed){showRecaptchaError();return}
26originalSend(injectTrackingIntoBody(body))})};return xhr}
27Object.setPrototypeOf(PatchedXHR,OriginalXHR);PatchedXHR.prototype=OriginalXHR.prototype;window.XMLHttpRequest=PatchedXHR}
28function patchFetch(){const originalFetch=window.fetch.bind(window);window.fetch=function(input,init={}){if(!init.body||!isHubSpotRequest(init.body)){return originalFetch(input,init)}
29return verifyRecaptchaToken().then(function(passed){if(!passed){showRecaptchaError();return Promise.reject(new Error("reCAPTCHA verification failed"))}
30init.body=injectTrackingIntoBody(init.body);return originalFetch(input,init)})}}
31function revealFormWhenReady(){document.querySelectorAll('.hs-form-html').forEach(host=>{if(host.dataset.readyWatched)return;host.dataset.readyWatched='true';let quietTimer=null;const QUIET_MS=300;const MAX_WAIT=5000;const markReady=()=>{if(host.classList.contains('form-ready'))return;applyPhoneMask();markFieldsActive();stampDOMFields();host.classList.add('form-ready')};const observer=new MutationObserver(()=>{clearTimeout(quietTimer);quietTimer=setTimeout(markReady,QUIET_MS)});observer.observe(host,{childList:!0,subtree:!0});quietTimer=setTimeout(markReady,QUIET_MS);setTimeout(markReady,MAX_WAIT)})}
32function watchForReRenders(){document.querySelectorAll(".hbspt-form, .hs-form-html").forEach(container=>{new MutationObserver(()=>{applyPhoneMask();stampDOMFields()}).observe(container,{childList:!0,subtree:!0})})}
33patchXHR();patchFetch();window.addEventListener("load",function(){waitForGeoCookie(function(geo){resolvedGeo=geo;setTimeout(function(){revealFormWhenReady();watchForReRenders();if(geo)blockRestrictedCountries(geo)},2000)})})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.