mobileからtimestampを行頭に挿入するUserScript
Screenshot
あとで撮影する
code:script.js
import {
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,
// dark themeのときは↓を使う
});
好きなタイムスタンプを挿入できるようにするには、以下のaddItemを書き換えてください
code: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({
onClick: () => todayYYYYMMDD({type: 'link'}),
});
}
code:timestamp.js
import {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});
}
UserScript.icon