選択範囲を日付書式に変換するUserScript
code:script.js
scrapbox.PopupMenu.addButton({
onClick: text => text.split('\n').map(t => {
// あきらめた正規表現
const regexpDate = /(.*)\(\[?0-9{4}.0-9{2}\?.0-9{2}.*?)\](.*)/; // 2020-02-03みたいな文字を抜き出す
const regexpDash = /(.*)([0-9]{4}.[0-9]{2}.[0-9]{2}.*?)(.*)/;
const match = regexpDate.exec(t) ?? regexpDash.exec(t);
if (match === null) return t;
.replace(/\|\|\(|\)/g, '') .split(/( | Mon| Tue| Wed| Thu| Fri| Sat| Sun) ?/);
console.log(tmp);
let date;
let isOutputTime = false;
if (tmp.length === 3 || tmp.length === 5) {
// 曜日、時分がありそうな場合
date = new Date(${tmp[0]} ${tmp[tmp.length - 1]})
isOutputTime = true;
} else {
}
const yyyy = date.getFullYear();
const mm = ("0" + (date.getMonth() + 1)).slice(-2);
const dd = ("0" + (date.getDate())).slice(-2);
let ymd = ${yyyy}/${mm}/${dd}
if (isOutputTime) {
const hh = ("0" + (date.getHours())).slice(-2);
const mi = ("0" + (date.getMinutes())).slice(-2);
const ss = ("0" + (date.getSeconds())).slice(-2);
ymd = ${ymd} ${hh}:${mi}:${ss}
}
return ${before}${after}[! (${ymd})];
}).join('\n')
});
更新履歴
1.0.0 UserScript作成
2.0.0 menuselection追加(2020/04/08)
2.0.1 title修正(2020/09/30 09:32:23)
2.1.0 FSC追加(2020/10/22 14:03:26)