mobileからtimestampを行頭に挿入するUserScript
Screenshot
あとで撮影する
script.jsimport {
todayYYYYMMDD, todayHHMMSS, todayYYYYMMDD_HHMMSS
} from '/api/code/customize/mobileからtimestampを行頭に挿入するUserScript/timestamp.js';
import {isMobile} from '/api/code/customize/モバイル版Scrapboxかどうかを判定するUserScript/script.js';
if (isMobile()) {
const id = 'Timestamp';
scrapbox.PageMenu.addMenu({
title: id,
image: 'https://img.icons8.com/ios/180/add-time.png',
// dark themeのときは↓を使う
//image: 'https://img.icons8.com/ios/180/FFFFFF/add-time.png',
});
好きなタイムスタンプを挿入できるようにするには、以下の addItem
を書き換えてください
script.js scrapbox.PageMenu(id).addItem({
title: '#YYYY-MM-DD HH:mm:ss ',
onClick: () => todayYYYYMMDD_HHMMSS({type: 'hash'}),
});
scrapbox.PageMenu(id).addItem({
title: 'YYYY-MM-DD HH:mm:ss ',
onClick: () => todayYYYYMMDD_HHMMSS(),
});
scrapbox.PageMenu(id).addItem({
title: 'HH:mm:ss ',
onClick: () => todayHHMMSS(),
});
scrapbox.PageMenu(id).addItem({
title: '[YYYY-MM-DD]',
onClick: () => todayYYYYMMDD({type: 'link'}),
});
}
timestamp.jsimport {insertText} from '/api/code/customize/scrapbox-insert-text/script.js';
const zero = n => String(n).padStart(2, '0');
const toYYYYMMDD = d => `${d.getFullYear()}-${zero(d.getMonth() + 1)}-${zero(d.getDate())}`;
const toHHMMSS = d => `${zero(d.getHours())}:${zero(d.getMinutes())}:${zero(d.getSeconds())}`;
const toHHMM = d => `${zero(d.getHours())}:${zero(d.getMinutes())}`;
const toYYYYMMDD_HHMMSS = d => `${toYYYYMMDD(d)} ${toHHMMSS(d)}`;
export 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});
}