scrapbox-commit-viewer
/icons/hr.icon
こんなかんじ
table:table
時刻 ID 差分
YYYY-MM-DD aaddadad +.......
-........
別のタブで開くようにする
使い方
開発コンソールから実行する
code:js
import('/api/code/takker/scrapbox-commit-viewer/script.js')
.then(({execute}) => execute());
Page menuから実行する
code:pageMenu.js
import {execute} from '/api/code/takker/scrapbox-commit-viewer/script.js';
scrapbox.PageMenu.addItem({
title: 'Show this page\'s commits',
onClick: () => execute(),
});
bookmarkletから実行する
無理
ESModuleを使えない
ちょっと見にくいかも
beforeとafterに余白が入りすぎている
code:script.js
import {
table, caption, thead, th, tbody, tr, td,
a, style,
} from '../easyDOMgenerator/script.js';
import {lightFormat} from '../date-fns.min.js/script.js';
export async function execute() {
const project = scrapbox.Project.name;
const title = scrapbox.Page.title;
const id = scrapbox.Page.id;
const res = await fetch(/api/commits/${project}/${id})
const {commits} = await res.json();
const dom = table(
caption(
a(
{href: ../${project}/${title}, target: '_blank', rel: 'noopener noreferrer'},
/${project}/${title}
),
'の編集履歴'
),
thead(th('Datetime'), th('Type'), th('Before'), th('After')),
tbody(...commits.flatMap(({created, changes}) => [
tr(
td(lightFormat(new Date(created * 1000), 'yyyy-MM-dd HH:mm:ss')),
td(changes0.lines.origText ?? ''), td(changes0.lines.text ?? ''), ),
...changes.slice(1).flatMap(change => !getType(change) ? [] :
[tr(
td(''),
td(getType(change)),
td(change.lines.origText ?? ''),
td(change.lines.text ?? ''),
)]
),
])),
);
const tab = window.open();
tab.document.write(dom.outerHTML);
tab.document.close();
tab.document.head.appendChild(style(
`th {
text-align: left;
}
td {
white-space: nowrap;
}
`
));
}
function getType(change) {
return Object.keys(change).find(key => key.startsWith('_'))?.slice?.(1);
}