-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
77 lines (72 loc) · 1.82 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var palette = ["#FF1741"];
function updateH(tier, color) {
var header = document.getElementsByTagName(tier)[0];
header.style.color = color;
header.style.opacity = 1;
var text = header.innerHTML;
var prefix = text.includes("Hover")
? "Primary Surface Color"
: text.includes(" ")
? text.split(" ")[0]
: text;
header.innerHTML =
prefix.replace(":", "") + " " + color.toUpperCase().replace("#", "#");
}
function contrast(bgColor, backgrounds = palette) {
return tinycolor.mostReadable(bgColor, backgrounds).toHexString();
}
function display(color) {
updateH("h1", "#" + color);
updateH(
"h2",
tinycolor("#" + color)
.darken("20")
.toString()
);
updateH(
"h3",
tinycolor("#" + color)
.lighten()
.toString()
);
updateH(
"h4",
tinycolor("#" + color)
.darken("20")
.darken()
.toString()
);
updateH(
"h5",
tinycolor("#" + color)
.complement()
.toHexString()
);
updateH("h6", contrast("#" + color));
updateH(
"h7",
contrast("#" + color, ["#b3b3b3", "404040", "282828", "FFFFFF", "CF6679"])
);
}
$(document).ready(() => {
for (const li of document.getElementsByClassName("color")) {
palette.push(li.getAttribute("value"));
var curr = li.getAttribute("style");
var readable = contrast(curr);
if (palette.length > 14) {
palette.splice(7, 12);
palette.splice(0, 3);
}
li.setAttribute("style", `${curr}; color: ${readable}`);
let overlay = document.createElement("div");
overlay.classList.add("overlay");
overlay.setAttribute("style", `${curr}; color: ${readable}`);
overlay.innerHTML = li.getAttribute("value");
overlay.setAttribute(
"onmouseover",
`display('${li.getAttribute("value").substring(1)}')`
);
li.appendChild(overlay);
overlay.style.cursor = "none";
}
});