Last active
December 4, 2018 15:22
-
-
Save shotasenga/375b2091b0cc8bb2cc80db475cf2e0b2 to your computer and use it in GitHub Desktop.
マネーフォーワードの食費を自販機の消費かどうか振り分けるボタン追加
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name MoneyFoward is it vendning machine? | |
// @namespace http://senta.me/ | |
// @version 0.1.2 | |
// @description マネーフォーワードの食費を自販機の消費かどうか振り分けるボタン追加 | |
// @author @__senta | |
// @match https://moneyforward.com/cf | |
// @grant none | |
// ==/UserScript== | |
;(() => { | |
const innerText = el => el.innerText.trim() | |
const innerNumber = el => parseInt(innerText(el), 10) | |
const go = () => { | |
const queue = Array.from( | |
document.querySelectorAll(".transaction_list.target-active") | |
) | |
.map(el => ({ | |
$subcategory: el.querySelector("td:nth-of-type(7)"), | |
category: innerText(el.querySelector("td:nth-of-type(6)")), | |
price: Math.abs(innerNumber(el.querySelector("td:nth-of-type(4)"))) | |
})) | |
.filter(({ category }) => category === "食費") | |
.map(({ price, $subcategory }) => ({ | |
$subcategory, | |
actual: price < 170 ? "自販機" : "食費" | |
})) | |
.filter(({ $subcategory, actual }) => innerText($subcategory) !== actual) | |
setTimeout(function process() { | |
const { $subcategory, actual } = queue.pop() | |
$subcategory.querySelector('[data-toggle="dropdown"]').click() | |
Array.from($subcategory.querySelectorAll(".dropdown-menu.sub_menu a")) | |
.find(el => innerText(el) === actual) | |
.click() | |
if (queue.length > 0) { | |
console.log(`${queue.length} remaining`) | |
setTimeout(process, 1000) | |
} else { | |
console.log(`finished`) | |
} | |
}) | |
} | |
const button = document.createElement("button") | |
button.className = "btn" | |
button.innerText = "食費振り分け" | |
button.addEventListener("click", go) | |
document.querySelector(".footer_links").appendChild(button) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment