Skip to content

Instantly share code, notes, and snippets.

@mohno007
Last active January 16, 2020 10:26
Show Gist options
  • Save mohno007/fa55de20f3707e108408aa194fafd5ee to your computer and use it in GitHub Desktop.
Save mohno007/fa55de20f3707e108408aa194fafd5ee to your computer and use it in GitHub Desktop.
マネーフォワード経費(MF経費) で経費一覧で抜けている日付を一覧表示するBookmarklet
javascript:{
const datesOfMonth = date => {
const firstDate = firstOfMonth(date);
const until = nextFirstOfMonth(date);
const result = [];
for (let date = new Date(firstDate); +date < +until; date.addDays(1))
result.push(new Date(date));
return result;
};
const firstOfMonth = d=>{
const firstDate = new Date(d);
firstDate.setDate(1);
return firstDate;
};
const nextFirstOfMonth = d=>{
const nxt = firstOfMonth(d);
nxt.addMonths(1);
return nxt;
};
const isWeekday = d=>{
const day = d.getDay();
return day >= 1 && day <= 5;
};
const format = d=>{
const y = d.getFullYear();
const m = d.getMonth() + 1;
const dm = ("" + d.getDate()).padStart(2, "0");
const wd = "日月火水木金土"[d.getDay()];
return `${y}/${m}/${dm}(${wd})`;
};
const parse = s => new Date(s);
const dateElems = [...document.querySelectorAll('#ex-main-container > div.ex-container > div.ex-form-container > table > tbody > tr > td.js-transaction-recognized_at_td')];
const dates = [...dateElems.reduce((set,curr)=>set.add(curr.textContent), new Set())].sort();
const required = new Set(datesOfMonth(parse(dates[0])).filter(isWeekday).map(format));
const missing = new Set(required);
for (const date of dates) {
missing.delete(date);
}
alert([...missing].join('\n'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment