26 lines
1.4 KiB
HTML
26 lines
1.4 KiB
HTML
<!doctype html><html lang="ja"><head><meta charset="utf-8" />
|
|
<style>body{font:14px system-ui;margin:0;padding:16px}textarea{width:100%;height:60vh}
|
|
.row{display:flex;gap:8px;align-items:center;margin-bottom:8px}</style></head>
|
|
<body>
|
|
<div class="row">
|
|
<input id="path" data-testid="path" value="output/note.md" style="flex:1" />
|
|
<button id="load" data-testid="load">読み込み</button>
|
|
<button id="save" data-testid="save">保存</button>
|
|
<span id="status" data-testid="status"></span>
|
|
</div>
|
|
<textarea id="body" data-testid="body"></textarea>
|
|
<script>
|
|
let seq=0;const pending=new Map();
|
|
function call(req){return new Promise((res,rej)=>{const id=++seq;pending.set(id,{res,rej});
|
|
window.parent.postMessage({...req,id},'*');});}
|
|
window.addEventListener('message',e=>{const r=e.data;const p=pending.get(r&&r.id);if(!p)return;
|
|
pending.delete(r.id);r.ok?p.res(r.data):p.rej(new Error(r.error));});
|
|
const $=id=>document.getElementById(id);
|
|
async function load(){try{const d=await call({type:'readFile',path:$('path').value});
|
|
$('body').value=d.content;$('status').textContent='読込OK';}catch(err){$('status').textContent='読込失敗:'+err.message;}}
|
|
async function save(){try{await call({type:'writeFile',path:$('path').value,content:$('body').value});
|
|
$('status').textContent='保存OK';}catch(err){$('status').textContent='保存失敗:'+err.message;}}
|
|
$('load').onclick=load;$('save').onclick=save;
|
|
load();
|
|
</script></body></html>
|