Skip to content

Instantly share code, notes, and snippets.

@kartiknair
Created May 12, 2020 11:00
Show Gist options
  • Save kartiknair/55101e69b1f9eb3284219a3dce9723db to your computer and use it in GitHub Desktop.
Save kartiknair/55101e69b1f9eb3284219a3dce9723db to your computer and use it in GitHub Desktop.
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