1function t__paintIcons(recid, iconsSelector) {2var rec = document.querySelector('#rec' + recid);3if (!rec) return;45var icons = rec.querySelectorAll(iconsSelector);6if (!icons.length) return;78icons.forEach(function(icon) {9var iconURL = icon.getAttribute('data-original');10if (!iconURL) return;11var iconColor = icon.getAttribute('data-color');12if (!iconColor) return;
var isImg = icon.tagName === 'IMG'; var iconsURLs = [ '/lib__tildaicon__', '/lib/tildaicon/', '/tild6164-3166-4434-b265-613330313930/circle.svg', '/tild3435-3031-4565-b439-323735306565/star.svg', '/tild3836-3733-4133-b431-346465373061/rhomb.svg', '/tild3336-3766-4730-a266-626536316465/cross.svg', '/tild3331-6332-4132-b565-663737653932/rhomb2.svg', '/tild3834-3661-4635-b166-303739306635/arrow.svg', '/tild3163-6165-4531-b437-616562623533/flake.svg', '/tild3435-3465-4165-b231-623435653462/heart.svg', '/lib/icons/', 'images/lib', ]; var isTildaIcon = iconsURLs.some(function(url) { return iconURL.indexOf(url) > -1; }); var isModifiedIcon = iconURL.includes('-/paint/'); if (!isTildaIcon || isModifiedIcon) { if (isImg) { icon.src = iconURL; } else { icon.style.backgroundImage = 'url(' + iconURL + ')'; } return; } var xhr = new XMLHttpRequest(); xhr.open('GET', iconURL); xhr.responseType = 'document'; xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { var response = xhr.response; var svg = response.querySelector('svg'); if (!svg) return; var figureList = svg.querySelectorAll('*:not(g):not(title):not(desc)'); figureList.forEach(function(figure) { figure.style.fill = iconColor; }); let svgString = new XMLSerializer().serializeToString(svg); // Заменям переменные глобальных стилей на их значения const cssVars = svgString.matchAll(/var\((--uc-color-color-[a-zA-Z0-9]+),\s*[a-fA-F0-9#]+\)/g); const bodyStyle = window.getComputedStyle(document.body); for (const match of cssVars) { const varValue = bodyStyle.getPropertyValue(match[1]); if (varValue) svgString = svgString.replace(match[0], varValue); } var svgEncodedURL = 'data:image/svg+xml;base64,' + window.btoa(svgString); if (isImg) { icon.src = svgEncodedURL; } else { icon.style.backgroundImage = 'url(' + svgEncodedURL + ')'; } icon.removeAttribute('data-original'); icon.removeAttribute('data-color'); } else if (xhr.readyState === XMLHttpRequest.DONE) { if (isImg) { icon.src = iconURL; } else { icon.style.backgroundImage = 'url(' + iconURL + ')'; } } }; xhr.send(); });}