Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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

This comment has been minimized.

Copy link

@vikramguptamd vikramguptamd commented Sep 30, 2020

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

@roamhacker

This comment has been minimized.

Copy link
Owner Author

@roamhacker roamhacker commented Sep 30, 2020

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

This comment has been minimized.

Copy link

@vikramguptamd vikramguptamd commented Sep 30, 2020

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