Another replacement for the experimental "Replace Color" option. When trying to create an iconset using the sourcefiles from the icon collections I provided, it will not work for all files because many of them doesn't contain any color information which could be replaced. These icons will stay black. The following code not only replaces existing color attributes but also adds this information if not existent. It works with all icon collections I provided but possibly not with others.
regex = /(<path|<rect|<circle|<ellipse|<polygon)([\S|\s]*?)(\sstyle="")?([\S|\s]*?)(\n?\/>)/gi;
var matches = [];
var m;
while ((m = regex.exec(content)) !== null) {
matches.push(m[0]);
}
for (var j = 0; j < matches.length; j++) {
var Match = matches[j];
if (Match.indexOf('\\sstyle="') !== -1 && Match.indexOf('fill:none;') === -1) {
var Match1 = Match.replace(/(<path|<rect|<circle|<ellipse|<polygon)([\S|\s]*?)(\sstyle="")?([\S|\s]*?)(\n?\/>)/i,
'$1$2$3fill:currentColor;$4$5');
content = content.split(Match).join(Match1);
}
if (Match.indexOf('fill="none"') === -1 && Match.indexOf('black') === -1 &&
Match.indexOf('fill:none') === -1 && Match.indexOf('style="') === -1) {
var Match2 = Match.replace(/(<path|<rect|<circle|<ellipse|<polygon)([\S|\s]*?)(\sstyle="")?([\S|\s]*?)(\n?\/>)/i,
'$1 style="fill:currentColor"$2$4$5');
content = content.split(Match).join(Match2);
}
}
The code comes from a VBScript "Create white SVG-Files" button I provided with my old Iconset Creator (CreateIconset (Incl. Dark/Light Sets for DOpus13)). I converted the code to JScript using AI.