(function(){letc="",u="",d="";asyncfunctionm(){for(leto=0;o<3;o++){try{constn=document.cookie.match(/(?:^|; )memos\.access-token=([^;]+)/);if(n&&n[1])returnn[1];for(letr=0;r<localStorage.length;r++){consta=localStorage.key(r);if(a&&(a.includes("access_token")||a.includes("token"))){consts=localStorage.getItem(a);if(s&&typeofs=="string"&&s.length>20&&!s.startsWith("{"))returns}}}catch{}o<2&&awaitnewPromise(n=>setTimeout(n,500))}returnnull}asyncfunctionp(){conste=window.location.hostname;if(!(e==="172.16.2.210"||e==="localhost"||e.includes("canifa")||e.includes("cucunote")||e.includes("cucu-note")))return;consto=awaitm();o&&chrome.runtime.sendMessage({type:"SYNC_AUTH",data:{memosAccessToken:o}})}p();chrome.runtime.onMessage.addListener((e,t,o)=>{if(e.type==="GET_TOKEN")returnm().then(n=>{o({token:n})}),!0});document.addEventListener("mouseup",h);document.addEventListener("keydown",asynce=>{if((e.key===" "||e.key==="Enter")&&c.length>0){constt=e.target;if(!t||t.tagName!=="INPUT"&&t.tagName!=="TEXTAREA"&&!t.isContentEditable){e.preventDefault(),e.stopPropagation(),awaity();return}}});document.addEventListener("keyup",h);functionh(){try{setTimeout(()=>{conste=window.getSelection();if(!e||e.rangeCount===0){c="",l();return}constt=e.toString().trim();if(t.length===0){c="",l();return}c=t,u=window.location.href,d=document.title,f()},50)}catch{}}asyncfunctiony(){if(c)try{i("Đang lưu...","loading"),chrome.runtime.sendMessage({type:"SAVE_NOTE",data:{text:c,url:u,title:d}},e=>{if(chrome.runtime.lastError){i(`Lỗi: ${chrome.runtime.lastError.message||"Extension error"}`,"error");return}if(e?.success)i("Đã lưu vào Canifa Note","success"),window.getSelection()?.removeAllRanges(),c="",l();else{constt=e?.error||"Không thể lưu";i(t,"error")}})}catch(e){i(e?.message||"Lỗi khi lưu","error")}}functionf(){l();conste=document.createElement("div");if(e.id="cucu-quick-hint",e.textContent="Space hoặc Enter để lưu nhanh",e.style.cssText=`
(function(){leti="",l="",d="";asyncfunctionm(){for(leto=0;o<3;o++){try{constn=document.cookie.match(/(?:^|; )memos\.access-token=([^;]+)/);if(n&&n[1])returnn[1];for(leta=0;a<localStorage.length;a++){consts=localStorage.key(a);if(s&&(s.includes("access_token")||s.includes("token"))){constc=localStorage.getItem(s);if(c&&typeofc=="string"&&c.length>20&&!c.startsWith("{"))returnc}}}catch{}o<2&&awaitnewPromise(n=>setTimeout(n,500))}returnnull}asyncfunctionf(){constt=window.location.hostname;if(!(t==="172.16.2.210"||t==="localhost"||t.includes("canifa")||t.includes("cucunote")||t.includes("cucu-note")))return;consto=awaitm();if(o){if(!chrome.runtime?.id)return;try{chrome.runtime.sendMessage({type:"SYNC_AUTH",data:{memosAccessToken:o}},()=>{chrome.runtime.lastError})}catch{}}}f();chrome.runtime.onMessage.addListener((t,e,o)=>{if(t.type==="GET_TOKEN")returnm().then(n=>{o({token:n})}),!0});document.addEventListener("mouseup",h);document.addEventListener("keydown",asynct=>{if((t.key===" "||t.key==="Enter")&&i.length>0){conste=t.target;if(!e||e.tagName!=="INPUT"&&e.tagName!=="TEXTAREA"&&!e.isContentEditable){t.preventDefault(),t.stopPropagation(),awaitp();return}}});document.addEventListener("keyup",h);functionh(){try{setTimeout(()=>{constt=window.getSelection();if(!t||t.rangeCount===0){i="",u();return}conste=t.toString().trim();if(e.length===0){i="",u();return}i=e,l=window.location.href,d=document.title,y()},50)}catch{}}asyncfunctionp(){if(i)try{if(r("Đang lưu...","loading"),!chrome.runtime?.id){r("Extension vừa cập nhật. Vui lòng tải lại trang (F5) để lưu note!","error");return}chrome.runtime.sendMessage({type:"SAVE_NOTE",data:{text:i,url:l,title:d}},t=>{if(chrome.runtime.lastError){r("Đang kết nối lại Extension, vui lòng thử lại...","error");return}if(t?.success)r("Đã lưu vào Canifa Note","success"),window.getSelection()?.removeAllRanges(),i="",u();else{conste=t?.error||"Không thể lưu";r(e,"error")}})}catch(t){r(t?.message||"Lỗi khi lưu","error")}}functiony(){u();constt=document.createElement("div");if(t.id="cucu-quick-hint",t.textContent="Space hoặc Enter để lưu nhanh",t.style.cssText=`