(function(){leti="",u="",d="";asyncfunctionl(){for(leto=0;o<5;o++){try{constn=window.Clerk;if(n&&!n.user)returnnull;if(n?.session?.getToken){consts=awaitn.session.getToken();if(s)returns}}catch{}o<4&&awaitnewPromise(n=>setTimeout(n,800))}returnnull}asyncfunctionh(){conste=window.location.hostname;if(!(e==="160.191.50.138"||e==="localhost"||e.includes("opennotion")||e.includes("cucunote")||e.includes("cucu-note")))return;consto=awaitl();o&&chrome.runtime.sendMessage({type:"SYNC_AUTH",data:{clerkSessionToken:o}})}h();chrome.runtime.onMessage.addListener((e,t,o)=>{if(e.type==="GET_CLERK_TOKEN")returnl().then(n=>{o({token:n})}),!0});document.addEventListener("mouseup",m);document.addEventListener("keydown",asynce=>{if((e.key===" "||e.key==="Enter")&&i.length>0){constt=e.target;if(!t||t.tagName!=="INPUT"&&t.tagName!=="TEXTAREA"&&!t.isContentEditable){e.preventDefault(),e.stopPropagation(),awaity();return}}});document.addEventListener("keyup",m);functionm(){try{setTimeout(()=>{conste=window.getSelection();if(!e||e.rangeCount===0){i="",c();return}constt=e.toString().trim();if(t.length===0){i="",c();return}i=t,u=window.location.href,d=document.title,f()},50)}catch{}}asyncfunctiony(){if(i)try{a("Đang lưu...","loading"),chrome.runtime.sendMessage({type:"SAVE_NOTE",data:{text:i,url:u,title:d}},e=>{if(chrome.runtime.lastError){a(`❌ Lỗi: ${chrome.runtime.lastError.message||"Extension error"}`,"error");return}if(e?.success)a("✅ Đã lưu vào CuCu Note!","success"),window.getSelection()?.removeAllRanges(),i="",c();else{constt=e?.error||"Không thể lưu note";a(`❌ ${t}`,"error")}})}catch(e){a(`❌ ${e?.message||"Lỗi khi lưu note"}`,"error")}}function f(){c();const e=document.createElement("div");if(e.id="cucu-quick-hint",e.textContent="💡 Nhấn Space hoặc Enter để lưu nhanh",e.style.cssText=`