Created
May 22, 2023 08:03
-
-
Save freaktechnik/d8ad59cbd7fc1668425a2ed6098427c8 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
function party() { | |
const colors = Array.from(document.styleSheets).find(stylesheet => | |
stylesheet.href.endsWith("colors.css") | |
).cssRules[0].style; | |
const colorVariables = Object.values(colors); | |
const sourceStyles = document.documentElement.style.getPropertyValue( | |
colorVariables[0] | |
) | |
? document.documentElement.style | |
: colors; | |
const nextColor = colorVariables.map((color, index) => { | |
const nextIndex = (index + 1) % colorVariables.length; | |
return [color, sourceStyles.getPropertyValue(colorVariables[nextIndex])]; | |
}); | |
for (const [property, color] of nextColor) { | |
document.documentElement.style.setProperty(property, color, "important"); | |
} | |
const colorBrowsers = Array.from(document.querySelectorAll("browser")).filter( | |
browser => | |
browser.src && | |
Array.from(browser.contentDocument.styleSheets).some(stylesheet => | |
stylesheet.href.endsWith("colors.css") | |
) | |
); | |
for (const browser of colorBrowsers) { | |
for (const [property, color] of nextColor) { | |
browser.contentDocument.documentElement.style.setProperty( | |
property, | |
color, | |
"important" | |
); | |
} | |
} | |
} | |
setInterval(party, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment