-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
289 lines (234 loc) · 10.6 KB
/
scripts.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
document.addEventListener("DOMContentLoaded", () => {
const extendedColors = [
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque",
"black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood",
"cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk",
"crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray",
"darkgreen", "darkgrey", "darkkhaki", "darkmagenta", "darkolivegreen",
"darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
"darkslateblue", "darkslategray", "darkslategrey", "darkturquoise", "darkviolet",
"deeppink", "deepskyblue", "dimgray", "dimgrey", "dodgerblue", "firebrick",
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold",
"goldenrod", "gray", "green", "greenyellow", "grey", "honeydew", "hotpink",
"indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush",
"lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan",
"lightgoldenrodyellow", "lightgray", "lightgreen", "lightgrey", "lightpink",
"lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
"lightslategrey", "lightsteelblue", "lightyellow", "lime", "limegreen",
"linen", "magenta", "maroon", "mediumaquamarine", "mediumblue",
"mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue",
"mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue",
"mintcream", "mistyrose", "moccasin", "navajowhite", "navy", "oldlace",
"olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod",
"palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff",
"peru", "pink", "plum", "powderblue", "purple", "red", "rosybrown",
"royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell",
"sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey",
"snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato",
"turquoise", "violet", "wheat", "white", "whitesmoke", "yellow",
"yellowgreen"
];
const colorKeywordPicker = document.getElementById("colorKeywordPicker");
const picon1 = document.getElementById("picon_1");
const picon2 = document.getElementById("picon_2");
const picon3 = document.getElementById("picon_3");
const picon4 = document.getElementById("picon_4");
const picon5 = document.getElementById("picon_5");
const picon6 = document.getElementById("picon_6");
const fanOfficeCoolStatus1 = document.getElementById("acOfficeCoolStatus1");
// Create table
const tableContainer = document.getElementById("colorTableContainer");
const table = document.createElement("table");
const tbody = document.createElement("tbody");
let isFirstLoad = true;
const showCopyNotification = (colorName) => {
if (isFirstLoad) return;
const copyNotification = document.getElementById("copyNotification");
copyNotification.textContent = `${colorName} copied to clipboard!`;
copyNotification.classList.add("show-message");
setTimeout(() => {
copyNotification.classList.remove("show-message");
}, 2000);
};
const copyToClipboard = (color) => {
const tempTextarea = document.createElement("textarea");
tempTextarea.value = color;
document.body.appendChild(tempTextarea);
tempTextarea.select();
document.execCommand("copy");
document.body.removeChild(tempTextarea);
showCopyNotification(color);
picon_1.style.color = color;
picon_2.style.color = color;
picon_3.style.color = color;
picon_4.style.color = color;
picon_5.style.color = color;
picon_6.style.color = color;
if (fanOfficeCoolStatus1.textContent === "On") {
picon1.classList.add("active");
} else {
picon1.classList.remove("active");
}
};
const defaultColor = "aliceblue";
copyToClipboard(defaultColor);
isFirstLoad = false;
let row;
extendedColors.forEach((color, index) => {
if (index % 22 === 0) {
row = document.createElement("tr");
tbody.appendChild(row);
}
const cell = document.createElement("td");
cell.style.backgroundColor = color;
cell.addEventListener("click", () => copyToClipboard(color));
row.appendChild(cell);
});
table.appendChild(tbody);
tableContainer.appendChild(table);
extendedColors.forEach((color) => {
const option = document.createElement("option");
option.value = color;
option.textContent = color;
colorKeywordPicker.appendChild(option);
});
const hueRange = document.getElementById("hueRange");
const saturationRange = document.getElementById("saturationRange");
const lightnessRange = document.getElementById("lightnessRange");
const alphaRange = document.getElementById("alphaRange");
const hueValue = document.getElementById("hueValue");
const saturationValue = document.getElementById("saturationValue");
const lightnessValue = document.getElementById("lightnessValue");
const alphaValue = document.getElementById("alphaValue");
const modifierColorDisplay = document.getElementById("modifierColorDisplay");
const iconExamples = document.querySelectorAll(".icon");
const copyMessageHSL = document.getElementById("copyMessageHSL");
const updateFanColorAndState = () => {
const hslColor = `hsla(${hueRange.value}, ${saturationRange.value}%, ${lightnessRange.value}%, ${alphaRange.value})`;
// Update the fan color and status
// fanOfficeCool.style.backgroundColor = hslColor;
modifierColorDisplay.style.backgroundColor = hslColor;
// Simulate turning the fan "On" and applying animation
// if (fanOfficeCoolStatus.textContent === "On") {
// fanOfficeCool.classList.add("active", "dynamic-color");
//} else {
// fanOfficeCool.classList.remove("active", "dynamic-color");
// }
};
hueRange.addEventListener("input", updateFanColorAndState);
saturationRange.addEventListener("input", updateFanColorAndState);
lightnessRange.addEventListener("input", updateFanColorAndState);
alphaRange.addEventListener("input", updateFanColorAndState);
});
hueRange.addEventListener("input", (e) => {
hueValue.textContent = e.target.value;
updateHSLColor();
});
saturationRange.addEventListener("input", (e) => {
saturationValue.textContent = e.target.value;
updateHSLColor();
});
lightnessRange.addEventListener("input", (e) => {
lightnessValue.textContent = e.target.value;
updateHSLColor();
});
alphaRange.addEventListener("input", (e) => {
alphaValue.textContent = e.target.value;
updateHSLColor();
});
document.getElementById("exportHSLModifierBtn").addEventListener("click", () => {
const hslColor = `hsla(${hueRange.value}, ${saturationRange.value}%, ${lightnessRange.value}%, ${alphaRange.value})`;
copyMessageHSL.textContent = `${hslColor} copied to clipboard!`;
copyMessageHSL.classList.add("show-message");
copyToClipboard(hslColor);
setTimeout(() => {
copyMessageHSL.classList.remove("show-message");
}, 2000);
});
function copyToClipboard(text) {
const tempTextarea = document.createElement("textarea");
tempTextarea.value = text;
document.body.appendChild(tempTextarea);
tempTextarea.select();
document.execCommand("copy");
document.body.removeChild(tempTextarea);
}
const updateHSLColor = () => {
const hslColor = `hsla(${hueRange.value}, ${saturationRange.value}%, ${lightnessRange.value}%, ${alphaRange.value})`;
modifierColorDisplay.style.backgroundColor = hslColor;
document.getElementById("exportHSLModifierBtn").textContent = `Copy ${hslColor} to clipboard`;
};
document.addEventListener("DOMContentLoaded", () => {
const hueRange = document.getElementById("hueRange");
const saturationRange = document.getElementById("saturationRange");
const lightnessRange = document.getElementById("lightnessRange");
const alphaRange = document.getElementById("alphaRange");
const hueValue = document.getElementById("hueValue");
const saturationValue = document.getElementById("saturationValue");
const lightnessValue = document.getElementById("lightnessValue");
const alphaValue = document.getElementById("alphaValue");
const icon1 = document.getElementById("icon_1");
const icon2 = document.getElementById("icon_2");
const icon3 = document.getElementById("icon_3");
const icon4 = document.getElementById("icon_4");
const icon5 = document.getElementById("icon_5");
const icon6 = document.getElementById("icon_6");
const fanOfficeCoolStatus = document.getElementById("acOfficeCoolStatus");
const updateFanColorAndState = () => {
const hslColor = `hsla(${hueRange.value}, ${saturationRange.value}%, ${lightnessRange.value}%, ${alphaRange.value})`;
icon1.style.color = hslColor;
icon2.style.color = hslColor;
icon3.style.color = hslColor;
icon4.style.color = hslColor;
icon5.style.color = hslColor;
icon6.style.color = hslColor;
if (fanOfficeCoolStatus.textContent === "On") {
icon1.classList.add("active");
} else {
icon1.classList.remove("active");
}
};
hueRange.value = 180;
saturationRange.value = 50;
lightnessRange.value = 50;
alphaRange.value = 1;
hueValue.textContent = hueRange.value;
saturationValue.textContent = saturationRange.value;
lightnessValue.textContent = lightnessRange.value;
alphaValue.textContent = alphaRange.value;
updateFanColorAndState();
hueRange.addEventListener("input", (e) => {
hueValue.textContent = e.target.value;
updateFanColorAndState();
});
saturationRange.addEventListener("input", (e) => {
saturationValue.textContent = e.target.value;
updateFanColorAndState();
});
lightnessRange.addEventListener("input", (e) => {
lightnessValue.textContent = e.target.value;
updateFanColorAndState();
});
alphaRange.addEventListener("input", (e) => {
alphaValue.textContent = e.target.value;
updateFanColorAndState();
});
function copyToClipboard(text) {
const tempTextarea = document.createElement("textarea");
tempTextarea.value = text;
document.body.appendChild(tempTextarea);
tempTextarea.select();
document.execCommand("copy");
document.body.removeChild(tempTextarea);
}
const copyMessageHSL = document.getElementById("copyMessageHSL");
document.getElementById("exportHSLModifierBtn").addEventListener("click", () => {
const hslColor = `hsla(${hueRange.value}, ${saturationRange.value}%, ${lightnessRange.value}%, ${alphaRange.value})`;
copyMessageHSL.textContent = `${hslColor} copied to clipboard!`;
copyMessageHSL.classList.add("show-message");
copyToClipboard(hslColor);
setTimeout(() => {
copyMessageHSL.classList.remove("show-message");
}, 2000);
});
});