templates
from 日記をテンプレートからつくるUserScript
code:diary.js
(function() {
Date.prototype.format = function(format) {
return format.replace('yyyy', this.getFullYear())
.replace('MM', ('0' + (this.getMonth() + 1)).slice(-2))
.replace('dd', ('0' + this.getDate()).slice(-2));
};
const d = new Date();
const today = d.format("yyyy-MM-dd");
const prevDay = new Date(d);
prevDay.setDate(d.getDate() - 1);
const prevDayFormatted = prevDay.format("yyyy-MM-dd");
const nextDay = new Date(d);
nextDay.setDate(d.getDate() + 1);
const nextDayFormatted = nextDay.format("yyyy-MM-dd");
const monthFormatted = d.format("yyyy-MM");
const lastWeek = new Date(d);
lastWeek.setDate(d.getDate() - 7);
const lastWeekFormatted = lastWeek.format("yyyy-MM-dd");
const hundredDaysAgo = new Date(d);
hundredDaysAgo.setDate(d.getDate() - 100);
const hundredDaysAgoFormatted = hundredDaysAgo.format("yyyy-MM-dd");
return `${today}
${prevDayFormatted} ← ${monthFormatted} → ${nextDayFormatted}
一週間前: ${lastWeekFormatted}
100日前: ${hundredDaysAgoFormatted}
#日記
`;
})();