|
73 | 73 | createColor();
|
74 | 74 | });
|
75 | 75 |
|
76 |
| -const createColor = function() { |
| 76 | +function createColor() { |
77 | 77 | const currentColor = colorPicker.value;
|
78 | 78 | const currentOpacity = opacityPicker.value;
|
79 | 79 | setBackgroundColor( currentColor, currentOpacity );
|
80 | 80 | createHEX( currentColor, currentOpacity );
|
81 | 81 | createRGB( currentColor, currentOpacity );
|
82 | 82 | }
|
83 | 83 |
|
84 |
| -const createHEX = function ( color, opacity ) { |
| 84 | +function createHEX ( color, opacity ) { |
85 | 85 | const cell = document.querySelector( "#HEX td" );
|
86 | 86 | if ( opacity == 1 ) {
|
87 |
| - cell.innerHTML = color; |
| 87 | + cell.textContent = color; |
88 | 88 | } else {
|
89 |
| - cell.innerHTML = color + hexOpacity( opacity ); |
| 89 | + cell.textContent = color + hexOpacity( opacity ); |
90 | 90 | }
|
91 | 91 | }
|
92 | 92 |
|
93 |
| -const createRGB = function ( color, opacity ) { |
| 93 | +function createRGB ( color, opacity ) { |
94 | 94 | const cell = document.querySelector( "#RGB td" );
|
95 | 95 | color = color.substring( 1, 6 );
|
96 |
| - let hexArray = color.match( /.{1,2}/g ); |
97 |
| - let R = parseInt( hexArray[0], 16 ), |
98 |
| - G = parseInt( hexArray[1], 16 ), |
99 |
| - B = parseInt( hexArray[2], 16 ); |
| 96 | + const hexArray = color.match( /.{1,2}/g ); |
| 97 | + const R = parseInt( hexArray[0], 16 ); |
| 98 | + const G = parseInt( hexArray[1], 16 ); |
| 99 | + const B = parseInt( hexArray[2], 16 ); |
100 | 100 |
|
101 | 101 | if( opacity == 1 ) {
|
102 |
| - cell.innerHTML = `rgb(${R} ${G} ${B})`; |
| 102 | + cell.textContent = `rgb(${R} ${G} ${B})`; |
103 | 103 | } else {
|
104 |
| - cell.innerHTML = `rgb(${R} ${G} ${B} / ${opacity})`; |
| 104 | + cell.textContent = `rgb(${R} ${G} ${B} / ${opacity})`; |
105 | 105 | }
|
106 | 106 | createHSL( R, G, B, opacity );
|
107 | 107 | }
|
108 | 108 |
|
109 |
| -const createHSL = function ( r, g, b, opacity ) { |
| 109 | +function createHSL ( r, g, b, opacity ) { |
110 | 110 | const cell = document.querySelector( "#HSL td" );
|
111 | 111 | r = r / 255,
|
112 | 112 | g = g / 255,
|
|
138 | 138 | l = +( l * 100 ).toFixed( 1 );
|
139 | 139 |
|
140 | 140 | if( opacity == 1 ) {
|
141 |
| - cell.innerHTML = `hsl(${h} ${s}% ${l}%)`; |
| 141 | + cell.textContent = `hsl(${h} ${s}% ${l}%)`; |
142 | 142 | } else {
|
143 |
| - cell.innerHTML = `hsl(${h} ${s}% ${l}% / ${opacity})` |
| 143 | + cell.textContent = `hsl(${h} ${s}% ${l}% / ${opacity})` |
144 | 144 | }
|
145 | 145 | createHWB( h, s, l, opacity );
|
146 | 146 | }
|
147 | 147 |
|
148 |
| -const createHWB = function ( h, s, l, opacity ) { |
| 148 | +function createHWB ( h, s, l, opacity ) { |
149 | 149 | const cell = document.querySelector( "#HWB td" );
|
150 | 150 | const hsv = s * ( l < 50 ? l : 100 - l ) / 100;
|
151 | 151 | const W = hsv === 0 ? 0 : 2 * hsv / ( l + hsv ) * 100;
|
152 | 152 | const B = l + hsv;
|
153 | 153 | if( opacity == 1 ) {
|
154 |
| - cell.innerHTML = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}%)`; |
| 154 | + cell.textContent = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}%)`; |
155 | 155 | }
|
156 | 156 | else {
|
157 |
| - cell.innerHTML = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}% / ${opacity})`; |
| 157 | + cell.textContent = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}% / ${opacity})`; |
158 | 158 | }
|
159 | 159 | }
|
160 | 160 |
|
161 |
| -const setBackgroundColor = function ( color, opacity ) { |
| 161 | +function setBackgroundColor ( color, opacity ) { |
162 | 162 | const body = document.querySelector( "div" );
|
163 | 163 | if( opacity != 1 ) {
|
164 | 164 | color = color + "" + hexOpacity( opacity );
|
|
168 | 168 | colorPicker.style.accentColor = color;
|
169 | 169 | }
|
170 | 170 |
|
171 |
| -const hexOpacity = function( opacity ) { |
172 |
| - if( opacity > 0 ) { |
| 171 | +function hexOpacity( opacity ) { |
| 172 | + if( opacity > 0 ){ |
173 | 173 | return Math.floor( opacity * 255 ).toString( 16 );
|
174 | 174 | }
|
175 | 175 | else {
|
176 | 176 | return "00";
|
177 | 177 | }
|
178 |
| -} |
| 178 | +} |
179 | 179 | </script>
|
180 | 180 | </body>
|
181 | 181 | </html>
|
0 commit comments