Created
November 21, 2023 13:26
-
-
Save NguyenTatNhac/ad490a7aadcd0078922414afae6eaf99 to your computer and use it in GitHub Desktop.
Spouse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CITIZENSHIP_SELECT_ID = 'xi-sel-400'; | |
const APPLICANTS_NUMBER_SEL_ID = 'xi-sel-422'; | |
const FAMILY_MEMBER_SEL_ID = 'xi-sel-427'; | |
const MEMBER_CITIZEN_SEL_ID = 'xi-sel-428'; | |
const selectBookAppointment = () => { | |
const bookApt = document.querySelector('a[href*="/ams/TerminBuchen/wizardng"]'); | |
if (bookApt) { | |
bookApt.click(); | |
} | |
} | |
const isHomePage = () => { | |
const bookApt = document.querySelector('a[href*="/ams/TerminBuchen/wizardng"]'); | |
return !!bookApt; | |
} | |
const isInformationPage = () => { | |
const consentCheck = document.getElementsByName('gelesen'); | |
return consentCheck.length > 0; | |
} | |
const isServiceSelectionPage = () => { | |
const countrySelect = document.getElementById(CITIZENSHIP_SELECT_ID); | |
return !!countrySelect; | |
} | |
const processHomepage = () => { | |
selectBookAppointment(); | |
} | |
const processInformationPage = () => { | |
// Tick on check box | |
const consentCheck = document.getElementsByName('gelesen')[0]; | |
if (consentCheck) { | |
consentCheck.checked = true; | |
} | |
// Click next | |
const btn = document.getElementById('applicationForm:managedForm:proceed'); | |
if (btn) { | |
btn.click(); | |
} | |
} | |
const select = (selectId, value) => { | |
const citizenSelect = document.getElementById(selectId); | |
citizenSelect.value = value; | |
citizenSelect.dispatchEvent(new Event('change')); | |
} | |
const delayExecuted = (fn, delayTime) => { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve(fn()); | |
}, delayTime); | |
}); | |
} | |
const informationIsFilled = () => { | |
const spouseCheckBox = document.getElementById('SERVICEWAHL_EN432-0-1-4-327471'); | |
// return spouseCheckBox?.checked; | |
return true; | |
} | |
const fillInformation = async () => { | |
// Select citizen | |
select(CITIZENSHIP_SELECT_ID, 432); | |
// Select number of applicants | |
await delayExecuted(() => { | |
select(APPLICANTS_NUMBER_SEL_ID, 1); | |
}, 1000); | |
// Select live with family member "Yes: | |
await delayExecuted(() => { | |
select(FAMILY_MEMBER_SEL_ID, 1); | |
}, 1000); | |
// Select family member Citizen | |
await delayExecuted(() => { | |
select(MEMBER_CITIZEN_SEL_ID, '432-0'); | |
}, 1000); | |
// Select "Apply for a residence title" | |
await delayExecuted(() => { | |
const selectionBox = document.getElementById('SERVICEWAHL_EN3432-0-1'); | |
selectionBox.click(); | |
}, 1000) | |
// Expand "Family reason" | |
await delayExecuted(() => { | |
const selectionBox = document.getElementById('SERVICEWAHL_EN_432-0-1-4'); | |
selectionBox.click(); | |
}, 1000); | |
// Tick on "spouse" | |
await delayExecuted(() => { | |
const checkBox = document.getElementById('SERVICEWAHL_EN432-0-1-4-327471'); | |
checkBox.click(); | |
}, 1000); | |
} | |
const appendButton = () => { | |
const newButton = document.createElement('button'); | |
newButton.textContent = 'Fill'; | |
document.body.appendChild(newButton); | |
newButton.addEventListener('click', () => { | |
fill(); | |
}); | |
} | |
const processServiceSelectionPage = async () => { | |
window.fill = fillInformation; | |
appendButton(); | |
if (!informationIsFilled()) { | |
await fillInformation(); | |
} | |
await delayExecuted(() => { | |
// Click next | |
const btn = document.getElementById('applicationForm:managedForm:proceed'); | |
if (btn) { | |
btn.click(); | |
} | |
}, 10000); | |
} | |
(function() { | |
'use strict'; | |
if (isHomePage()) { | |
processHomepage(); | |
} else if (isInformationPage()) { | |
processInformationPage(); | |
} else if (isServiceSelectionPage()) { | |
processServiceSelectionPage(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment