Skip to content

Instantly share code, notes, and snippets.

@Nick-Gabe
Last active April 28, 2023 22:23
Show Gist options
  • Save Nick-Gabe/d2523ff31f759ea7d856262a56fca696 to your computer and use it in GitHub Desktop.
Save Nick-Gabe/d2523ff31f759ea7d856262a56fca696 to your computer and use it in GitHub Desktop.
Share Carbon custom theme
// COPY AND PASTE IT IN YOUR BROWSER ------------------------
function generateThemeScript(themeName) {
const getTheme = (themeName) => {
const themeStorage = JSON.parse(localStorage.CARBON_THEMES || "[]");
return themeStorage.find(theme => theme.name === themeName)
}
const addTheme = (theme) => {
const themeStorage = JSON.parse(localStorage.CARBON_THEMES || "[]");
themeStorage.push(theme);
const uniqueThemeArray = themeStorage.filter((theme, index, source) => {
return index === source.findIndex(t => t.id === theme.id);
})
localStorage.setItem("CARBON_THEMES", JSON.stringify(uniqueThemeArray));
}
const theme = getTheme(themeName);
if(!theme) {
return console.error(`No theme found with the name ${themeName}`);
}
const themeStr = JSON.stringify(theme);
const addFn = addTheme.toString();
const addIIFE = `(${addFn})(${themeStr})`;
console.log(`%c
You can share the following function:
Just paste it on browser to add the theme :)
`, 'color: salmon');
console.log(addIIFE);
console.log('%cAfter pasting, refresh your page (but be cautious, save your code first)', 'color: salmon')
}
// To use it, just invoke with your theme name
// generateThemeScript("Custom Theme 1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment