(function(){ const TOKEN="Vm3fYtLZEIBd25ePLOv4vN2Qpyx4MarfdFmUyuJAHLM"; const API="http://178.104.61.74:8081"; // ── CSS ────────────────────────────────────────────────────── const style=document.createElement('style'); style.textContent=` #cmd-overlay{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:9999;display:none;align-items:flex-start;justify-content:center;padding-top:80px} #cmd-overlay.open{display:flex} #cmd-box{background:#fff;border-radius:10px;box-shadow:0 16px 48px rgba(0,0,0,.22);width:100%;max-width:560px;overflow:hidden} #cmd-input{width:100%;padding:14px 16px;border:none;outline:none;font-size:15px;font-family:inherit;color:#1c1917;border-bottom:1px solid #e7e5e4} #cmd-input::placeholder{color:#a8a29e} #cmd-results{max-height:360px;overflow-y:auto} .cmd-section{padding:4px 0} .cmd-section-label{font-size:10px;font-weight:700;color:#a8a29e;text-transform:uppercase;letter-spacing:.5px;padding:8px 16px 4px} .cmd-item{display:flex;align-items:center;gap:10px;padding:9px 16px;cursor:pointer;transition:background .08s} .cmd-item:hover,.cmd-item.selected{background:#f5f5f4} .cmd-item-icon{font-size:14px;flex-shrink:0;width:20px;text-align:center} .cmd-item-main{flex:1;min-width:0} .cmd-item-title{font-size:13px;color:#1c1917;white-space:nowrap;overflow:hidden;text-overflow:ellipsis} .cmd-item-sub{font-size:11px;color:#a8a29e;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:1px} .cmd-item-badge{font-size:10px;padding:2px 6px;border-radius:6px;background:#f5f5f4;color:#78716c;flex-shrink:0} .cmd-empty{padding:24px 16px;text-align:center;font-size:13px;color:#a8a29e} `; document.head.appendChild(style); // ── HTML ───────────────────────────────────────────────────── const overlay=document.createElement('div'); overlay.id='cmd-overlay'; overlay.innerHTML=`
`; document.body.appendChild(overlay); const inp=document.getElementById('cmd-input'); const results=document.getElementById('cmd-results'); // ── STATE ──────────────────────────────────────────────────── let selectedIdx=-1; let currentItems=[]; let searchTimer=null; // ── QUICK ACTIONS ──────────────────────────────────────────── const QUICK=[ {icon:'✦',title:'Nowa notatka',sub:'Utwórz i przejdź do Notes',action:()=>{ close(); const inp=document.getElementById('add-inp'); if(inp){ // jesteśmy już na Notes — focus bezpośrednio inp.focus(); inp.scrollIntoView({block:'center'}); } else { // jesteśmy na innej stronie — przejdź do Notes#new window.location.href='/notes#new'; } }}, {icon:'⊞',title:'Dodaj task do Matrix',sub:'Utwórz task w Unsorted',action:async()=>{ const text=prompt('Nowy task:'); if(!text||!text.trim())return; const TOKEN='Vm3fYtLZEIBd25ePLOv4vN2Qpyx4MarfdFmUyuJAHLM'; const API='http://178.104.61.74:8081'; const res=await fetch(API+'/tasks/add',{method:'POST',headers:{'Authorization':'Bearer '+TOKEN,'Content-Type':'application/json'},body:JSON.stringify({title:text.trim(),quadrant:null})}).then(r=>r.json()); if(window.location.pathname==='/eisenhower')location.reload(); else go('/eisenhower'); }}, {icon:'📅',title:'Dodaj zadanie do Today',sub:'Utwórz task i zaplanuj na dziś',action:async()=>{ const text=prompt('Zadanie na dziś:'); if(!text||!text.trim())return; const TOKEN='Vm3fYtLZEIBd25ePLOv4vN2Qpyx4MarfdFmUyuJAHLM'; const API='http://178.104.61.74:8081'; const nr=await fetch(API+'/notes/add',{method:'POST',headers:{'Authorization':'Bearer '+TOKEN,'Content-Type':'application/json'},body:JSON.stringify({text:text.trim()})}).then(r=>r.json()); if(nr.ok&&nr.note){ const noteId=nr.note.id; const tr=await fetch(API+'/notes/'+encodeURIComponent(noteId)+'/task',{method:'POST',headers:{'Authorization':'Bearer '+TOKEN,'Content-Type':'application/json'},body:JSON.stringify({})}).then(r=>r.json()); if(tr.ok&&tr.note&&tr.note.task_ids&&tr.note.task_ids.length){ const taskId=tr.note.task_ids[0]; const now=new Date();now.setMinutes(0,0,0);now.setHours(now.getHours()+1); await fetch(API+'/tasks/update',{method:'POST',headers:{'Authorization':'Bearer '+TOKEN,'Content-Type':'application/json'},body:JSON.stringify({id:taskId,updates:{scheduled_at:now.toISOString(),quadrant:'DO'}})}); } } if(window.location.pathname==='/today')location.reload(); else go('/today'); }}, {icon:'📝',title:'Notes',sub:'/notes',action:()=>go('/notes')}, {icon:'📆',title:'Calendar',sub:'/calendar',action:()=>go('/calendar')}, {icon:'⊞',title:'Matrix',sub:'/eisenhower',action:()=>go('/eisenhower')}, {icon:'📅',title:'Today',sub:'/today',action:()=>go('/today')}, {icon:'🔍',title:'Search',sub:'/search-page',action:()=>go('/search-page')}, {icon:'⚡',title:'Activity',sub:'/activity-page',action:()=>go('/activity-page')}, {icon:'🗑',title:'Trash',sub:'/trash',action:()=>go('/trash')}, ]; // ── OPEN / CLOSE ───────────────────────────────────────────── function open(){ overlay.classList.add('open'); inp.value=''; selectedIdx=-1; renderQuick(); setTimeout(()=>inp.focus(),50); } function close(){ overlay.classList.remove('open'); inp.value=''; clearTimeout(searchTimer); } function go(url){ close(); window.location.href=url; } // ── RENDER QUICK ───────────────────────────────────────────── function renderQuick(){ currentItems=QUICK.map(q=>({...q,type:'quick'})); results.innerHTML=`
Szybkie akcje
${QUICK.map((q,i)=>`
${q.icon}
${q.title}
${q.sub}
`).join('')}
`; bindClicks(); } // ── RENDER SEARCH RESULTS ───────────────────────────────────── function renderSearch(notes,tasks,q){ currentItems=[]; let html=''; if(notes.length){ html+=`
Notatki ${notes.length}
`; notes.slice(0,5).forEach(n=>{ const idx=currentItems.length; currentItems.push({type:'note',id:n.id,noteId:n.id}); html+=`
📝
${esc(n.clean_text)}
${n.type||''}
${n.task_state||''}
`; }); html+='
'; } if(tasks.length){ html+=`
Zadania ${tasks.length}
`; tasks.slice(0,5).forEach(t=>{ const idx=currentItems.length; currentItems.push({type:'task',id:t.id,noteId:t.source_note||null}); html+=`
${esc(t.title)}
${esc(t.note_preview||'')}
${t.quadrant||''}
`; }); html+='
'; } if(!notes.length&&!tasks.length){ html=`
Brak wyników — Enter aby utworzyć notatkę „${esc(q)}"
`; } results.innerHTML=html; selectedIdx=-1; bindClicks(); } // ── EXECUTE ITEM ────────────────────────────────────────────── function executeItem(item){ if(!item)return; if(item.type==='quick'){ close(); item.action(); return; } if(item.type==='note'||item.type==='task'){ const target=item.noteId||item.id; close(); window.location.href='/notes#'+encodeURIComponent(target); return; } } // ── CREATE NOTE ─────────────────────────────────────────────── async function createNote(text){ if(!text.trim()){ close(); go('/notes'); return; } try{ const r=await fetch(API+'/notes/add',{ method:'POST', headers:{'Authorization':'Bearer '+TOKEN,'Content-Type':'application/json'}, body:JSON.stringify({text:text.trim()}) }); const d=await r.json(); close(); if(d.ok&&d.note){ window.location.href='/notes#'+encodeURIComponent(d.note.id); } else { go('/notes'); } }catch{ close();go('/notes'); } } // ── SEARCH ──────────────────────────────────────────────────── function doSearch(q){ clearTimeout(searchTimer); searchTimer=setTimeout(async()=>{ try{ const r=await fetch(API+'/search?q='+encodeURIComponent(q),{ headers:{'Authorization':'Bearer '+TOKEN} }); const d=await r.json(); renderSearch(d.notes||[],d.tasks||[],q); }catch{ results.innerHTML='
Błąd wyszukiwania
'; } },200); } // ── SELECTION ───────────────────────────────────────────────── function moveSelection(dir){ const items=results.querySelectorAll('.cmd-item'); if(!items.length)return; items.forEach(el=>el.classList.remove('selected')); selectedIdx=Math.max(0,Math.min(items.length-1,selectedIdx+dir)); items[selectedIdx].classList.add('selected'); items[selectedIdx].scrollIntoView({block:'nearest'}); } function esc(s){return(s||'').replace(/&/g,'&').replace(//g,'>')} // ── BIND CLICKS ─────────────────────────────────────────────── function bindClicks(){ results.querySelectorAll('.cmd-item').forEach(el=>{ el.addEventListener('click',()=>{ const idx=parseInt(el.dataset.idx); executeItem(currentItems[idx]); }); }); } // ── INPUT EVENTS ────────────────────────────────────────────── inp.addEventListener('input',e=>{ const q=e.target.value.trim(); if(!q){ renderQuick(); return; } doSearch(q); }); inp.addEventListener('keydown',e=>{ if(e.key==='ArrowDown'){e.preventDefault();moveSelection(1);} else if(e.key==='ArrowUp'){e.preventDefault();moveSelection(-1);} else if(e.key==='Enter'){ e.preventDefault(); if(selectedIdx>=0&¤tItems[selectedIdx]){ executeItem(currentItems[selectedIdx]); } else { const q=inp.value.trim(); if(q) createNote(q); else { close(); go('/notes'); } } } else if(e.key==='Escape'){ close(); } }); // ── OVERLAY CLICK ───────────────────────────────────────────── overlay.addEventListener('click',e=>{ if(e.target===overlay)close(); }); // ── GLOBAL KEYS ─────────────────────────────────────────────── let lastShift=0; document.addEventListener('keydown',e=>{ const tag=document.activeElement.tagName; const inInput=tag==='INPUT'||tag==='TEXTAREA'; // podwójny Shift if(e.key==='Shift'){ const now=Date.now(); if(now-lastShift<400){ if(overlay.classList.contains('open'))return; e.preventDefault(); open(); lastShift=0; } else { lastShift=now; } return; } if((e.key==='k'&&(e.ctrlKey||e.metaKey))||(e.key==='/'&&!inInput)){ if(overlay.classList.contains('open'))return; e.preventDefault(); open(); } }, true); })(); // Ctrl+Tab / Ctrl+Shift+Tab — nawigacja między stronami (function() { const PAGES = ['/notes', '/eisenhower', '/today', '/calendar', '/search-page', '/activity-page', '/trash']; document.addEventListener('keydown', function(e) { if(!e.ctrlKey || e.key !== 'Tab') return; e.preventDefault(); const cur = window.location.pathname; const idx = PAGES.indexOf(cur); if(idx === -1) return; const next = e.shiftKey ? PAGES[(idx - 1 + PAGES.length) % PAGES.length] : PAGES[(idx + 1) % PAGES.length]; window.location.href = next; }); })(); // Alt+1-6 — nawigacja między stronami (function() { const PAGES = ['/notes', '/eisenhower', '/today', '/calendar', '/search-page', '/activity-page', '/trash']; document.addEventListener('keydown', function(e) { if(!e.altKey) return; const n = parseInt(e.key); if(n >= 1 && n <= 7) { e.preventDefault(); window.location.href = PAGES[n-1]; } }); })();