Last active
March 22, 2023 18:38
-
-
Save marcustyphoon/22a2554e35ae59b84fd0365cd49c4b28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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