Skip to content

Instantly share code, notes, and snippets.

@freaktechnik
Created May 22, 2023 08:03
Show Gist options
  • Save freaktechnik/d8ad59cbd7fc1668425a2ed6098427c8 to your computer and use it in GitHub Desktop.
Save freaktechnik/d8ad59cbd7fc1668425a2ed6098427c8 to your computer and use it in GitHub Desktop.
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