console.log("APPROVE SCRIPT LOADED"); var price_wrapper = document.querySelector(".js-product-price-number"); var model_ele = document.querySelector(".product-single__title-text"); var add_to_cart_btn = document.querySelector('.product-form__add-btn'); console.log('hello!!!!'); function init_button(){ var price_ele = price_wrapper.querySelector(".product-single__price-number").querySelector(".money"); if (!price_ele){ return; } if (!model_ele){ return; } var price = price_ele.innerHTML; price = price.replace(/[^0-9-.]/g, ''); var model = model_ele.innerHTML; var selected_options = document.querySelectorAll('.product-form__variant'); selected_options.forEach(function (item, index) { var option_ele = item.querySelector(".selector-wrapper").querySelector('select'); var option_name = option_ele.value; model = model + " / " + option_name; }); if(isNaN(price)){ return; } if(!model){ return; } if(!add_to_cart_btn){ return; } if ((parseFloat(price)) < 200){ document.getElementById('approve_button_id').style.display = "none"; return; } var approve_button = document.getElementById('approve_button_id'); if (!approve_button){ var new_button = document.createElement('approve-button'); new_button.id = "approve_button_id"; new_button.style.display="inline-block"; new_button.style.width="100%"; new_button.style.margin="24px 0px 0px"; new_button.style.textAlign="center"; new_button.setAttribute('application-type',"embedded_app"); add_to_cart_btn.after(new_button); } document.getElementById('approve_button_id').setAttribute('price',price); document.getElementById('approve_button_id').setAttribute('model',model); document.getElementById('approve_button_id').setAttribute('qty',1); document.getElementById('approve_button_id').setAttribute('type',"new_product"); } init_button(); //Get Product Options const observer = new MutationObserver(function() { init_button(); }); observer.observe(price_wrapper,{subtree: false, childList: true});