Skip to content

Instantly share code, notes, and snippets.

@MikaelCarpenter
Created June 19, 2022 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikaelCarpenter/8f9c62d382830633407ab4d453a9be9f to your computer and use it in GitHub Desktop.
Save MikaelCarpenter/8f9c62d382830633407ab4d453a9be9f to your computer and use it in GitHub Desktop.
// Reference: https://github.com/tobyxdd/bread/blob/master/bread.js
function processWord(word, node) {
const len = word.length;
const boldLen = Math.ceil(len * 0.45); // might need an exception for 1 letter words
const boldText = word.substring(0, boldLen);
const normText = word.substring(boldLen);
const span = document.createElement("span");
span.style.fontWeight = "bolder";
span.appendChild(document.createTextNode(boldText));
node.parentNode.insertBefore(span, node);
node.parentNode.insertBefore(document.createTextNode(`${normText} `), node);
}
function processNode(node) {
const text = node.textContent;
const words = text.split(" ");
words.forEach((word) => processWord(word, node));
node.remove();
}
// customize for your content
const textNodes = document.querySelectorAll(
"#contentPanel > div > div.EOs2MW > div > div.bWSNNT > div._14BzLL span"
);
textNodes.forEach(processNode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment