Clearmeadow / website · clearmeadow.ai / careers / careers.js
| 1 | (function(){var f=document.getElementById('cr-form');if(!f)return;var m=document.getElementById('cr-msg'); |
| 2 | var E=f.elements,k=E['kind'],box=document.getElementById('cr-tech'); |
| 3 | function sync(){var on=k&&k.value==='tech';if(box)box.hidden=!on;if(E['github'])E['github'].required=on;if(E['homepage'])E['homepage'].required=on;} |
| 4 | if(k){k.addEventListener('change',sync);sync();} |
| 5 | function url(v){v=(v||'').trim();if(v&&!/^https?:\/\//i.test(v))v='https://'+v;return v;} |
| 6 | f.addEventListener('submit',function(e){e.preventDefault(); |
| 7 | var n=(E['name'].value||'').trim(),em=(E['email'].value||'').trim(),t=E['request'].value.trim(),kind=k?k.value:'',gh='',hp=''; |
| 8 | if(!n){m.textContent='Please add your name.';return;} |
| 9 | if(!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(em)){m.textContent='Please add a valid email.';return;} |
| 10 | if(k&&!kind){m.textContent='Please choose what kind of work.';return;} |
| 11 | if(kind==='tech'){gh=url(E['github'].value);hp=url(E['homepage'].value); |
| 12 | if(!/^https:\/\/(www\.)?(github\.com|branchwell\.ai)\/[A-Za-z0-9_.-]+/i.test(gh.replace(/^http:/i,'https:'))){m.textContent='Tech roles need your Branchwell profile link.';return;} |
| 13 | if(!/^https?:\/\/[^\s\/]+\.[^\s\/]{2,}/i.test(hp)||/^https?:\/\/(www\.)?(github\.com|branchwell\.ai)(\/|$)/i.test(hp)){m.textContent='Tech roles need a link to your own website too.';return;}} |
| 14 | if(!t){m.textContent='Please write a short message.';return;} |
| 15 | var head='Name: '+n+'\nEmail: '+em+(kind?'\nKind of work: '+(kind==='tech'?'Tech':'Everything else'):'')+(gh?'\nBranchwell: '+gh:'')+(hp?'\nWebsite: '+hp:''); |
| 16 | var b=f.querySelector('button');b.disabled=true;m.textContent='Sending…'; |
| 17 | fetch('/api/request',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({request:head+'\n\n'+t,name:n,email:em,message:t,kind:kind,github:gh,homepage:hp,site:location.hostname,website:E['website'].value})}) |
| 18 | .then(function(r){if(!r.ok)throw 0;f.reset();sync();m.textContent='Thanks. We got your note and will be in touch about joining our team.';}) |
| 19 | .catch(function(){m.textContent='That didn’t go through. Please try again in a minute.';}) |
| 20 | .then(function(){b.disabled=false;});});})(); |