2
2
ColorCorrector.jsx for Adobe Illustrator
3
3
Description: Adjust color channels for selected objects by setting exact values or calculating relative changes
4
4
Date: June, 2024
5
+ Modification Date: February, 2025
5
6
Author: Sergey Osokin, email: [email protected]
6
7
7
8
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
8
9
9
10
Release notes:
11
+ 0.1.2 Fixed adjustment of gradient duplicates in selection
12
+ 0.1.1 Fixed typo for correct work with gradients
10
13
0.1 Initial version
11
14
12
15
Donate (optional):
@@ -33,7 +36,7 @@ app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix dr
33
36
function main ( ) {
34
37
var SCRIPT = {
35
38
name : 'Color Corrector' ,
36
- version : 'v0.1'
39
+ version : 'v0.1.2 '
37
40
} ;
38
41
39
42
var CFG = {
@@ -201,10 +204,16 @@ function main() {
201
204
win . close ( ) ;
202
205
}
203
206
207
+ /**
208
+ * Starts the color adjustment process for selected items
209
+ * It applies color modifications based on user-defined values,
210
+ * skipping duplicate gradient names
211
+ */
204
212
function start ( ) {
205
213
// Fix preview
206
214
tmpPaths . push ( selection [ 0 ] . layer . pathItems . add ( ) ) ;
207
215
216
+ // Set default text values based on color mode
208
217
if ( isRgb ) {
209
218
setDefaultText ( r , 'R' ) ;
210
219
setDefaultText ( g , 'G' ) ;
@@ -217,11 +226,28 @@ function main() {
217
226
}
218
227
219
228
var values = isRgb ? [ r . text , g . text , b . text ] : [ c . text , m . text , y . text , k . text ] ;
229
+ var props = [ 'fillColor' , 'strokeColor' ] ;
230
+ var appear = [ isFill , isStroke ] ; // Appearance checkboxes
231
+ var uniqueGradients = { } ; // Store gradients to avoid duplicate adjustments
220
232
221
233
for ( var i = 0 , len = items . length ; i < len ; i ++ ) {
234
+ // If the item is Text Frame, use its textRange, otherwise use the item itself
222
235
var item = / t e x t / i. test ( items [ i ] . typename ) ? items [ i ] . textRange : items [ i ] ;
223
- if ( isFill . value ) adjustColors ( item , 'fillColor' , values , channels , isEditGlobal . value , isRgb ) ;
224
- if ( isStroke . value ) adjustColors ( item , 'strokeColor' , values , channels , isEditGlobal . value , isRgb ) ;
236
+
237
+ for ( var j = 0 ; j < 2 ; j ++ ) {
238
+ // Skip processing if the corresponding checkbox is not enabled
239
+ if ( ! appear [ j ] . value ) continue ;
240
+
241
+ var color = item [ props [ j ] ] ;
242
+
243
+ if ( / g r a d i e n t / i. test ( color ) ) {
244
+ var gradName = color . gradient . name . replace ( / \s / g, '_' ) ;
245
+ if ( uniqueGradients [ gradName ] ) continue ; // Skip if already handled
246
+ uniqueGradients [ gradName ] = true ; // Mark as processed
247
+ }
248
+
249
+ adjustColors ( item , props [ j ] , values , channels , isEditGlobal . value , isRgb ) ;
250
+ }
225
251
}
226
252
}
227
253
@@ -383,7 +409,7 @@ function adjustColors(item, type, values, channels, isGlobal, isRgb) {
383
409
if ( / g r a d i e n t / i. test ( item [ type ] ) ) {
384
410
for ( var i = 0 ; i < item [ type ] . gradient . gradientStops . length ; i ++ ) {
385
411
var gradStop = item [ type ] . gradient . gradientStops [ i ] ;
386
- adjustColors ( gradStop , 'color' , values , channels , isRgb ) ;
412
+ adjustColors ( gradStop , 'color' , values , channels , isGlobal , isRgb ) ;
387
413
}
388
414
} else {
389
415
for ( var j = 0 ; j < channels . length ; j ++ ) {
0 commit comments