(() => { 'use strict'; const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en; for(const node of document.querySelectorAll('[data-revision-time]')){ const date=new Date(Number(node.dataset.revisionTime)*1000); if(!Number.isNaN(date.valueOf())){node.dateTime=date.toISOString();node.textContent=date.toLocaleString(undefined,{year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit',timeZoneName:'short'});node.title=date.toISOString();} } let busy=false; document.addEventListener('click',async event=>{ const button=event.target.closest('[data-restore-revision]');if(!button||busy)return; const message=prompt(t('Restore as a new revision. Enter a change message:','新しいリビジョンとして復元します。更新メッセージを入力してください。'),t('Restore revision ','リビジョンを復元: ')+button.dataset.restoreRevision); if(message===null)return; busy=true;button.disabled=true; try{ const response=await fetch('/_/api/v1/revisions/restore',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify({revision_uuid:button.dataset.restoreRevision,base_revision_uuid:button.dataset.baseRevision,message}),signal:AbortSignal.timeout(30000)}); if(response.redirected||!response.ok)throw Error(response.status===412?t('Changed elsewhere. Reload history before restoring.','別の画面で更新されました。履歴を再読み込みしてから復元してください。'):t('Restore failed. Check your login and permissions.','復元できませんでした。ログイン状態と権限を確認してください。')); location.reload(); }catch(error){alert(error.message);}finally{busy=false;button.disabled=false;} }); })();