Skip to content

Instantly share code, notes, and snippets.

@marcustyphoon
Last active March 22, 2023 18:38
Show Gist options
  • Save marcustyphoon/22a2554e35ae59b84fd0365cd49c4b28 to your computer and use it in GitHub Desktop.
Save marcustyphoon/22a2554e35ae59b84fd0365cd49c4b28 to your computer and use it in GitHub Desktop.
tumblr.getCssMap().then((s=>{const o=(s,o)=>"πŸ“"+o,t="β€’",c={};for(const[o,t]of Object.entries(s))for(const s of t)c[s]=o;const n=document.querySelectorAll(`[class]:not(.${t})`);for(const s of n){const n=[];for(const t of s.classList.values()){const s=c[t];s&&n.push(o(t,s))}s.classList.add(t,...n)}}));
tumblr.getCssMap().then((cssMap) => {
const options = {
// Choose how you would like each translated class formatted.
// Yes, emoji are supported! Avoid punctuation and whitespace.
format: (originalCss, mappedCss) => 'πŸ“' + mappedCss,
// This class gets added to almost every DOM element.
// It's nice to make it short for the π’Άπ‘’π“ˆπ“‰π’½π‘’π“‰π’Ύπ’Έ.
markerClass: 'β€’',
};
const reverseCssMap = {};
for (const [key, values] of Object.entries(cssMap)) {
for (const value of values) {
reverseCssMap[value] = key;
}
}
const elements = document.querySelectorAll(`[class]:not(.${options.markerClass})`);
for (const element of elements) {
const classes = [];
for (const css of element.classList.values()) {
const mappedCss = reverseCssMap[css];
if (mappedCss) {
classes.push(options.format(css, mappedCss));
}
}
element.classList.add(options.markerClass, ...classes);
}
console.log(`added css map to ${elements.length} elements`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment