record.jsimport {pageExists} from '/api/code/takker/scrapboxに特定のページが存在するかどうか確かめる/pageExists.js';
export default async function() {
const project_name = scrapbox.Project.name;
const zero = n => String(n).padStart(2, '0');
const timestamp = d => `${d.getFullYear()}-${zero(d.getMonth() + 1)}-${zero(d.getDate())}`;
const today = timestamp(new Date());
let _yesterday = new Date();
_yesterday.setDate(_yesterday.getDate() - 1); // 昨日の日付にする
const yesterday = timestamp(_yesterday);
const title=`日刊記録sheet ${today}`;
// 既に作成されている場合はそのページを開く
const isExist = await pageExists(project_name, title);
if (isExist) {
window.open(`https://scrapbox.io/${project_name}/${title}`);
return;
}
const lines=[
`yesterday: [日刊記録sheet ${yesterday}]`,
'',
'[** 00:00 - 03:00] 未明',
' ',
'',
'[** 03:00 - 06:00] 明け方',
' ',
'',
'[** 06:00 - 09:00] 朝',
' ',
'',
'[** 09:00 - 12:00] 昼前',
' ',
'',
'[** 12:00 - 15:00] 昼過ぎ',
' ',
'',
'[** 15:00 - 18:00] 夕方',
' ',
'',
'[** 18:00 - 21:00] 夜のはじめ頃',
' ',
'',
'[** 21:00 - 00:00] 夜遅く',
' ',
'',
'',
`#${today}`];
// pageを生成
const body = encodeURIComponent(lines.join('\n'));
window.open(`https://scrapbox.io/${project_name}/${title}?body=${body}`);
}