-
-
Save kartiknair/55101e69b1f9eb3284219a3dce9723db 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
import { getContrast } from "color2k"; | |
import { cloudflareColors } from "./colors"; | |
let accessibleCombo = null; | |
while (!accessibleCombo) { | |
let randomPair = [ | |
cloudflareColors[Math.floor(Math.random() * cloudflareColors.length)].hex, | |
cloudflareColors[Math.floor(Math.random() * cloudflareColors.length)].hex, | |
]; | |
if (getContrast(randomPair[0], randomPair[1]) > 7.1) | |
accessibleCombo = randomPair; | |
} | |
const newStyle = document.createElement("style"); | |
newStyle.innerHTML = ` | |
main { | |
background-color: ${accessibleCombo[0]}; | |
color: ${accessibleCombo[1]}; | |
}`; | |
document.head.appendChild(newStyle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment