Hi @aviel222 aren't you learning scripting? You should try to do these changes yourself and see how you go, You might surprise yourself with what you can achieve!
Anyway, here is a modified script. I hope you can learn from it.
/**
* Replaces colors of items in document.
* Currently configured to:
* (a) not change [C=100 M=0 Y=0 K=0] or [C=0 M=100 Y=0 K=0] (including in spot color)
* (b) change 10% black or lighter to white
* (c) change anyhting else to 100% black
* @discussion https://community.adobe.com/t5/illustrator-discussions/make-100-black-in-document/m-p/13482548
* Note: you can customise which colors are excluded by editing the `changeColor` function or making your own replacer function.
*/
(function () {
if (!confirm('Do you want to replace colors?'))
return;
var doc = app.activeDocument,
items = doc.pageItems,
white = makeWhite(),
black = makeBlack();
for (var i = 0; i < items.length; i++)
replaceColors(items[i], changeColor);
/**
* Returns a color based on the given color.
* A `replacer` function for replaceColors.
* @param {Color} c - the input color.
* @returns {Color} - the output color
*/
function changeColor(startColor) {
var c = startColor;
if (c.typename == 'SpotColor')
c = c.spot.color;
if (
(
c.typename == 'GrayColor'
&& c.gray <= 10
)
|| (
c.typename == 'CMYKColor'
&& c.cyan == 0
&& c.magenta == 0
&& c.yellow == 0
&& c.black <= 10
)
)
return white;
else if (
(
c.typename == 'CMYKColor'
&& c.cyan == 100
&& c.magenta == 0
&& c.yellow == 0
&& c.black == 0
)
|| (
c.typename == 'CMYKColor'
&& c.cyan == 0
&& c.magenta == 100
&& c.yellow == 0
&& c.black == 0
)
)
return c;
else
return black;
};
/**
* Replace `item`s basic colors with
* a supplied `replacementColor` but only
* if `filterFunction` returns true;
* @author m1b
* @version 2023-01-12
* @param {PageItem} item - the item to replace colors of.
* @param {Function} replacer - function that returns a replacement color.
*/
function replaceColors(item, replacer) {
if (item == undefined)
throw Error('replaceColors: No item supplied.');
var noColor = "[NoColor]",
colorables = [];
// collect all the colorables
if (item.constructor.name == 'PathItem') {
colorables.push(item);
}
else if (
item.constructor.name == 'CompoundPathItem'
&& item.pathItems
) {
colorables.push(item.pathItems[0]);
}
else if (
item.constructor.name == 'TextFrame'
&& item.textRanges
) {
for (var i = item.textRanges.length - 1; i >= 0; i--)
colorables.push({
fillColor: item.textRanges[i].characterAttributes.fillColor,
strokeColor: item.textRanges[i].characterAttributes.strokeColor
});
}
if (colorables.length > 0)
for (var i = 0; i < colorables.length; i++) {
if (
colorables[i].hasOwnProperty('fillColor')
&& colorables[i].fillColor != noColor
&& (
!colorables[i].hasOwnProperty('filled')
|| colorables[i].filled == true
)
&& colorables[i].fillColor != undefined
)
colorables[i].fillColor = replacer(colorables[i].fillColor);
if (
colorables[i].hasOwnProperty('strokeColor')
&& colorables[i].strokeColor != noColor
&& (
colorables[i].constructor.name == 'CharacterAttributes'
|| colorables[i].stroked == true
)
&& colorables[i].strokeColor != undefined
)
colorables[i].strokeColor = replacer(colorables[i].strokeColor);
}
else if (item.constructor.name == 'GroupItem') {
for (var i = 0; i < item.pageItems.length; i++)
replaceColors(item.pageItems[i], replacer);
}
};
/**
* Returns a black color.
* @returns {CMYKColor}
*/
function makeBlack() {
var c = new CMYKColor();
c.cyan = 0;
c.magenta = 0;
c.yellow = 0;
c.black = 100;
return c;
};
/**
* Returns a white color.
* @returns {CMYKColor}
*/
function makeWhite() {
var c = new CMYKColor();
c.cyan = 0;
c.magenta = 0;
c.yellow = 0;
c.black = 0;
return c;
};
})();
Edit: replacer now handles SpotColor.