Last active
November 21, 2024 17:22
-
-
Save Nick-Gabe/d2523ff31f759ea7d856262a56fca696 to your computer and use it in GitHub Desktop.
Share Carbon custom theme
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
// 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