window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<120;i++){if(fn())return;await new Promise(r=>setTimeout(r,100));}throw Error('Timed out: '+fn.toString());};const fill=(n,value)=>{n.value=value;n.dispatchEvent(new Event('input',{bubbles:true}));};try{ const path=location.pathname; if(path==='/v/plan/task/-/new'){ const api='/_/api/v1/extension/organizer.tasks/',dialog=document.querySelector('#tasks-dialog'),form=document.querySelector('#tasks-form'); const input=name=>form.querySelector('[name="'+name+'"]'); await wait(()=>input('page_path'));if(input('notify_due').checked||input('notify_planned').checked)throw Error('Initial defaults not off'); document.querySelector('#tasks-close').click(); const prefs=await fetch(api+'preferences').then(r=>r.json());const saved=await fetch(api+'preferences',{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify({...prefs.preferences,notify_due:true,notify_planned:true,reminder_time:'10:35'})});if(!saved.ok)throw Error('Preferences save failed'); document.querySelector('#tasks-new').click();await wait(()=>input('page_path')); if(input('notify_due').checked||input('notify_planned').checked)throw Error('Undated task enabled reminders'); fill(input('title'),'タスク編集のレイアウト確認');fill(input('notes'),'主要項目を左右に整理。日付と通知をまとめて設定します。'); fill(input('planned_on'),'2030-01-01');fill(input('due_on'),'2030-01-02'); if(!input('notify_due').checked||!input('notify_planned').checked||input('reminder_time').value!=='10:35')throw Error('Dated defaults missing'); input('notify_due').click();fill(input('due_on'),'2030-01-03');if(input('notify_due').checked)throw Error('Explicit reminder choice overwritten'); for(const [key,value] of [['status','doing'],['bucket','backlog'],['complexity','4']]){const radio=form.querySelector('[name="'+key+'"][value="'+value+'"]');if(radio.type!=='radio')throw Error('Not a native radio group');radio.click();if(form.querySelectorAll('[name="'+key+'"]:checked').length!==1)throw Error('Multiple radio choices');} fill(input('estimate_minutes'),'90');form.requestSubmit();await wait(()=>!dialog.open); const items=await fetch(api+'items?q='+encodeURIComponent('レイアウト確認')).then(r=>r.json());const task=items.items[0]; if(task.status!=='doing'||task.bucket!=='backlog'||task.complexity!==4||!task.notify_planned||task.notify_due||task.reminder_time!=='10:35')throw Error('Editor fields not persisted'); await wait(()=>document.querySelector('[data-task-id="'+task.uuid+'"] [data-action=detail]'));document.querySelector('[data-task-id="'+task.uuid+'"] [data-action=detail]').click();await wait(()=>input('page_path')); if(input('notify_due').checked)throw Error('Defaults changed existing task'); if(form.querySelector('.task-editor-advanced').open)throw Error('Advanced section should start collapsed'); const fields=document.querySelector('#tasks-fields'),rect=dialog.getBoundingClientRect(); if(rect.width>innerWidth+1||rect.height>innerHeight+1||fields.scrollWidth>fields.clientWidth+1)throw Error('Editor overflow'); if(innerWidth>=1000){const left=form.querySelector('.task-editor-main').getBoundingClientRect(),right=form.querySelector('.task-editor-plan').getBoundingClientRect();if(right.left<=left.right||Math.abs(right.top-left.top)>2)throw Error('Editor is not two columns');if(fields.scrollHeight>fields.clientHeight+2)throw Error('Desktop editor needs scrolling: '+fields.scrollHeight+'/'+fields.clientHeight);} if(innerWidth<760&&form.querySelector('.task-editor-plan').getBoundingClientRect().topdocument.querySelector('#contacts-controls button'));document.querySelector('#contacts-controls button').click();fill(document.querySelector('[name=name]'),'ブラウザ連絡先');fill(document.querySelector('[name=emails]'),'browser@example.invalid');fill(document.querySelector('[name=notes]'),'Non-public notes');document.querySelector('#contact-editor form').requestSubmit();await wait(()=>document.querySelector('#contacts-list button')?.textContent.includes('ブラウザ'));const r=await fetch('/_/api/v1/extension/organizer.contacts/items?q=browser').then(r=>r.json());if(r.items.length!==1)throw Error('Contact save missing'); fill(document.querySelector('[name=name]'),'変更後');document.querySelector('#contact-editor form').requestSubmit();await wait(()=>document.querySelector('#contacts-list button')?.textContent.includes('変更後')); await wait(()=>document.querySelector('.contact-history'));document.querySelector('.contact-history').open=true;await wait(()=>document.querySelectorAll('.contact-history-row').length===2);document.querySelectorAll('.contact-history-row')[1].querySelector('button').click();await wait(()=>document.querySelector('.contact-history pre').textContent.includes('ブラウザ連絡先')); window.confirm=()=>true;document.querySelectorAll('.contact-history-row')[1].querySelectorAll('button')[1].click();await wait(()=>document.querySelector('#contacts-list button')?.textContent.includes('ブラウザ')); const exported=await fetch('/_/api/v1/extension/organizer.contacts/export.vcf').then(r=>r.text());if(!exported.includes('ブラウザ連絡先'))throw Error('Export missing'); document.querySelector('#tasks-dav-open').click();await wait(()=>document.querySelector('#tasks-dav-dialog').open);const dav=document.querySelector('#tasks-dav-dialog');if(getComputedStyle(dav.querySelector('.dav-compat-toggle')).display!=='none')throw Error('CalDAV-only compatibility visible');fill(dav.querySelector('form>input'),'Browser contact client');dav.querySelector('form').requestSubmit();await wait(()=>!dav.querySelector('section').hidden);const credentials=await fetch('/_/api/v1/caldav-credentials').then(r=>r.json());if(credentials.items.length!==1||credentials.items[0].scope!=='contacts')throw Error('Wrong credential scope');dav.querySelector('tbody button').click();await wait(()=>!dav.querySelector('tbody button'));dav.querySelector('header button').click(); }else if(path==='/-/sys/config'){ await wait(()=>document.querySelector('[name=due_days]'));fill(document.querySelector('[name=due_days]'),'2');document.querySelector('[name=notify_due]').click();document.querySelector('[name=notify_planned]').click();fill(document.querySelector('[name=reminder_time]'),'08:45');document.querySelector('.productivity-settings').requestSubmit();await wait(()=>document.querySelector('#productivity-status').textContent.includes('保存'));const d=await fetch('/_/api/v1/extension/organizer.tasks/preferences').then(r=>r.json());if(d.preferences.due_days!==2||!d.preferences.notify_due||!d.preferences.notify_planned||d.preferences.reminder_time!=='08:45'||!d.defaults.notify_due||d.defaults.notify_planned)throw Error('Preferences missing'); }else if(path==='/v/plan/dashboard'){ await wait(()=>document.querySelectorAll('.productivity-day').length>300);if(!document.querySelector('.productivity-day[data-level="2"]'))throw Error('Seven-point completion missing'); if(document.querySelectorAll('[data-widget]').length!==6)throw Error('Widget registry missing'); const tab=document.querySelector('[data-tab=done]');tab.click();await wait(()=>document.querySelector('#widget-panel-tasks').textContent.includes('Browser work task'));if(location.pathname!=='/v/plan/dashboard'||document.querySelector('#organizer-dashboard iframe'))throw Error('Tab navigation escaped widget'); document.querySelector('#dashboard-controls button[aria-pressed]').click();const width=document.querySelector('[data-widget=tasks] [data-size=width]');width.value='6';width.dispatchEvent(new Event('change'));const height=document.querySelector('[data-widget=tasks] [data-size=height]');height.value='5';height.dispatchEvent(new Event('change')); document.querySelector('[data-widget=tasks] .widget-arrange button').click();document.querySelector('#dashboard-controls button:last-child').click();await wait(()=>document.querySelector('#dashboard-status').textContent.includes('保存しました'));const layout=await fetch('/_/api/v1/extension/organizer.tasks/dashboard').then(r=>r.json());if(layout.widgets[2].id!=='tasks'||layout.widgets[2].width!==6||layout.widgets[2].height!==5||layout.widgets[2].tab!=='done')throw Error('Layout did not persist'); if(!document.querySelector('.organizer-nav a[href="/v/plan/contacts"]')||!document.querySelector('.organizer-nav a[aria-current="page"]'))throw Error('Shared navigation missing'); }else if(path==='/v/plan/tasks'){ const prefs=await fetch('/_/api/v1/extension/organizer.tasks/preferences').then(r=>r.json());await fetch('/_/api/v1/extension/organizer.tasks/preferences',{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify({...prefs.preferences,due_days:2,estimate_minutes:60})}); await wait(()=>document.querySelector('#tasks-quick-title'));fill(document.querySelector('#tasks-quick-title'),'Recording task');document.querySelector('#tasks-capture').requestSubmit();await wait(()=>document.querySelector('[data-action=work]'));document.querySelector('[data-action=work]').click();await wait(()=>document.querySelector('.task-work-bar a').textContent.includes('Recording task'));document.querySelector('.task-work-bar button').click();await wait(()=>document.querySelector('.task-work-bar').hidden); document.querySelector('[data-action=add-child]').click();const child=document.querySelector('.task-child-capture');fill(child.querySelector('input'),'Defaulted child');child.requestSubmit();await wait(()=>document.querySelectorAll('.task-inline-row').length===2);const children=await fetch('/_/api/v1/extension/organizer.tasks/items?q=Defaulted').then(r=>r.json());if(children.items[0].estimate_minutes!==60||!children.items[0].due_on)throw Error('Subtask defaults missing'); }else{ const input=document.querySelector('[data-home-type-search]');fill(input,'add task 検証 cost:2h complexity:3');input.closest('form').requestSubmit();await wait(()=>document.querySelector('.home-command-panel button'));document.querySelector('.home-command-panel button').click();await wait(()=>document.querySelector('.home-command-panel a'));const d=await fetch('/_/api/v1/extension/organizer.tasks/items?q='+encodeURIComponent('検証')).then(r=>r.json());if(d.items[0].estimate_minutes!==120)throw Error('Command cost missing');fill(input,'add cal 会議 from:2026-11-02T09:00 to:2026-11-02T10:00');input.closest('form').requestSubmit();await wait(()=>document.querySelector('.home-command-panel button'));document.querySelector('.home-command-panel button').click();await wait(()=>document.querySelector('.home-command-panel a')?.href.includes('/event/')); } if(document.documentElement.scrollWidth>innerWidth+2)throw Error('Page horizontal overflow: '+[...document.querySelectorAll('body *')].filter(n=>{const r=n.getBoundingClientRect();return r.width&&r.right>innerWidth+2;}).slice(0,15).map(n=>n.tagName+'.'+n.className+':'+Math.round(n.getBoundingClientRect().right)).join(', '));document.body.dataset.vimReady='true'; }catch(e){const n=document.createElement('pre');n.id='error';n.textContent=(e.stack||String(e))+'\n'+(document.querySelector('.home-command-panel')?.textContent||'');document.body.append(n);}});