| 1 | (function(){ |
| 2 | var d=document,root=d.documentElement; |
| 3 | function $(s,c){return (c||d).querySelector(s)} |
| 4 | function $$(s,c){return Array.prototype.slice.call((c||d).querySelectorAll(s))} |
| 5 | var reduce=window.matchMedia&&matchMedia("(prefers-reduced-motion:reduce)").matches; |
| 6 | |
| 7 | // theme toggle |
| 8 | var tb=$("#theme"); |
| 9 | if(tb)tb.addEventListener("click",function(){ |
| 10 | var dark=root.dataset.theme?root.dataset.theme==="dark":matchMedia("(prefers-color-scheme:dark)").matches; |
| 11 | var next=dark?"light":"dark"; |
| 12 | if(!reduce){root.classList.add("theme-anim");setTimeout(function(){root.classList.remove("theme-anim")},450)} |
| 13 | root.dataset.theme=next; |
| 14 | try{localStorage.setItem("theme",next)}catch(e){} |
| 15 | }); |
| 16 | |
| 17 | // mobile menu |
| 18 | var bg=$("#burger"),menu=$("#menu"); |
| 19 | if(bg)bg.addEventListener("click",function(){ |
| 20 | var o=menu.classList.toggle("open");bg.setAttribute("aria-expanded",o)}); |
| 21 | $$("#menu a").forEach(function(a){a.addEventListener("click",function(){menu.classList.remove("open");bg.setAttribute("aria-expanded","false")})}); |
| 22 | |
| 23 | // reveals + rule draw |
| 24 | function onceIn(els,cb){ |
| 25 | if(!("IntersectionObserver" in window)){els.forEach(cb);return} |
| 26 | var io=new IntersectionObserver(function(es){es.forEach(function(e){ |
| 27 | if(e.isIntersecting){cb(e.target);io.unobserve(e.target)}})},{rootMargin:"0px 0px -12% 0px"}); |
| 28 | els.forEach(function(e){io.observe(e)}); |
| 29 | } |
| 30 | onceIn($$("[data-reveal]"),function(el){ |
| 31 | var sib=el.parentNode.children; |
| 32 | var i=Array.prototype.indexOf.call(sib,el); |
| 33 | el.style.transitionDelay=(i%4)*0.08+"s"; |
| 34 | el.classList.add("in"); |
| 35 | setTimeout(function(){el.style.transitionDelay=""},1300); |
| 36 | }); |
| 37 | onceIn($$(".section-rule"),function(el){el.classList.add("in")}); |
| 38 | |
| 39 | // OS detection |
| 40 | var ua=(navigator.userAgent||"")+" "+(navigator.platform||""); |
| 41 | var os=/Android|iPhone|iPad/.test(ua)?null:/Win/i.test(ua)?"windows":/Mac/i.test(ua)?"mac":/Linux|X11/i.test(ua)?"linux":null; |
| 42 | var names={windows:"Windows",linux:"Linux",mac:"macOS"}; |
| 43 | if(os){ |
| 44 | var card=$('[data-os="'+os+'"]'); |
| 45 | if(card){ |
| 46 | card.classList.add("yours"); |
| 47 | var pl=$(".plabel",card);pl.textContent="Your system";pl.classList.add("yl"); |
| 48 | var b=$("[data-primary]",card);b.classList.remove("btn-out");b.classList.add("btn-solid"); |
| 49 | } |
| 50 | var h=$("#os-hint");if(h)h.textContent="Detected "+names[os]+" · also Windows, Linux, macOS"; |
| 51 | var nt=$("#os-note");if(nt)nt.textContent="Your system: "+names[os]; |
| 52 | } |
| 53 | |
| 54 | // copy |
| 55 | function flash(el,label){var o=el.textContent;el.textContent=label;setTimeout(function(){el.textContent=o},1400)} |
| 56 | var cc=$("#copy-cmd"); |
| 57 | if(cc)cc.addEventListener("click",function(){ |
| 58 | if(navigator.clipboard)navigator.clipboard.writeText($("#cmd").textContent).then(function(){flash($("span",cc),"Copied")},function(){}); |
| 59 | }); |
| 60 | var cl=$("#copy-link"); |
| 61 | if(cl)cl.addEventListener("click",function(){ |
| 62 | if(navigator.clipboard)navigator.clipboard.writeText(location.href.split("#")[0]).then(function(){flash(cl.lastChild,"Copied")},function(){}); |
| 63 | }); |
| 64 | |
| 65 | // ruler + breadcrumb |
| 66 | var ruler=$("#ruler"); |
| 67 | if(!ruler||getComputedStyle(ruler).display==="none")return; |
| 68 | var band=$("#band"),needle=$("#needle"),pct=$("#pct"); |
| 69 | for(var i=0;i<=40;i++){ |
| 70 | var m=d.createElement("span");m.className="mk"+(i%4===0?" maj":"");m.style.top=(i/40*100)+"%"; |
| 71 | if(i%4===0){var t=d.createElement("i");t.textContent=i*2.5;m.appendChild(t)} |
| 72 | ruler.insertBefore(m,band); |
| 73 | } |
| 74 | function update(){ |
| 75 | var H=root.scrollHeight,vh=innerHeight,max=Math.max(1,H-vh),p=Math.min(1,Math.max(0,scrollY/max)); |
| 76 | needle.style.top=(p*100)+"%"; |
| 77 | band.style.top=(scrollY/H*100)+"%";band.style.height=(vh/H*100)+"%"; |
| 78 | var v=Math.round(p*100);pct.textContent=("00"+v).slice(-3)+" %"; |
| 79 | ruler.setAttribute("aria-valuenow",v); |
| 80 | } |
| 81 | addEventListener("scroll",update,{passive:true});addEventListener("resize",update);update(); |
| 82 | ruler.addEventListener("click",function(e){ |
| 83 | scrollTo({top:e.clientY/innerHeight*(root.scrollHeight-innerHeight),behavior:reduce?"auto":"smooth"}); |
| 84 | }); |
| 85 | })(); |