(function () { //DDP var take = async function () { console.log("DISKY - DDP") const BASE_URL = "https://pr.aqur.com"; const fetchOptions = { method: "POST", headers: { "Content-Type": "application/json" } }; const chatform = localStorage.getItem("chatform"); if (chatform) { if (/\/prorder_rf\/completeConst.aspx/.test(window.location.pathname)) { async function track(trackingData) { try { await fetch(`${BASE_URL}/track`, { ...fetchOptions, body: trackingData }); localStorage.removeItem("chatform"); let chatformData = JSON.parse(chatform); const response2 = await fetch(`${BASE_URL}/pdi/${chatformData.uuId}`); const data2 = await response2.json(); data2.data.Completed = true; data2.data.status = "Completed"; await fetch(`${BASE_URL}/pdi/set`, { ...fetchOptions, body: JSON.stringify(data2.data) }); } catch (error) { console.error('Error:', error); } } track(chatform); } if(/\/prorder_rf\/formConst.aspx/.test(window.location.pathname)) { errorCheck() } if (/\/prorder_rf\/confirmConst.aspx/.test(window.location.pathname)) { const renderConfirmForm = () => { const formElement = document.getElementById("ctl09"); if (formElement) { // action属性を変更 formElement.action = "https://www.riceforce.com/prorder_rf/confirmConst.aspx"; // フォーム内の全ての input 要素を取得 const inputs = formElement.querySelectorAll("input[disabled]"); // disabled 属性を削除 inputs.forEach(input => input.removeAttribute("disabled")); // HTMLのテキスト形式で取得 const modifiedHtmlText = formElement.outerHTML; let param = { event: "renderConfirm", html: modifiedHtmlText } window.parent.postMessage(param, '*') } else { console.log("フォームが見つかりませんでした。"); } } setTimeout(renderConfirmForm, 2000) } } function errorCheck() { var errorCheckInterval = setInterval(function () { const errorMessage1 = document.querySelector('.lp_error'); const errorMessage2 = document.querySelector('.errorText'); if (errorMessage1 || errorMessage2) { console.log("errorMessage1", errorMessage1); console.log("errorMessage2", errorMessage2); clearInterval(errorCheckInterval); const errorText = (errorMessage1?.textContent || errorMessage2?.textContent || "").trim(); var param = { event: "chatform_bindFormErrorFound", text: errorText, }; window.parent.postMessage(param, '*'); history.back(); setTimeout(() => { window.parent.postMessage({ event: "tryReset" }, "*"); }, 2000); } }, 3000); } // setTimeout(() => { if (!window.aqur) { window.aqur = {}; } window.aqur.fillInput = (selector, value) => { const inputElement = document.querySelector(selector); if (inputElement) { inputElement.value = value; var event = new Event('input', { bubbles: true, cancelable: true }); var changeEvent = new Event('change', { bubbles: true, cancelable: true }); inputElement.dispatchEvent(event); inputElement.dispatchEvent(changeEvent); inputElement.scrollIntoView(); } }; window.aqur.fillInputKeyBoard = async (selector, value, delay = 100) => { const inputElement = document.querySelector(selector); if (!inputElement) return; inputElement.focus(); inputElement.scrollIntoView({ behavior: 'smooth', block: 'center' }); const triggerEvent = (el, type, options = {}) => { const event = new Event(type, { bubbles: true, cancelable: true, ...options, }); el.dispatchEvent(event); }; // Trigger focus events triggerEvent(inputElement, 'focus'); // triggerEvent(inputElement, 'focusin'); // Clear existing value inputElement.value = ''; for (let i = 0; i < value.length; i++) { const char = value[i]; // Simulate key events const keyCode = char.charCodeAt(0); inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: char, char, keyCode, which: keyCode, bubbles: true, })); inputElement.dispatchEvent(new KeyboardEvent('keypress', { key: char, char, keyCode, which: keyCode, bubbles: true, })); inputElement.value += char; inputElement.dispatchEvent(new InputEvent('input', { data: char, inputType: 'insertText', bubbles: true, })); inputElement.dispatchEvent(new KeyboardEvent('keyup', { key: char, char, keyCode, which: keyCode, bubbles: true, })); await new Promise(resolve => setTimeout(resolve, delay)); } // Trigger change and blur events triggerEvent(inputElement, 'change'); triggerEvent(inputElement, 'blur'); }; window.aqur.chooseRadioButton = (radioSelector, value) => { const radioButton = document.querySelector(`${radioSelector}[value='${value}']`); if (radioButton) { radioButton.checked = true; let event = new Event('change', { bubbles: true, composed: true }) radioButton.dispatchEvent(event); } }; window.aqur.chooseSelectBox = (selectBoxSelector, value, useOptionVal = true) => { let option = "" if (useOptionVal) { option = document.querySelector(`${selectBoxSelector} option[value='${value}']`); } else { option = document.querySelector(`${selectBoxSelector} option[label='${value}']`); } const selectElement = document.querySelector(`${selectBoxSelector}`); if (option && selectElement) { option.selected = true; const event = new Event('change', { bubbles: true, composed: true }) selectElement.dispatchEvent(event); } }; window.aqur.chooseSelectBoxLabel = (selectBoxSelector, label) => { const selectElement = document.querySelector(selectBoxSelector); var option; if (selectElement) { option = Array.from(selectElement.options).find( opt => opt.textContent.trim() === label ); } if (option) { option.selected = true; const event = new Event('change', { bubbles: true, composed: true }); selectElement.dispatchEvent(event); } }; window.aqur.findValue = (d,n) => { let value=""; rtn = value; for(var i=0; i < d.length; i++){ var item = d[i]; if(item.values){ item.values.forEach(function(v) { if(v.name==n){ rtn = v.value } }) } } return rtn } // }, 1000); window.addEventListener("message", (event) => { //console.log("window message") //aqurBindidng if (event.data.event == "setGender") { window.aqur.chooseRadioButton('input[name="ctl00$Gender"]', event.data.value) } if (event.data.event == "setYear") { window.aqur.chooseSelectBox('select[name="ctl00$BirthYear"]', event.data.value) } if (event.data.event == "setMonth") { window.aqur.chooseSelectBox('select[name="ctl00$BirthMonth"]', event.data.value) } if (event.data.event == "setDay") { window.aqur.chooseSelectBox('select[name="ctl00$BirthDate"]', event.data.value) } if (event.data.event == "setLastName") { window.aqur.fillInput('input[name="ctl00$LastName"]', event.data.value) } if (event.data.event == "setFirstName") { window.aqur.fillInput('input[name="ctl00$FirstName"]', event.data.value) } if (event.data.event == "setLastNameKana") { window.aqur.fillInput('input[name="ctl00$LastKanaName"]', event.data.value) } if (event.data.event == "setFirstNameKana") { window.aqur.fillInput('input[name="ctl00$FirstKanaName"]', event.data.value) } if (event.data.event == "setPostalCode") { window.aqur.fillInput('input[name="ctl00$Zip"]', event.data.value) } if (event.data.event == "setPref") { window.aqur.chooseSelectBoxLabel('select[name="ctl00$PrefCD"]', event.data.value) } if (event.data.event == "setCity") { window.aqur.fillInput('input[name="ctl00$Address1"]', event.data.value) } if (event.data.event == "setBuilding") { // window.aqur.fillInput2('input[name="ctl00$Address2"]', event.data.value) } if (event.data.event == "setTel") { var value = event.data.value.replaceAll(/-/g, ''); window.aqur.fillInput('input[name="ctl00$Tel1"]', value) } if (event.data.event == "setEmail") { window.aqur.fillInput('input[name="ctl00$MailAddress1"]', event.data.value) } if(event.data.event == "setNewsletterSendable") { if(event.data.value) { window.aqur.chooseRadioButton('input[name="ctl00$MailMagazine1"]', "1") } else { window.aqur.chooseRadioButton('input[name="ctl00$MailMagazine1"]', "0") } } if(event.data.event == "setPayment") { window.aqur.chooseRadioButton('input[name="ctl00$PaymentKB"]', event.data.value) } if(event.data.event == "setCardNumber"){ window.aqur.fillInput('input[name="ctl00$cardNumber"]', event.data.value) } if(event.data.event == "setCardExpirationYear"){ window.aqur.chooseSelectBoxLabel('select[name="ctl00$cardExpirationYear"]', event.data.value) } if(event.data.event == "setCardExpirationMonth"){ window.aqur.chooseSelectBoxLabel('select[name="ctl00$cardExpirationMonth"]', event.data.value) } if(event.data.event == "setCardCvc"){ window.aqur.fillInput('input[name="ctl00$CardSecurityCode"]', event.data.value) } //購入確定ボタン押下 if (event.data.event == "chatform_bindFormSubmit") { const submit = () => { window.aqur.fillInputKeyBoard('input[name="ctl00$Address2"]', window.aqur.findValue(event.data.project?.data, "Street") + "" + window.aqur.findValue(event.data.project?.data, "Building")) const agree = document.querySelector('#chkConfirmed') if(!agree.checked) { agree.click() } const sendButton = document.querySelector('input[name="ctl00$FormAssist_submit"]'); if (sendButton !== null) { sendButton.click(); } else { console.error('Element with ID ".__send" not found.'); } errorCheck() } setTimeout(submit, 2000) } }) } setTimeout(take, 0); }())