作成・更新日表示機能
code:script.js
import DateTool from '/api/code/src-wintyo/library/DateTool.js';
(() => {
function createDateHtml (createdDate, updatedDate) {
const createdDateString = DateTool.format(createdDate, 'YYYY/MM/DD hh:mm:ss');
const updatedDateString = DateTool.format(updatedDate, 'YYYY/MM/DD hh:mm:ss');
return $('<span>')
.addClass('page-created-date')
.text(Created: ${createdDateString} + '\n' + Updated: ${updatedDateString});
}
function setOrUpdateTime () {
if (scrapbox.Layout !== 'page') {
return;
}
const $dateLabel = $('.page-menu .date-label');
const createdDate = new Date($dateLabel.eq(0).attr('title'));
const updatedDate = new Date($dateLabel.eq(1).attr('title'));
$('.page-created-date').remove();
$('.editor').append(createDateHtml(createdDate, updatedDate));
}
new MutationObserver(setOrUpdateTime)
.observe(document.querySelector('title'), { childList: true })
setOrUpdateTime();
})();
code:style.css
.page-created-date {
position: absolute;
top: -34px;
right: 0;
font-size: 15px;
line-height: 1.2;
text-align: right;
white-space: pre-wrap;
}
参考