Skip to content

Instantly share code, notes, and snippets.

@flyisland
Last active August 3, 2023 01:37
Show Gist options
  • Save flyisland/697bf278d1961ec308903b11703a561a to your computer and use it in GitHub Desktop.
Save flyisland/697bf278d1961ec308903b11703a561a to your computer and use it in GitHub Desktop.
A JS snippet to add a checkbox to each transaction of the Fava Journal to change its background color
const journal = document.querySelector("ol.journal");
const head = journal.querySelector("li.head p")
const checkHead = document.createElement('span');
checkHead.className = "flag"
checkHead.textContent = 'X';
head.insertBefore(checkHead, head.firstChild);
function handleCheckboxChange(event) {
if (event.target.checked) {
event.target.parentNode.style.backgroundColor = 'lightgreen';
} else {
event.target.parentNode.style.backgroundColor = '';
}
}
const trans = journal.querySelectorAll("li.transaction p")
trans.forEach(tran => {
const checkbox = document.createElement('input');
checkbox.className = "flag"
checkbox.type = 'checkbox';
tran.insertBefore(checkbox, tran.firstChild);
checkbox.addEventListener('change', handleCheckboxChange);
})
@flyisland
Copy link
Author

This comes in handy when reviewing the accounts for any mistakes or oversights.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment