Skip to content

Instantly share code, notes, and snippets.

@nopeless
Created July 7, 2025 17:31
Show Gist options
  • Select an option

  • Save nopeless/37e3559d22b2be25b7f7aff335e7322a to your computer and use it in GitHub Desktop.

Select an option

Save nopeless/37e3559d22b2be25b7f7aff335e7322a to your computer and use it in GitHub Desktop.
const classes = new Set();
document.querySelectorAll('[class]').forEach(el => {
el.classList.forEach(cls => classes.add(cls));
});
const replacer = prefix => [...classes].find(c => c.startsWith(prefix));
const classRegex = /class\^=("[^"]+"|(?:\\.|[^\\\n\]])+)/g;
const cssProcessor = text => text.replace(classRegex, match => `class=${replacer(match[1])}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment