(function(){ /* ============================================================ AI HAIRSTYLE CHANGER FOR MEN - by Face Shape (v4) - Aspect-ratio preserved (no tall-photo distortion) - Wide smaller/bigger range (0.2x - 5.0x) - 19 hair colors (browns-heavy), default = Dark Brown - Aggressive immediate preload (no upload lag) - hcHeroSwap + result panel + camera + thank-you killer ============================================================ */ var HC_CUTS=[ {k:"buzzcut",n:"Buzzcut",u:"https://profreetools.online/wp-content/uploads/2026/06/1.-Buzzcut.webp"}, {k:"crewcut",n:"Crew Cut",u:"https://profreetools.online/wp-content/uploads/2026/06/2.-Crew-Cut.webp"}, {k:"pompadour",n:"Pompadour",u:"https://profreetools.online/wp-content/uploads/2026/06/3.-Pompadour.webp"}, {k:"taperfade",n:"Taper Fade",u:"https://profreetools.online/wp-content/uploads/2026/06/4.-Taper-Fade.webp"}, {k:"texturedcrop",n:"Textured Crop",u:"https://profreetools.online/wp-content/uploads/2026/06/5.-Textured-Crop.webp"}, {k:"combover",n:"Comb Over",u:"https://profreetools.online/wp-content/uploads/2026/06/6.-Comb-Over.webp"}, {k:"slickback",n:"Slick Back",u:"https://profreetools.online/wp-content/uploads/2026/06/7.-Slick-Back.webp"}, {k:"quiff",n:"Quiff",u:"https://profreetools.online/wp-content/uploads/2026/06/8.-Quiff.webp"}, {k:"wavylong",n:"Textured Wavy",u:"https://profreetools.online/wp-content/uploads/2026/06/LONG-Hair-9-Textured-Wavy-Long.webp"}, {k:"koreancomma",n:"Korean Comma",u:"https://profreetools.online/wp-content/uploads/2026/06/10.-Korean-Comma.webp"}, {k:"curtain",n:"Curtain",u:"https://profreetools.online/wp-content/uploads/2026/06/11.-Curtain-Middle-Part.webp"}, {k:"manbun",n:"Man Bun",u:"https://profreetools.online/wp-content/uploads/2026/06/12.-Man-Bun.webp"}, {k:"burstmohawk",n:"Burst Mohawk",u:"https://profreetools.online/wp-content/uploads/2026/06/NEW-unique-tendy-13.-Burst-Fade-Mohawk.webp"}, {k:"fringedesign",n:"Textured Fringe",u:"https://profreetools.online/wp-content/uploads/2026/06/14.-Textured-Fringe-with-Design.webp"}, {k:"mullet",n:"Modern Mullet",u:"https://profreetools.online/wp-content/uploads/2026/06/15.-Modern-Mullet.webp"}, {k:"flowhockey",n:"Flow / Hockey",u:"https://profreetools.online/wp-content/uploads/2026/06/16.-Flow-Hockey-Hair.webp"}, {k:"edgar",n:"Edgar Cut",u:"https://profreetools.online/wp-content/uploads/2026/06/17.-Edgar-Cut.webp"}, {k:"wolfcut",n:"Wolf Cut",u:"https://profreetools.online/wp-content/uploads/2026/06/18.-Wolf-Cut-Male.webp"} ]; var STYLE_FIT={ buzzcut: {wMul:1.05,yMul:-0.05}, crewcut: {wMul:1.08,yMul:-0.05}, pompadour: {wMul:1.12,yMul:-0.04}, taperfade: {wMul:1.08,yMul:-0.05}, texturedcrop:{wMul:1.10,yMul:-0.05}, combover: {wMul:1.14,yMul:-0.05}, slickback: {wMul:1.10,yMul:-0.05}, quiff: {wMul:1.12,yMul:-0.04}, wavylong: {wMul:1.22,yMul:-0.06}, koreancomma: {wMul:1.16,yMul:-0.05}, curtain: {wMul:1.16,yMul:-0.05}, manbun: {wMul:1.10,yMul:-0.05}, burstmohawk: {wMul:1.08,yMul:-0.04}, fringedesign:{wMul:1.14,yMul:-0.05}, mullet: {wMul:1.22,yMul:-0.05}, flowhockey: {wMul:1.22,yMul:-0.05}, edgar: {wMul:1.12,yMul:-0.05}, wolfcut: {wMul:1.24,yMul:-0.05} }; /* 19 colors - browns first, default = index 0 (Dark Brown) */ var HC_COLORS=[ {n:"Dark Brown",c:"#3b2417",t:"#3b2417"}, {n:"Medium Brown",c:"#54381f",t:"#54381f"}, {n:"Light Brown",c:"#6b4a2f",t:"#6b4a2f"}, {n:"Chestnut",c:"#4a2c20",t:"#4a2c20"}, {n:"Caramel",c:"#8a5a2e",t:"#8a5a2e"}, {n:"Ash Brown",c:"#6e5b4a",t:"#6e5b4a"}, {n:"Golden Brown",c:"#7d5320",t:"#7d5320"}, {n:"Natural Black",c:"#1a1a1a",t:"#1a1a1a"}, {n:"Soft Black",c:"#2b2b2b",t:"#2b2b2b"}, {n:"Dark Blonde",c:"#9c7c4d",t:"#9c7c4d"}, {n:"Golden Blonde",c:"#c9a24b",t:"#c9a24b"}, {n:"Ash Gray",c:"#8a8a8f",t:"#9a9aa0"}, {n:"Platinum Silver",c:"#cfcfd6",t:"#d8d8de"}, {n:"Copper Red",c:"#a8521f",t:"#a8521f"}, {n:"Auburn",c:"#6a2e1f",t:"#6a2e1f"}, {n:"Burgundy",c:"#5c2230",t:"#5c2230"}, {n:"Ice Blue",c:"#5b8fb0",t:"#5b8fb0"}, {n:"Smoky Purple",c:"#6e5a86",t:"#6e5a86"}, {n:"Steel Blue Black",c:"#2a3340",t:"#2a3340"} ]; var HC_DEFAULT_COLOR=0; /* Dark Brown */ var HC_BEST={ oval:["texturedcrop","pompadour","quiff","combover"], round:["pompadour","quiff","fringedesign","slickback"], square:["taperfade","texturedcrop","crewcut","buzzcut"], oblong:["combover","fringedesign","texturedcrop","edgar"], diamond:["texturedcrop","fringedesign","quiff","curtain"], heart:["combover","curtain","wavylong","koreancomma"], triangle:["pompadour","quiff","slickback","wavylong"] }; var HC_NARRATIVE={ oval:"balanced symmetrical proportions", round:"softer curves and equal length-width", square:"a strong defined jawline", oblong:"a longer vertical face length", diamond:"prominent cheekbones with narrower forehead and chin", heart:"a wider forehead tapering to a narrow chin", triangle:"a broader jawline narrowing toward the forehead" }; var HC={api:null,img:null,box:null,marks:null,shape:null,conf:0,scores:null,sym:0,frame:0,overall:0, activeCut:"texturedcrop",activeColor:HC_DEFAULT_COLOR, loaded:false,loading:false,cbs:[],cache:{}, hX:0,hY:0,hS:1,camStream:null}; function hcEl(id){return document.getElementById(id);} function hcQA(s){return document.querySelectorAll(s);} function hcStatus(t,sp){var x=hcEl("hc-status");if(!x)return;if(!t){x.classList.remove("show");x.innerHTML="";return;}x.innerHTML=(sp?'
':"")+'
'+t+"
";x.classList.add("show");} function hcCap(s){return s?s.charAt(0).toUpperCase()+s.slice(1):"";} function hcHeroSwap(on){var r=hcEl("hc-root");if(!r)return;if(on){r.classList.add("hc-active");}else{r.classList.remove("hc-active");}} /* ---------- FACE-API LOADING ---------- */ function hcLoadApi(cb){ if(window.faceapi){HC.api=window.faceapi;hcLoadModels(cb);return;} var s=document.createElement("script"); s.src="https://cdn.jsdelivr.net/npm/@vladmandic/face-api/dist/face-api.js"; s.onload=function(){HC.api=window.faceapi;hcLoadModels(cb);}; s.onerror=function(){ var s2=document.createElement("script"); s2.src="https://unpkg.com/@vladmandic/face-api/dist/face-api.js"; s2.onload=function(){HC.api=window.faceapi;hcLoadModels(cb);}; s2.onerror=function(){hcStatus("Could not load AI engine. Check connection.",false);}; document.head.appendChild(s2); }; document.head.appendChild(s); } function hcLoadModels(cb){ if(HC.loaded){cb&&cb();return;} if(HC.loading){if(cb)HC.cbs.push(cb);return;} HC.loading=true;if(cb)HC.cbs.push(cb); var f=HC.api; var srcs=["https://cdn.jsdelivr.net/npm/@vladmandic/face-api/model","https://unpkg.com/@vladmandic/face-api/model"]; function go(i){ if(i>=srcs.length){HC.loading=false;hcStatus("Could not load AI model.",false);return;} Promise.all([ f.nets.tinyFaceDetector.loadFromUri(srcs[i]), f.nets.faceLandmark68Net.loadFromUri(srcs[i]) ]).then(function(){ HC.loaded=true;HC.loading=false; var q=HC.cbs;HC.cbs=[]; for(var k=0;kbv){bv=sc[k];best=k;} var c=Math.round(60+bv*35);if(c>95)c=95;if(c<60)c=60; HC.shape=best;HC.conf=c;HC.scores=sc; } function hcMetrics(p){ var nx=p[27].x; var pairs=[[0,16],[1,15],[2,14],[3,13],[4,12],[5,11],[6,10],[7,9],[17,26],[18,25],[19,24],[20,23],[21,22],[36,45],[39,42]]; var totDiff=0,totRef=0; for(var i=0;i0?(1-(totDiff/totRef)):0; HC.sym=Math.max(70,Math.min(98,Math.round(symRatio*100))); var topScore=0;for(var k in HC.scores)if(HC.scores[k]>topScore)topScore=HC.scores[k]; HC.frame=Math.max(75,Math.min(96,Math.round(70+topScore*28))); HC.overall=Math.round(HC.sym*0.45+HC.frame*0.55); } /* ---------- IMAGE LOADER ---------- */ function hcLoadImg(url,key,cb){ if(HC.cache[key]){cb(HC.cache[key]);return;} var im=new Image();im.crossOrigin="anonymous"; im.onload=function(){HC.cache[key]=im;cb(im);}; im.onerror=function(){var im2=new Image();im2.onload=function(){HC.cache[key]=im2;cb(im2);};im2.onerror=function(){cb(null);};im2.src=url;}; im.src=url; } /* ---------- RENDER (aspect-ratio preserved) ---------- */ function hcRender(){ var c=hcEl("hc-canvas"),im=HC.img; if(!c||!im)return; /* preserve photo aspect ratio - cap by longer side, no distortion */ var maxW=560,maxH=760,ratio=im.width/im.height,W,H; if(im.width/maxW>=im.height/maxH){W=maxW;H=Math.round(maxW/ratio);} else{H=maxH;W=Math.round(maxH*ratio);} if(W<1)W=1;if(H<1)H=1; c.width=W;c.height=H; var ctx=c.getContext("2d"); ctx.clearRect(0,0,W,H);ctx.drawImage(im,0,0,W,H); c.style.display="block"; var adj=hcEl("hc-adjust");if(adj)adj.classList.add("show"); var cut=null;for(var i=0;i232&&(mx-mn)<24){d[i+3]=0;continue;} if(avg>205&&(mx-mn)<20){var ff=1-((avg-205)/27);d[i+3]=Math.round(d[i+3]*Math.max(0,ff));} /* blue-edge halo cleanup: bluish + low-alpha-ish edge pixels -> reduce alpha */ if(bb>r+22&&bb>g+14&&avg<150){d[i+3]=Math.round(d[i+3]*0.25);} if(tint&&d[i+3]>0){d[i]=Math.round(r*tint.r/255);d[i+1]=Math.round(g*tint.g/255);d[i+2]=Math.round(bb*tint.b/255);} } octx.putImageData(data,0,0); }catch(err){pixelOK=false;} if(pixelOK){ctx.drawImage(oc,x,y,w,h);} else{ if(color&&color.t){octx.globalCompositeOperation="multiply";octx.fillStyle=color.t;octx.fillRect(0,0,W,H2);octx.globalCompositeOperation="source-over";} ctx.save();ctx.globalCompositeOperation="multiply";ctx.drawImage(oc,x,y,w,h);ctx.restore(); } } /* ---------- RESULT PANEL ---------- */ function hcRenderResult(){ var rp=hcEl("hc-result");if(!rp)return; rp.classList.add("show"); var emp=hcEl("hc-result-empty");if(emp)emp.style.display="none"; var chip=hcEl("hc-chip");if(chip)chip.innerHTML='DETECTED  '+hcCap(HC.shape)+' Face  · '+HC.conf+'%'; var s=hcEl("hc-sym-v"),fr=hcEl("hc-frame-v"),ov=hcEl("hc-ov-v"); if(s)s.textContent=HC.sym+"%"; if(fr)fr.textContent=HC.frame+"%"; if(ov)ov.textContent=HC.overall+"%"; var sR=hcEl("hc-sym-ring"),fR=hcEl("hc-frame-ring"),oR=hcEl("hc-ov-ring"); if(sR)sR.setAttribute("stroke-dasharray",(HC.sym*1.759)+" 999"); if(fR)fR.setAttribute("stroke-dasharray",(HC.frame*1.759)+" 999"); if(oR)oR.setAttribute("stroke-dasharray",(HC.overall*1.759)+" 999"); var nm=hcEl("hc-narr"); if(nm){ var cutName="";for(var i=0;i with '+HC_NARRATIVE[HC.shape]+', our system recommends '+cutName+' styles that complement your features without overpowering them.'; } var bars=hcEl("hc-bars");if(bars){ bars.innerHTML=""; var order=["oval","round","square","heart","diamond","oblong","triangle"]; var tot=0;for(var k in HC.scores)tot+=HC.scores[k];if(tot<=0)tot=1; order.forEach(function(sh){ var pct=Math.round((HC.scores[sh]/tot)*100);if(pct<0)pct=0; var row=document.createElement("div");row.className="hc-brow"; row.innerHTML='
'+hcCap(sh)+''+pct.toFixed(1)+'%
'; bars.appendChild(row); }); } var bh=hcEl("hc-besthint");if(bh)bh.textContent="Best cuts for your "+hcCap(HC.shape)+" face shown first"; } /* ---------- BUILD UI ---------- */ function hcBuildCuts(){ var g=hcEl("hc-cutgrid");if(!g)return;g.innerHTML=""; var bl=HC_BEST[HC.shape||"oval"]||[]; var ordered=[],seen={}; bl.forEach(function(k){for(var i=0;iBEST FIT':"")+''+ct.n+' hairstyle for men'+ct.n+''; d.addEventListener("click",function(){ var all=g.querySelectorAll(".hc-cut");for(var j=0;jUpload your photo'; }); } } /* ---------- THANK-YOU KILLER ---------- */ function hcKillThankYou(){ function kill(){ try{ var nodes=document.querySelectorAll("p,div,span,h2,h3,h4"); for(var i=0;i0&&txt.length<140&&txt.indexOf("thank you for reading")>=0&&txt.indexOf("subscribe")>=0){ n.style.display="none";n.style.visibility="hidden";n.setAttribute("aria-hidden","true"); } n.__hcChecked=true; } }catch(e){} } kill(); try{var obs=new MutationObserver(function(){kill();});obs.observe(document.body,{childList:true,subtree:true});setTimeout(function(){obs.disconnect();},10000);}catch(e){} setTimeout(kill,300);setTimeout(kill,1000);setTimeout(kill,2500);setTimeout(kill,5000); } /* ---------- BOOT ---------- */ function hcInit(){ hcBuildCuts();hcBuildColors();hcInitTabs();hcInitAdjust();hcInitButtons();hcArmPreload();hcKillThankYou(); } var hcTries=0,hcDone=false; function hcRetry(){ if(hcDone)return; if(hcEl("hc-cutgrid")&&hcEl("hc-upload")){try{hcInit();hcDone=true;}catch(err){if(window.console)console.log("HC err:",err);}} if(!hcDone&&hcTries<200){hcTries++;setTimeout(hcRetry,120);} } if(document.readyState!=="loading"){hcRetry();}else{document.addEventListener("DOMContentLoaded",hcRetry);} window.addEventListener("load",function(){if(!hcDone)hcRetry();}); setTimeout(hcRetry,500);setTimeout(hcRetry,1500);setTimeout(hcRetry,3000); })();