Это пример каталога товаров, в нем отображаются товары с опцией "цвет".
Стандартный блок подгружает изображение товара соответствующего цвета. Задача - заменять изображение по умолчанию другим изображением из прописанных в скрипте в зависимости от названия цвета.
Есть вот такой скрипт, он работает не так как ожидалось.

<script>
$( document ).ready(function() {
//Таблица цвета
var colortable = { 'жёлтый':         'https://static.tildacdn.com/tild3539-3532-4663-b235-336131383033/Rectangle_2_3.svg',
                   'зелёный':        'https://static.tildacdn.com/tild3936-3761-4537-b030-636434366664/Rectangle_2_4.svg',
                   'красный':        'https://static.tildacdn.com/tild3139-3166-4137-b831-646462373336/Rectangle_2_5.svg',
                   'синий':          'https://static.tildacdn.com/tild6661-3430-4938-b332-366264333836/Rectangle_2_6.svg',
                   'бирюзовый':      'https://static.tildacdn.com/tild3932-3835-4238-a632-343331666230/Rectangle_2_7.svg',
                   'оранжевый':      'https://static.tildacdn.com/tild3138-6435-4562-b165-376534336438/Rectangle_2_8.svg',
                   'фиолетовый':     'https://static.tildacdn.com/tild3965-3166-4439-b133-363037653032/Rectangle_2_9.svg',
                   'чёрный':         'https://static.tildacdn.com/tild3239-6364-4338-b537-303639663230/Rectangle_2_10.svg',
                   'зелёно-красный': 'https://static.tildacdn.com/tild6430-3463-4566-b766-323731616139/Group_1_4.svg',
                   'розовый':        'https://static.tildacdn.com/tild3830-6339-4834-b835-333366643263/Rectangle_2_11.svg'
                 };
let nameofselect= "Цвет";
let popup=false;
let waymode='';
//Создаём иконки
function makecolorbox(popup){
 $('.js-product-edition-option[data-edition-option-id="'+nameofselect+'"]').addClass('productColor'); 
       $('.t-store__product-snippet .js-product-edition-option[data-edition-option-id="'+nameofselect+'"]').addClass('productColor'); 
       if(popup){waymode = '.t-store__prod-popup__container .productColor'
       }else{ waymode = '.productColor' };
       $(waymode).append('<div class="stcolorbox"></div>');
       $(waymode).each(function(index) {
          let colorsize =  $(this).find('select option').size();
          for (let i = 0; i < colorsize ; i++) {
               let colorval = $(this).find('select option:eq('+i+')').val();
               $(this).find('.stcolorbox').append('<div class="coloritem" style="background-image:url('+colortable[colorval]+') "></div>');
          };
       });
};
//При загрузке
let tistore = setInterval(function() {
    if (document.querySelector('.js-product-controls-wrapper .stcolorbox')){
        clearInterval(tistore) }else{  makecolorbox()
    }
}, 300);
//При открытии окна
$(document).on('click',' .t-store__card a[href*="/tproduct/"] ',function(e){ setTimeout(function(){makecolorbox(popup=true)}, 200) });
//Клик по иконке цвета
$(document).on('click','.coloritem',function(e){
$(this).parent().find('.coloritem').removeClass('coloritemactive').addClass('clearactive');
$(this).addClass('coloritemactive');
let colorpos = $(this).index()+1;
$(this).closest('.js-product-edition-option').find('select :nth-child('+colorpos+')').prop('selected', true);
$(this).closest('.js-product-edition-option').find('select').change();  
});
//При изменении select
$(document).on('change','.productColor select',function(e){ 
    let colorsel = $(this)[0].selectedIndex;
    $(this).closest('.js-product-edition-option').find('.stcolorbox .coloritem').removeClass('coloritemactive').addClass('clearactive');
    $(this).closest('.js-product-edition-option').find('.stcolorbox .coloritem:eq('+colorsel+')').addClass('coloritemactive');
});

function filtrload(){
   setTimeout(function(){ 
   let tigrid = setInterval(function() {
      if (document.querySelector('.js-store-grid-cont .stcolorbox')){
          clearInterval(tigrid)
      }else{ makecolorbox()};
   }, 100);
}, 500);  
};
$(document).on('click','.js-store-filter , .js-store-filter-chosen-item , .js-store-load-more-btn , .js-store-parts-switcher',function(e){ 
   filtrload();
});
$(document).on('keydown','.t-store__filter__input',function(event){if(event.keyCode == 13) {
   filtrload();
 };
}); 
});
</script>
Ниже - стили с которыми не должен конфликтовать скрипт
<style>
/*прячем артикул и описание товара*/
    /*артикул*/
    div.t-store__card__sku.t-descr.t-descr_xxs
    {
        /*display: none !important;*/
    }
    /*описание*/
    div.js-store-prod-descr.t-store__card__descr.t-typography__descr.t-descr.t-descr_xxs
    {
        display: none !important;
    }
    /*слово Цвет*/
    div.js-product-edition-option-name.t-product__option-title.t-typography__options.t-descr.t-descr_xxs
    {
        /*
        display: none !important;
        */
    }
    
</style>
<style>
    /*прячем иконки*/
    form.t-product__option-variants.t-product__option-variants_custom.t-product__option-variants_buttons.t-product__option-variants_image
    {
        display: nones !important;
        
    }
    
    .js-product-edition-option[data-edition-option-id="Размер"]
    {
        display: none !important;
    }
    
    /*нормально работающий стиль кружков с миниатюрами вариантов товаров*/
    .t-product__option-checkmark.t-bgimg.t-product__option-checkmark_buttons.t-product__option-checkmark_image.loaded
    {
    cursor: pointer;
    background-size: cover !important;
    width: 25px !important;
    height: 25px !important;
    margin-right: 10px !important;
    margin-bottom: 10px !important;
    border-radius: 25px !important;
    background-color: #fff !important;
    transition: all 0.3s ease-in-out !important
    }
    
    .js-product .t-product__option-variants_buttons .t-product__option-input:checked+ .t-product__option-checkmark_image:before
    {
        border-radius: 25px
    }
    
    .t-product__option-checkmark.t-bgimg.t-product__option-checkmark_buttons.t-product__option-checkmark_image.loaded
    {
        border: 1px solid red !important
    }
    
</style>