Last active
August 3, 2023 01:37
-
-
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
This file contains 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
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); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comes in handy when reviewing the accounts for any mistakes or oversights.