Skip to content

Instantly share code, notes, and snippets.

@kartofelek007
Last active December 27, 2024 15:04
Show Gist options
  • Select an option

  • Save kartofelek007/9ac04afbd87308f3f262cda630b9798a to your computer and use it in GitHub Desktop.

Select an option

Save kartofelek007/9ac04afbd87308f3f262cda630b9798a to your computer and use it in GitHub Desktop.
Sierotki w js
function getAllTexts(rootElement) {
const treeWalker = document.createTreeWalker(
rootElement,
NodeFilter.SHOW_TEXT,
{
acceptNode: (node) => {
if (node.nextElementSibling != null || (node.textContent.length <= 2 && node.textContent.search("\n") !== -1)) {
return NodeFilter.FILTER_SKIP;
} else {
return NodeFilter.FILTER_ACCEPT;
}
}
},
false
);
const nodeList = [];
while (treeWalker.nextNode()) {
nodeList.push(treeWalker.currentNode);
}
return nodeList;
}
export function sieroty() {
const textElements = getAllTexts(document.body);
for (let el of textElements) {
let current = el.nodeValue;
current = current.replace(/ +/g, ' ');
current = current.replace(/\s[a]\s/g, ' a\u00A0'); //\u00A0 - &nbsp; https://stackoverflow.com/questions/66638682/nbsp-not-displaying-properly-in-javascript
current = current.replace(/\s[i]\s/g, ' i\u00A0');
current = current.replace(/\s[o]\s/g, ' o\u00A0');
current = current.replace(/\s[u]\s/g, ' u\u00A0');
current = current.replace(/\s[w]\s/g, ' w\u00A0');
current = current.replace(/\s[z]\s/g, ' z\u00A0');
el.nodeValue = current;
}
}
@Qweter333

Copy link
Copy Markdown

Thank you for such useful information! I will try to apply it in practice

Finding a reliable online game can be tricky, but this Richard Casino is a great choice. It offers a wide range of games, including slots and live poker, giving you the chance to have fun and win money. The support team is quick and helpful, and the site’s clean design makes navigation simple. On top of that, there are awesome bonuses to enhance your gaming experience!

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