fix(feeds): open X sharing in a single isolated popup

This commit is contained in:
Anya Tokugawa committed 2026-11-30 23:14:06 +09:00
1 parent 37c1443219
commit fdf6dffc84
4 files changed
+29 -2

No files matched your search

+7 -1
View File
@@ -6,6 +6,12 @@
const toolbar=document.getElementById('feed-toolbar'),status=document.getElementById('feed-status'),sourcesView=document.getElementById('feed-sources'),rows=document.getElementById('feed-rows'),reader=document.getElementById('feed-reader'),layout=root.querySelector('.feed-layout'),more=document.getElementById('feed-more');
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
const report=e=>{if(e.name!=='AbortError')status.textContent=e.message;};
function sharePopup(event){
if(event.defaultPrevented||event.button!==0||event.ctrlKey||event.metaKey||event.shiftKey||event.altKey)return;
event.preventDefault();event.stopPropagation();
// noopener can return null on success. Never retry by opening another tab.
window.open(event.currentTarget.href,'_blank','popup=yes,width=640,height=720,resizable=yes,scrollbars=yes,noopener,noreferrer');
}
function button(text,label,fn){const b=el('button',text);b.type='button';b.title=b.ariaLabel=label;b.addEventListener('click',()=>Promise.resolve().then(fn).catch(report));return b;}
async function request(path,options={}){const response=await fetch(api+path,{credentials:'same-origin',cache:'no-store',...options,headers:{'Content-Type':'application/json',...options.headers}});if(response.redirected||response.status===401)throw Error(t('Please sign in again.','再度ログインしてください。'));const data=await response.json().catch(()=>({}));if(!response.ok)throw Error(response.status===412?t('Changed elsewhere or refresh is cooling down. Reload before retrying.','別の操作と競合したか、更新の待機時間中です。再読込して確認してください。'):t('Request failed: ','操作に失敗しました: ')+(data.error||response.status));return data;}
const post=(path,body)=>request(path,{method:'POST',body:JSON.stringify(body)});
@@ -169,7 +175,7 @@
const state=button(a.status==='unknown'?'↻':pendingAction(a)?'◷':a.status==='confirmed'?'✓':'!',label,async()=>{if(a.status!=='unknown')return;await post('action/check',{request_id:a.request_id});await updateAction(item);});state.className='feed-action-status';state.disabled=a.status!=='unknown'||!writable;state.title+=(a.error?' · '+a.error:'');actions.append(state);}
if(item.url){const a=el('a',undefined,'feed-original');a.title=a.ariaLabel=t('Open original','原文を開く');a.href=item.url;a.target='_blank';a.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','M14 3h7v7M21 3l-11 11M10 5H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5');svg.append(path);a.append(svg);actions.append(a);}
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(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';share.addEventListener('click',sharePopup);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||'')+' · '+(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 · 読取専用');