Last active
December 4, 2019 17:36
-
-
Save benjamincharity/489b73c571ee06d7ca758e2b846433d0 to your computer and use it in GitHub Desktop.
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 sheet = window.document.styleSheets[0]; | |
const rule = '.task-list-item-checkbox:checked+.task-list-item-text{opacity:.5;text-decoration:line-through;}'; | |
sheet.insertRule(rule, sheet.cssRules.length); | |
const listItems = document.querySelectorAll('.task-list-item'); | |
Array.from(listItems).forEach(item => { | |
const nodes = Array.from(item.childNodes).filter(item => item instanceof Text || item.tagName === "CODE"); | |
const checkbox = item.querySelectorAll('input')[0]; | |
const originalText = nodes.map(node => node.nodeValue || node.textContent).join('').trim(); | |
const replacementNode = document.createElement('span'); | |
replacementNode.classList.add('task-list-item-text'); | |
replacementNode.innerHTML = originalText; | |
item.insertBefore(replacementNode, checkbox.nextSibling); | |
Array.from(item.childNodes).forEach(node => { | |
if (node instanceof Text || node.tagName === "CODE") { | |
node.remove(); | |
} | |
}); | |
}); | |
} |
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 e=window.document.styleSheets[0],t=".task-list-item-checkbox:checked+.task-list-item-text{opacity:.5;text-decoration:line-through;}";e.insertRule(t,e.cssRules.length);const o=document.querySelectorAll(".task-list-item");Array.from(o).forEach(e=>{const t=Array.from(e.childNodes).filter(e=>e instanceof Text||"CODE"===e.tagName),o=e.querySelectorAll("input")[0],n=t.map(e=>e.nodeValue||e.textContent).join("").trim(),i=document.createElement("span");i.classList.add("task-list-item-text"),i.innerHTML=n,e.insertBefore(i,o.nextSibling),Array.from(e.childNodes).forEach(e=>{(e instanceof Text||"CODE"===e.tagName)&&e.remove()})})} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment