開いているページをエクスポートするUserScript
ボタン用の画像: https://scrapbox.io/files/64d6cf929d602b001cf95ae9.svg
c.f. /customize/特定のページのみを含んだexport用dataを生成するbookmarklet
minify バージョン
code:script_min.js
scrapbox.PageMenu.addMenu({title:"export data",image:"https://scrapbox.io/files/64d6cf929d602b001cf95ae9.svg",onClick:async()=>{const o=${scrapbox.Project.name},a=${encodeURIComponent(scrapbox.Page.title)},c=/api/pages/${o}/${a},t=await(await fetch(c)).json(),s={pages:{title:t.title,created:t.created,updated:t.updated,lines:t.lines}},d=new Blob(JSON.stringify(s,null," "),{type:"octet/stream"}),n=window.URL.createObjectURL(d),e=document.createElement("a");e.href=n,e.download=${o}-${a}.json,e.style.display="none",document.body.appendChild(e),e.click(),window.URL.revokeObjectURL(n),e.parentNode.removeChild(e)}});
readable バージョン
code:script.js
scrapbox.PageMenu.addMenu({
title: 'export data',
image: 'https://scrapbox.io/files/64d6cf929d602b001cf95ae9.svg',
onClick: async () => {
const projectName = ${scrapbox.Project.name};
const pageName = ${encodeURIComponent(scrapbox.Page.title)};
const target = /api/pages/${projectName}/${pageName};
const response = await fetch(target); // 重いページで重くなる可能性がある
const json = await response.json();
const exportData = {pages: [{
title: json.title,
created: json.created,
updated: json.updated,
lines: json.lines,
},],};
const blob = new Blob(JSON.stringify(exportData,null,' '), {type: 'octet/stream'}); // download dataを作成
const url = window.URL.createObjectURL(blob); // download linkを生成
// 同一scrapbox pageに隠しa要素を作り、それを踏んでdownloadを実行する
const a = document.createElement('a');
a.href = url;
a.download = ${projectName}-${pageName}.json;
a.style.display = 'none';
document.body.appendChild(a);
a.click(); // downloadを実行
// 後始末
window.URL.revokeObjectURL(url);
a.parentNode.removeChild(a);
},
});
ボタン用の画像の SVG
File Export Classic Solid Icon | Font Awesome
code:export.svg
<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><style>svg{fill:#848484}</style><path d="M0 64C0 28.7 28.7 0 64 0H224V128c0 17.7 14.3 32 32 32H384V288H216c-13.3 0-24 10.7-24 24s10.7 24 24 24H384V448c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V64zM384 336V288H494.1l-39-39c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l80 80c9.4 9.4 9.4 24.6 0 33.9l-80 80c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l39-39H384zm0-208H256V0L384 128z"/></svg>
昔作ったやつだtakker.icon