(function() { // アンカーからuuIdを取得 function getUuIdFromAnchor() { const queryString = window.location.search; const params = new URLSearchParams(queryString); // アンカーが#で始まっている場合はそれを取り除く return params.get("uuId"); } // uuIdの値を取得 const uuId = getUuIdFromAnchor(); var take = function () { console.log("This DDP", window.location.href) var path = window.location.pathname; if (path.includes('/donate/form_gd/')) { let formPage = document.querySelector('#customer_kbn_private') if(formPage) { console.log("FORM PAGE => ", uuId) // uuIdが取得できた場合にfetchリクエストを実行 if (uuId) { const fetchUrl = `https://pr.aqur.com/pdi/${uuId}`; fetch(fetchUrl) .then(response => response.json()) .then(async data => { let encData = await encryptData(JSON.stringify(data.data), 'jar@qur') localStorage.setItem('encData', JSON.stringify(encData)) bindForm(data.data) }) .catch(error => { console.error('Error fetching the URL:', error); }); } else { console.error('uuId is not found in the URL'); } } // the client request to remove auto clicking confirm from code // let confirmSubmitElem = document.querySelector('#js-kifu-submit2') // if(confirmSubmitElem) { // console.log("CONFIRM PAGE") // let chatform = localStorage.getItem('chatform') // if(chatform) { // const submitConfirm = ()=>{ // confirmSubmitElem.click() // }; // //setTimeout(submitConfirm, 1500); // } // } let thankPageElem = document.querySelector('p.p-thanks__ttl') if(thankPageElem) { let chatform = localStorage.getItem('chatform') if(chatform) { console.log("THANK PAGE") var url = "https://pr.aqur.com/track"; function track(trackingData) { fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: trackingData }) .then(response => response.json()) .then(data => { console.log("Conversion Tracked!!") let tmpTrackData = JSON.parse(trackingData) tmpTrackData.Completed = true var param = { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify(tmpTrackData) }; const url = "https://pr.aqur.com/pdi/set"; fetch(url, param) .then(response => response.json()) .then(data => { console.log('Update PDI succes') }).catch(error => { console.log("fail"); }); localStorage.removeItem("chatform") localStorage.removeItem("encData") }) } let userData = localStorage.getItem('encData') decryptData(JSON.parse(userData), 'jar@qur').then(decrypted => { track(decrypted) }); } } } } setTimeout(take, 2000) // document.addEventListener("DOMContentLoaded", () => { // setTimeout(take, 0); // }) const fillInput = (selector, value) => { return new Promise((resolve, reject) => { let inputEvent = new InputEvent('change', { bubbles: true, cancelable: false }); const inputElement = document.querySelector(selector); if (inputElement) { inputElement.value = value; inputElement.dispatchEvent(inputEvent); resolve(`Input with name "${selector}" filled and event dispatched`); } else { reject(`Element with name "${selector}" not found.`); } }); }; const chooseSelectBox = (selectBoxSelector, value, useOptionVal = true) => { return new Promise((resolve, reject) => { 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); resolve(`Select box with name '${selectBoxSelector}' set to option value '${value}' and event dispatched.`); } else { reject(new Error(`Select box with name '${selectBoxSelector}' and option value '${value}' not found.`)); } }); }; function AllEventClick(inputElm) { const events = ['mousedown', 'mouseup', 'click']; events.forEach(eventType => { const event = new MouseEvent(eventType, { view: window, bubbles: true, cancelable: true }); inputElm.dispatchEvent(event); }); } async function bindForm(serverData){ //console.log("bindForm", serverData) let d = serverData.data var chatform = { pid:serverData.pid, sid:serverData.sid, uuId:serverData.uuId, id:serverData.id } localStorage.setItem('chatform', JSON.stringify(chatform)); await new Promise(resolve => setTimeout(resolve, 1000)) let amount = d.DonatePrice if(/1500/.test(amount)) { let firstAmount = document.querySelector('#amount_1') AllEventClick(firstAmount) } else if(/3000/.test(amount)){ let secondAmount = document.querySelector('#amount_2') AllEventClick(secondAmount) } else if(/5000/.test(amount)) { let thirdAmount = document.querySelector('#amount_3') AllEventClick(thirdAmount) } else if(/free/.test(amount)){ let freeElem = document.querySelector('#amount_4') AllEventClick(freeElem) await new Promise(resolve => setTimeout(resolve, 500)) await fillInput('#amount_5', d.OtherAmount) } let Group = d.Group if(/private/.test(Group)) { // 個人 let inidvElem = document.querySelector('#customer_kbn_private') AllEventClick(inidvElem) } else { // 法人 let gpElem = document.querySelector('#customer_kbn_corporate') AllEventClick(gpElem) await fillInput('#companyName', d.CorporateName) } await fillInput('#familyName', d.LastName) await fillInput('#givenName', d.FirstName) await fillInput('#kanaFamilyName', d.LastNameKana) await fillInput('#kanaGivenName', d.FirstNameKana) await fillInput('#phone', d.Tel) if(d.Email) { await fillInput('#email', d.Email) } if(d.LivingOversea == "overseas") { await chooseSelectBox('select#pref', '海外') await fillInput('#city', d.OverSeaCity) await fillInput('#address1', d.OverSeaBuilding) } else { await fillInput('#postalCode', d.Zip) await chooseSelectBox('select#pref', d.Prefecture) await fillInput('#city', d.City) await fillInput('#address1', d.Street1 + d.Street2) } await scrollToSelector(['#cardNumber']) // await fillInput('#cardNumber', d.ccNumber) // await fillInput('#cardExpMonth', d.ccExpMonth > 9 ? d.ccExpMonth : "0" + d.ccExpMonth) // await fillInput('#cardExpYear', d.ccExpYear.slice(2)) // await fillInput('#cardCVV', d.ccCvc) // await fillInput('#cardNameGiven', d.ccName.split(" ")[0]) // await fillInput('#cardNameFamily', d.ccName.split(" ")[1]) // const nxtBtn = () => { // let submitElem = document.querySelector('#js-kifu-submit') // AllEventClick(submitElem) // } // setTimeout(nxtBtn, 1500); } async function encryptData(data, password) { const enc = new TextEncoder(); const encodedPassword = enc.encode(password); const key = await crypto.subtle.importKey( "raw", encodedPassword, { name: "PBKDF2" }, false, ["deriveKey"] ); const salt = crypto.getRandomValues(new Uint8Array(16)); const derivedKey = await crypto.subtle.deriveKey( { name: "PBKDF2", salt: salt, iterations: 100000, hash: "SHA-256" }, key, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"] ); const iv = crypto.getRandomValues(new Uint8Array(12)); const encryptedData = await crypto.subtle.encrypt( { name: "AES-GCM", iv: iv }, derivedKey, enc.encode(data) ); return { salt: Array.from(salt), iv: Array.from(iv), data: Array.from(new Uint8Array(encryptedData)) }; } async function decryptData(encrypted, password) { const enc = new TextEncoder(); const encodedPassword = enc.encode(password); const key = await crypto.subtle.importKey( "raw", encodedPassword, { name: "PBKDF2" }, false, ["deriveKey"] ); const salt = new Uint8Array(encrypted.salt); const iv = new Uint8Array(encrypted.iv); const derivedKey = await crypto.subtle.deriveKey( { name: "PBKDF2", salt: salt, iterations: 100000, hash: "SHA-256" }, key, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"] ); const decryptedData = await crypto.subtle.decrypt( { name: "AES-GCM", iv: iv }, derivedKey, new Uint8Array(encrypted.data) ); const dec = new TextDecoder(); return dec.decode(decryptedData); } function scrollToSelector(selectors) { for (const selector of selectors) { const element = document.querySelector(selector); if (element) { element.focus() element.scrollIntoView({ behavior: 'smooth', block: 'start' }); break; // Stop after the first match } } } }())