Skip to content

Instantly share code, notes, and snippets.

@TfTHacker
Last active November 9, 2020 20:13
Show Gist options
  • Save TfTHacker/94fd043b195af43e3e6fb715bda7409b to your computer and use it in GitHub Desktop.
Save TfTHacker/94fd043b195af43e3e6fb715bda7409b to your computer and use it in GitHub Desktop.
// roam/js code snippet to add crossing out completed todos
// also adds the CSS classname custom-strikethrough for css mods
;(()=>{
if( typeof window.roamhacker_checkboxStrikeout != 'undefined') return;
window.roamhacker_checkboxStrikeout = {};
const scanCheckboxes = () => {
document.querySelectorAll('.check-container input').forEach( (element)=>{
var span = element.parentElement.parentElement.parentElement
if(element.checked) {
span.classList.add('custom-strikethrough')
span.style.textDecoration='line-through'
} else {
span.classList.remove('custom-strikethrough')
span.style.textDecoration='none'
}
})
}
scanCheckboxes()
var observerCheckBoxes = new MutationObserver(scanCheckboxes);
observerCheckBoxes.observe(document.querySelector('#app'), {
childList: true,
subtree: true
})
})();
@vikramguptamd
Copy link

Hi guys, newbie here... so how do I add this to Roam?

@TfTHacker
Copy link
Author

Hi guys, newbie here... so how do I add this to Roam?
You need to add a roam/js block. So steps:

  1. Create a new page in your Roam Graph (Name it whatever you want)
  2. in a block type {{[[roam/js]]}} then ENTER
  3. in the new block below the one you just typed into, press tab (this second block needs to be directly underneath the block from step 2 and needs to be indented under that block)
  4. type /Code Block (forward slash for commands
  5. Then you will see in the block a CODE editor. Very small. Paste the code from above into that code editor
  6. In the code editor, change the code type to "Javascript" -- there is a list of supported coding languages in upper right hand corner of the code block
  7. Press the button in the [[roam/js]] block to activate the code

@vikramguptamd
Copy link

Thank you 🙏🏼 It worked like a charm!!! I appreciate it!

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