script.jsimport {insertText} from '/api/code/takker/scrapbox-insert-text/script.js';
import {toYYYYMMDD, toHHMMSS, toYYYYMMDD_HHMMSS} from '/api/code/takker/scrapbox-timestamp/timestamp.js';
timestamp.jsconst zero = n => String(n).padStart(2, '0');
export function toYYYYMMDD(d, {separator = '-'} = {}) {
return `${d.getFullYear()}${separator}${zero(d.getMonth() + 1)}${separator}${zero(d.getDate())}`;
}
export const toHHMMSS = d => `${zero(d.getHours())}:${zero(d.getMinutes())}:${zero(d.getSeconds())}`;
export const toHHMM = d => `${zero(d.getHours())}:${zero(d.getMinutes())}`;
export const toYYYYMMDD_HHMMSS = d => `${toYYYYMMDD(d)} ${toHHMMSS(d)}`;
script.jsexport function todayYYYYMMDD({type = 'plain'} ={}) {
const today = toYYYYMMDD(new Date());
const text = (() => {
switch(type) {
case 'plain':
return `${today} `;
case 'hash':
return `#${today} `;
case 'link':
return `[${today}]`;
}
})();
insertText({text});
}
export function todayHHMMSS() {
const today = toHHMMSS(new Date());
insertText({text: `${today} `});
}
export function todayYYYYMMDD_HHMMSS({type = 'plain'} ={}) {
const now = new Date();
const today = toYYYYMMDD(now);
const time = toHHMMSS(now);
const text = (() => {
switch(type) {
case 'plain':
return `${today} ${time} `;
case 'hash':
return `#${today} ${time} `;
case 'link':
return `[${today}] ${time} `;
}
})();
insertText({text});
}