feat: add browser upload queue and trusted sessions with bounded projections
This commit is contained in:
1 parent
84d52390f9
commit
b90aef79d0
79 files changed
+1962
-196
No files matched your search
+54
-16
@@ -28,12 +28,14 @@
|
||||
const transfer=button('⇄','OPML',opmlForm);transfer.id='feed-opml';toolbar.append(transfer);
|
||||
const history=button('◷',t('Operation history','操作履歴'),actionHistory);history.id='feed-history';toolbar.append(history);
|
||||
const helpButton=button('?',t('Keyboard shortcuts','キー操作'),showHelp),help=el('div',undefined,'feed-help');help.id='feed-help';help.hidden=true;helpButton.setAttribute('aria-controls',help.id);helpButton.setAttribute('aria-expanded','false');
|
||||
help.append(el('span',t('j/k articles · Shift+j/k folders · Enter read · Esc index · / search · n unread · m read/unread · * star · r refresh · ? / Esc close help','j/k 記事移動 · Shift+j/k フォルダ移動 · Enter 本文 · Esc 一覧 · / 検索 · n 次の未読 · m 既読/未読 · * star · r 更新 · ? / Esc ヘルプを閉じる')),button('×',t('Close help','ヘルプを閉じる'),hideHelp));status.before(help);toolbar.append(helpButton);
|
||||
help.append(el('span',t('j/k articles · Shift+j/k folders / subscriptions · Shift+h parent · Shift+l enter · Enter read · Esc index · / search · n unread · m read/unread · * star · r refresh · ? / Esc close help','j/k 記事移動 · Shift+j/k フォルダ・購読元移動 · Shift+h 親へ · Shift+l 配下へ · Enter 本文 · Esc 一覧 · / 検索 · n 次の未読 · m 既読/未読 · * star · r 更新 · ? / Esc ヘルプを閉じる')),button('×',t('Close help','ヘルプを閉じる'),hideHelp));status.before(help);toolbar.append(helpButton);
|
||||
let debounce;searchbox.addEventListener('input',()=>{clearTimeout(debounce);debounce=setTimeout(()=>{search=searchbox.value.trim();load(false).catch(report);},180);});
|
||||
const columns=document.getElementById('feed-columns');for(const s of ['',t('Date','日付'),t('Feed','配信元'),t('Subject','件名')])columns.append(el('span',s));
|
||||
const columns=document.getElementById('feed-columns');for(const s of ['',t('Date','日付'),t('Time','時刻'),t('Feed','配信元'),t('Subject','件名')])columns.append(el('span',s));
|
||||
function hideHelp(){if(help.contains(document.activeElement))helpButton.focus();help.hidden=true;helpButton.setAttribute('aria-expanded','false');}
|
||||
function showHelp(){if(!help.hidden){hideHelp();return;}help.hidden=false;helpButton.setAttribute('aria-expanded','true');}
|
||||
function date(ms){return ms?new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{month:'2-digit',day:'2-digit'}).format(new Date(ms)):'—';}
|
||||
const dateOptions={timeZone:root.dataset.timezone||undefined},dateFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{...dateOptions,month:'2-digit',day:'2-digit'}),timeFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{...dateOptions,hour:'2-digit',minute:'2-digit',hourCycle:'h23'}),fullDateFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{...dateOptions,year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit',hourCycle:'h23',timeZoneName:'short'});
|
||||
function validDate(ms){return typeof ms==='number'&&ms>0&&Number.isFinite(new Date(ms).getTime());}
|
||||
function date(ms){return validDate(ms)?dateFormat.format(new Date(ms)):'—';}
|
||||
function closeReader(){editing=false;detailSeq++;detailController?.abort();layout.classList.remove('reading','action-history');rows.focus();}
|
||||
function drawSources(){sourcesView.replaceChildren();const all=button(t('All sources','すべての購読元'),'',()=>chooseSource(''));sourcesView.append(all);let folder=null;
|
||||
for(const source of sources){if(folder!==source.folder){folder=source.folder;sourcesView.append(el('h3',folder||t('Sources','購読元')));}const row=el('div',undefined,'feed-source');row.setAttribute('aria-current',String(currentSource===source.uuid));
|
||||
@@ -54,16 +56,36 @@
|
||||
remoteCategory=id;categoryMode=mode;remoteFeed=feed;markCatalog();layout.classList.remove('sources-open','reading','action-history');
|
||||
detailSeq++;detailController?.abort();clearTimeout(actionTimer);selected=-1;editing=false;reader.replaceChildren();await load(false);
|
||||
}
|
||||
const sortedSubscriptions=subs=>[...subs].sort((a,b)=>a.title.localeCompare(b.title)||a.id.localeCompare(b.id));
|
||||
function moveFolder(delta){
|
||||
if(!catalogLoaded||sources.find(s=>s.uuid===currentSource)?.provider!=='freshrss')return;
|
||||
const groups=catalogGroups();if(!groups.length)return;
|
||||
const current=groups.findIndex(g=>g.id===remoteCategory&&g.mode===categoryMode);
|
||||
if(remoteFeed){const g=groups[current],subs=sortedSubscriptions(g?g.subs:catalog),index=subs.findIndex(s=>s.id===remoteFeed)+delta;if(index<0||index>=subs.length)return;return navigateCatalog(g?.id||'',g?.mode||'',subs[index].id);}
|
||||
const index=current<0?(delta>0?0:groups.length-1):current+delta;if(index<0||index>=groups.length)return;
|
||||
// Folder search must not leave the newly selected folder invisible.
|
||||
if(catalogSearch){catalogSearch='';drawSources();}
|
||||
const group=groups[index],result=chooseCatalog(group.id,group.mode);
|
||||
const selectedFolder=sourcesView.querySelector('.feed-folder-name[aria-current="true"]');
|
||||
selectedFolder?.scrollIntoView({block:'nearest'});rows.focus({preventScroll:true});return result;
|
||||
const group=groups[index];return navigateCatalog(group.id,group.mode);
|
||||
}
|
||||
function navigateCatalog(id,mode,feed=''){
|
||||
// Clear only the tree filter, never article search or unread/star filters.
|
||||
catalogSearch='';
|
||||
const result=chooseCatalog(id,mode,feed);drawSources();
|
||||
sourcesView.querySelector('.feed-catalog button[aria-current="true"]')?.scrollIntoView({block:'nearest'});rows.focus({preventScroll:true});return result;
|
||||
}
|
||||
function enterFolder(enter){
|
||||
if(!catalogLoaded||sources.find(s=>s.uuid===currentSource)?.provider!=='freshrss')return;
|
||||
const groups=catalogGroups(),group=groups.find(g=>g.id===remoteCategory&&g.mode===categoryMode),state=folderState(currentSource);
|
||||
if(enter){
|
||||
if(remoteFeed)return;
|
||||
if(!group){if(groups.length)return navigateCatalog(groups[0].id,groups[0].mode);return;}
|
||||
state.add(JSON.stringify([group.mode,group.id]));
|
||||
}else{
|
||||
if(remoteFeed)return navigateCatalog(group?.id||'',group?.mode||'');
|
||||
if(!group)return;
|
||||
state.delete(JSON.stringify([group.mode,group.id]));
|
||||
}
|
||||
try{localStorage.setItem('pageswiki.feed-folders.v1:'+currentSource,JSON.stringify([...state]));}catch{}
|
||||
if(!enter)return navigateCatalog('','');
|
||||
const sub=sortedSubscriptions(group.subs)[0];return navigateCatalog(group.id,group.mode,sub?.id||'');
|
||||
}
|
||||
function drawCatalog(parent){
|
||||
if(!catalogLoaded)return;
|
||||
@@ -74,8 +96,8 @@
|
||||
const all=select(t('All subscriptions','すべての購読'),{id:'',mode:''});all.className='feed-tree-all';nav.append(all);
|
||||
const find=el('input');find.type='search';find.placeholder=find.ariaLabel=t('Find subscription / folder','購読・フォルダを検索');find.value=catalogSearch;nav.append(find);
|
||||
const list=el('div',undefined,'feed-folders');nav.append(list);parent.append(nav);
|
||||
function subscriptions(target,subs,g){let count=0;const sorted=[...subs].sort((a,b)=>a.title.localeCompare(b.title)||a.id.localeCompare(b.id));const more=button('↓',t('More subscriptions','購読元をさらに表示'),append);
|
||||
function append(){more.remove();for(const sub of sorted.slice(count,count+50)){const group=g||{id:'',mode:''},b=select(sub.title||sub.id,group,sub.id);b.title=(sub.title||sub.id)+(sub.categories.length?' · '+sub.categories.map(c=>c.label).join(' / '):'');target.append(b);}count+=50;if(count<sorted.length)target.append(more);}append();
|
||||
function subscriptions(target,subs,g){const sorted=sortedSubscriptions(subs);let count=0;const more=button('↓',t('More subscriptions','購読元をさらに表示'),append);
|
||||
function append(){more.remove();const end=Math.max(count+50,sorted.findIndex(s=>s.id===remoteFeed)+1);for(const sub of sorted.slice(count,end)){const group=g||{id:'',mode:''},b=select(sub.title||sub.id,group,sub.id);b.title=(sub.title||sub.id)+(sub.categories.length?' · '+sub.categories.map(c=>c.label).join(' / '):'');target.append(b);}count=end;if(count<sorted.length)target.append(more);}append();
|
||||
}
|
||||
const draw=()=>{list.replaceChildren();const query=find.value.trim().toLocaleLowerCase();catalogSearch=find.value;
|
||||
if(query){const matches=catalog.filter(s=>s.title.toLocaleLowerCase().includes(query)||s.categories.some(c=>c.label.toLocaleLowerCase().includes(query)));const results=el('div',undefined,'feed-subscriptions');list.append(results);subscriptions(results,matches,null);if(!matches.length)results.append(el('small',t('No subscriptions','購読なし')));return;}
|
||||
@@ -92,7 +114,15 @@
|
||||
const data=await request('catalog?'+new URLSearchParams({source:currentSource}),{signal:catalogController.signal});if(version!==catalogSeq)return;catalog=data.subscriptions;catalogFolders=data.folders||[];catalogLoaded=true;drawSources();
|
||||
}
|
||||
async function chooseSource(id){currentSource=id;remoteFeed=remoteCategory=categoryMode=catalogSearch='';catalog=[];catalogFolders=[];catalogLoaded=false;drawSources();layout.classList.remove('reading');editing=false;await Promise.all([loadCatalog(),load(false)]);if(sources.find(s=>s.uuid===id)?.provider!=='freshrss')layout.classList.remove('sources-open');}
|
||||
function rowNode(item,index){const row=el('div',undefined,'feed-row'+(item.read?'':' unread'));row.id='feed-row-'+index;row.setAttribute('role','option');row.setAttribute('aria-selected',String(index===selected));for(const text of [(item.starred?'★':item.read?' ':'●'),date(item.published_ms),item.feed||sources.find(s=>s.uuid===item.source)?.title||'',item.title||t('(Untitled)','(無題)')])row.append(el('span',text));row.title=item.title;row.onclick=()=>open(index).catch(report);return row;}
|
||||
function rowNode(item,index){
|
||||
const row=el('div',undefined,'feed-row'+(item.read?'':' unread'));
|
||||
row.id='feed-row-'+index;row.setAttribute('role','option');row.setAttribute('aria-selected',String(index===selected));
|
||||
const known=validDate(item.published_ms),published=el('span',known?timeFormat.format(new Date(item.published_ms)):'—','feed-published-time');
|
||||
published.title=published.ariaLabel=t('Published: ','配信日時: ')+(known?fullDateFormat.format(new Date(item.published_ms)):t('Unknown','不明'));
|
||||
row.append(el('span',item.starred?'★':item.read?' ':'●'),el('span',date(item.published_ms)),published,
|
||||
el('span',item.feed||sources.find(s=>s.uuid===item.source)?.title||''),el('span',item.title||t('(Untitled)','(無題)')));
|
||||
row.title=item.title;row.onclick=()=>open(index).catch(report);return row;
|
||||
}
|
||||
function drawRows(){rows.replaceChildren(...items.map(rowNode));more.hidden=!next;more.textContent='↓';more.title=more.ariaLabel=t('More articles','続きを表示');if(!items.length)rows.append(el('p',t('No articles','記事なし'),'feed-warning'));}
|
||||
async function load(append){if(append&&(!next||loading))return;controller?.abort();controller=new AbortController();const version=++seq;loading=true;more.disabled=true;
|
||||
try{const q=new URLSearchParams({source:currentSource,filter,q:search,feed:remoteFeed,category:remoteCategory,category_mode:categoryMode});if(append){q.set('before',next.ms);q.set('key',next.key);}const data=await request('items?'+q,{signal:controller.signal});if(version!==seq)return;
|
||||
@@ -115,13 +145,21 @@
|
||||
const gecko=root.dataset.linkMode==='gecko', controller=new AbortController();
|
||||
const close=button('×',t('Close preview','プレビューを閉じる'),()=>dialog.close());bar.append(name,external,close);frame.title=dialog.ariaLabel;frame.referrerPolicy='no-referrer';
|
||||
if(gecko){
|
||||
const licenses=el('a','ⓘ');licenses.href=api+'browser/distribution/v0.0.1/index.html';licenses.target='_blank';licenses.rel='noopener noreferrer';licenses.title=licenses.ariaLabel=t('Engine sources and licenses','エンジンのソースとライセンス');bar.insertBefore(licenses,close);
|
||||
frame.src=api+'browser/';frame.allow='cross-origin-isolated';
|
||||
const send=command=>frame.contentWindow?.postMessage({type:'pageswiki-gecko',command},location.origin);
|
||||
const send=(command,options={})=>frame.contentWindow?.postMessage({type:'pageswiki-gecko',command,...options},location.origin);
|
||||
const findbar=el('form',undefined,'feed-gecko-find'),query=el('input'),findStatus=el('output');findbar.hidden=true;query.type='search';query.maxLength=256;query.placeholder=query.ariaLabel=t('Find in article','記事内を検索');findStatus.role='status';
|
||||
const findButton=button('⌕',t('Find in article (Ctrl+F)','記事内検索 (Ctrl+F)'),()=>{findbar.hidden=!findbar.hidden;if(!findbar.hidden)query.focus();});findButton.disabled=true;bar.insertBefore(findButton,name);
|
||||
const search=backwards=>{if(query.value.trim())send('find',{query:query.value,backwards});};
|
||||
findbar.append(query,button('↑',t('Previous match','前の一致'),()=>search(true)),button('↓',t('Next match','次の一致'),()=>search(false)),findStatus,button('×',t('Close search','検索を閉じる'),()=>{findbar.hidden=true;findButton.focus();}));
|
||||
findbar.onsubmit=e=>{e.preventDefault();search(false);};query.oninput=()=>findStatus.textContent='';query.addEventListener('keydown',e=>{if(e.key==='Escape'){e.preventDefault();findbar.hidden=true;findButton.focus();}else if(e.key==='Enter'&&e.shiftKey){e.preventDefault();search(true);}});
|
||||
dialog.addEventListener('keydown',e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='f'&&!findButton.disabled){e.preventDefault();findbar.hidden=false;query.focus();}});
|
||||
dialog.append(findbar);
|
||||
const nav={};for(const [icon,label,command]of [['←',t('Back','戻る'),'back'],['→',t('Forward','進む'),'forward'],['⟳',t('Reload','再読込'),'reload']]){const b=button(icon,label,()=>send(command));b.disabled=true;nav[command]=b;bar.insertBefore(b,name);}
|
||||
addEventListener('message',e=>{if(e.origin!==location.origin||e.source!==frame.contentWindow||e.data?.type!=='pageswiki-gecko')return;if(e.data.listening)frame.contentWindow.postMessage({type:'pageswiki-gecko',href:url.href},location.origin);if(e.data.close)dialog.close();if(e.data.ready)nav.reload.disabled=false;if(typeof e.data.back==='boolean')nav.back.disabled=!e.data.back;if(typeof e.data.forward==='boolean')nav.forward.disabled=!e.data.forward;if(e.data.href){try{const u=new URL(e.data.href);if(['http:','https:'].includes(u.protocol)&&!u.username&&!u.password){name.textContent=u.hostname;name.title=external.href=u.href;}}catch{}}},{signal:controller.signal});
|
||||
addEventListener('message',e=>{if(e.origin!==location.origin||e.source!==frame.contentWindow||e.data?.type!=='pageswiki-gecko')return;if(e.data.listening)frame.contentWindow.postMessage({type:'pageswiki-gecko',href:url.href},location.origin);if(e.data.close)dialog.close();if(e.data.ready)nav.reload.disabled=findButton.disabled=false;if(e.data.find&&!findButton.disabled){findbar.hidden=false;query.focus();}if(typeof e.data.findResult==='boolean'&&e.data.query===query.value)findStatus.textContent=e.data.findResult?'':t('No match','一致なし');if(e.data.findError)findStatus.textContent=t('Search unavailable','検索できません');if(e.data.failed){for(const b of Object.values(nav))b.disabled=true;findButton.disabled=true;findbar.hidden=true;const error=el('p',t('Viewer unavailable. Close and retry, or open the original with ↗.','ビューアを開始できません。閉じて再試行するか、↗から原文を開いてください。'),'feed-warning');error.role='alert';frame.src='about:blank';frame.replaceWith(error);return;}if(typeof e.data.back==='boolean')nav.back.disabled=!e.data.back;if(typeof e.data.forward==='boolean')nav.forward.disabled=!e.data.forward;if(e.data.href){try{const u=new URL(e.data.href);if(['http:','https:'].includes(u.protocol)&&!u.username&&!u.password){name.textContent=u.hostname;name.title=external.href=u.href;}}catch{}}},{signal:controller.signal});
|
||||
let hiddenTimer;document.addEventListener('visibilitychange',()=>{clearTimeout(hiddenTimer);if(document.hidden)hiddenTimer=setTimeout(()=>dialog.close(),60000);},{signal:controller.signal});dialog.addEventListener('close',()=>clearTimeout(hiddenTimer),{once:true});
|
||||
}else{frame.setAttribute('sandbox','allow-scripts');frame.src=url.href;}
|
||||
dialog.append(bar,frame);root.append(dialog);
|
||||
dialog.prepend(bar);dialog.append(frame);root.append(dialog);
|
||||
dialog.addEventListener('keydown',e=>e.stopPropagation());dialog.addEventListener('close',()=>{controller.abort();frame.src='about:blank';dialog.remove();editing=wasEditing;const item=items[selected];if(item&&!editing)pollAction(item);});dialog.showModal();close.focus();
|
||||
}
|
||||
function renderItem(item){reader.replaceChildren();const actions=el('div',undefined,'feed-actions');actions.append(button('←',t('Back to list','一覧へ戻る'),closeReader));
|
||||
@@ -133,7 +171,7 @@
|
||||
const original=actions.querySelector('.feed-original');if(original)original.addEventListener('click',e=>openArticleLink(e,original.href));
|
||||
if(item.url&&root.dataset.shareX==='true'){const share=el('a',undefined,'feed-share-x feed-original');share.title=share.ariaLabel=t('Share original article on X','原文の記事をXでシェア');share.href='https://twitter.com/intent/tweet?'+new URLSearchParams({text:item.title||'',url:item.url});share.target='_blank';share.rel='noopener noreferrer';const svg=document.createElementNS('http://www.w3.org/2000/svg','svg'),path=document.createElementNS(svg.namespaceURI,'path');svg.setAttribute('viewBox','0 0 24 24');svg.setAttribute('aria-hidden','true');path.setAttribute('d','M18 3h3l-7 8 8 10h-6l-5-7-6 7H2l7-9L2 3h6l5 6z');svg.append(path);share.append(svg);actions.append(share);}
|
||||
if(writable)actions.append(button(t('+ Wiki / Task','+ Wiki・タスク'),t('Capture with attribution','出典付きで取り込む'),()=>captureForm(item)));
|
||||
reader.append(actions,el('h1',item.title||t('(Untitled)','(無題)')),el('p',(item.feed||'')+' · '+(item.published_ms?new Date(item.published_ms).toLocaleString():t('Date unknown','日付不明')),'feed-meta'));
|
||||
reader.append(actions,el('h1',item.title||t('(Untitled)','(無題)')),el('p',(item.feed||'')+' · '+(validDate(item.published_ms)?fullDateFormat.format(new Date(item.published_ms)):t('Date unknown','日付不明')),'feed-meta'));
|
||||
if(item.provider==='freshrss'&&!canWrite)read.title=star.title=t('FreshRSS · read only','FreshRSS · 読取専用');
|
||||
const body=el('div',undefined,'feed-body');
|
||||
if(item.body_html){body.classList.add('feed-body-html');const shadow=body.attachShadow({mode:'open'}),style=el('style',':host{display:block;overflow-wrap:anywhere;line-height:1.6}p{margin:.6em 0}h1,h2,h3{line-height:1.3}a{color:var(--link,var(--accent,#659de4))}pre{white-space:pre-wrap;overflow-wrap:anywhere;padding:.5em;background:color-mix(in srgb,currentColor 5%,transparent)}blockquote{margin:.5em 0;padding-left:1em;border-left:3px solid var(--border,#8885)}table{border-collapse:collapse;max-width:100%;display:block;overflow:auto}th,td{padding:.3em .6em;border:1px solid var(--border,#8885)}');const content=el('div');content.innerHTML=item.body_html;shadow.append(style,content);}
|
||||
@@ -240,7 +278,7 @@
|
||||
};
|
||||
}
|
||||
document.addEventListener('keydown',event=>{if(event.defaultPrevented||event.isComposing||event.ctrlKey||event.altKey||event.metaKey||document.querySelector('dialog[open]'))return;if(event.key==='Escape'&&!help.hidden){hideHelp();event.preventDefault();return;}const input=event.target.closest?.('input,textarea,select,[contenteditable]:not([contenteditable=false]),[role=textbox]');if(input||event.target.isContentEditable){if(event.key==='Escape'){event.target.blur();event.preventDefault();}return;}if(event.key==='?'&&!help.hidden){hideHelp();event.preventDefault();return;}if(event.key==='Enter'&&event.target.closest?.('button,a'))return;if(editing){if(event.key==='Escape'){closeReader();event.preventDefault();}return;}
|
||||
if(event.shiftKey&&['j','k'].includes(event.key.toLowerCase())){event.preventDefault();Promise.resolve().then(()=>moveFolder(event.key.toLowerCase()==='j'?1:-1)).catch(report);return;}
|
||||
if(event.shiftKey&&['h','j','k','l'].includes(event.key.toLowerCase())){event.preventDefault();const key=event.key.toLowerCase();Promise.resolve().then(()=>key==='h'||key==='l'?enterFolder(key==='l'):moveFolder(key==='j'?1:-1)).catch(report);return;}
|
||||
let action;switch(event.key){case 'j':case 'ArrowDown':action=()=>open(Math.min(items.length-1,selected+1));break;case 'k':case 'ArrowUp':action=()=>open(Math.max(0,selected-1));break;case 'Enter':case 'l':action=()=>open(Math.max(0,selected));break;case 'Escape':case 'h':action=closeReader;break;case '/':action=()=>searchbox.focus();break;case 'r':if(writable)action=queueRefresh;break;case 'm':action=()=>setState(!items[selected]?.read,!!items[selected]?.starred);break;case '*':action=()=>setState(!!items[selected]?.read,!items[selected]?.starred);break;case 'n':action=()=>{const i=items.findIndex((x,i)=>i>selected&&!x.read);if(i>=0)return open(i);};break;case '?':action=showHelp;break;}if(action){event.preventDefault();Promise.resolve().then(action).catch(report);}
|
||||
});
|
||||
(async()=>{const q=new URLSearchParams(location.search);currentSource=q.get('source')||'';await reload();if(q.has('settings')&&writable){sourceForm();return;}if(q.has('id')&¤tSource){let index=items.findIndex(x=>x.source===currentSource&&x.id===q.get('id'));if(index<0){const data=await request('item?'+new URLSearchParams({source:currentSource,id:q.get('id')}));items.unshift(data.item);index=0;drawRows();}await open(index);}})().catch(report);
|
||||
|
||||
Reference in new issue
Block a user