function init_button(){ var price = document.querySelector('.price--withoutTax').innerHTML; var price = price.replace(/^.*\$/,''); price = price.replace(/,/,''); var model = document.querySelector('.productView-title').innerHTML; var qty = document.querySelector('.form-input--incrementTotal').value; if(isNaN(price)) return; if(!model) return; var new_button = document.createElement('approve-button'); new_button.id = "approve_button_id"; new_button.style.display="inline-block"; new_button.style.margin="15px 0px"; new_button.style.width="208%" new_button.setAttribute('application-type',"embedded_app"); var add_to_cart_element = document.querySelector('#form-action-addToCart'); add_to_cart_element.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',qty); document.getElementById('approve_button_id').setAttribute('type',"new_product"); } function update_button(){ var price = document.querySelector('.price--withoutTax').innerHTML; var price = price.replace(/^.*\$/,''); price = price.replace(/,/,''); var model = document.querySelector('.productView-title').innerHTML; var qty = document.querySelector('.form-input--incrementTotal').value; if(isNaN(price)) return; if(!model) return; document.getElementById('approve_button_id').setAttribute('price',price); document.getElementById('approve_button_id').setAttribute('model',model); document.getElementById('approve_button_id').setAttribute('qty',qty); document.getElementById('approve_button_id').setAttribute('type',"new_product"); } init_button(); var product_container = document.querySelector('.productView-details'); const observer2 = new MutationObserver(function() { var qty_ele = product_container.querySelector('.form-input--incrementTotal'); qty_ele.addEventListener('change', function (evt) { var qty = qty_ele.value; var btn_qty = document.getElementById('approve_button_id').getAttribute('qty'); if (parseInt(qty) != parseInt(btn_qty)){ document.getElementById('approve_button_id').setAttribute('qty',qty); } }); }); observer2.observe(product_container,{subtree: true, childList: true});