benjamincharity
12/4/2019 - 5:24 PM

Strikethrough for GitHub checkboxes

{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()})})}
{
  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();
      }
    });
  });
}