Skip to content

Instantly share code, notes, and snippets.

@yogendra
Last active June 11, 2026 12:50
Show Gist options
  • Select an option

  • Save yogendra/32e06b604a68675ed01b94bae964c506 to your computer and use it in GitHub Desktop.

Select an option

Save yogendra/32e06b604a68675ed01b94bae964c506 to your computer and use it in GitHub Desktop.
Useful Scripts for bookmarklet
// mdac-filler.js
// Bookmarklet: javascript:(function(){const s=document.createElement('script');s.src='https://gist.githubusercontent.com/yogendra/32e06b604a68675ed01b94bae964c506/raw/mdac-filler.js';s.onload=()=>{console.log('MDAC engine loaded. Ready to call fillMdac(data);')};document.head.appendChild(s);})();
//
function fillMdac(data) {
const findLbl = (str) => Array.from(document.querySelectorAll('td, label, span')).find(el => el.textContent.includes(str));
const setT = (lbl, val) => {
const l = findLbl(lbl);
const i = l?.closest('tr')?.querySelector('input[type="text"], input[type="email"]');
if (i) {
i.value = val;
i.dispatchEvent(new Event('input', { bubbles: true }));
i.dispatchEvent(new Event('change', { bubbles: true }));
}
};
const setS = (lbl, val) => {
const l = findLbl(lbl);
const s = l?.closest('tr')?.querySelector('select');
if (!s) return;
const tgt = val.toUpperCase().replace(/\s+/g, '');
for (let i = 0; i < s.options.length; i++) {
if (s.options[i].text.toUpperCase().replace(/\s+/g, '').includes(tgt)) {
s.selectedIndex = i;
s.dispatchEvent(new Event('change', { bubbles: true }));
if (s.id && window.PrimeFaces?.widgets) {
const w = window.PrimeFaces.widgets[s.id.replace(/_input$/, '')];
if (w?.selectValue) w.selectValue(s.options[i].value);
}
break;
}
}
};
// 1. Personal Information Section
setT("Name :", data.name);
setT("Passport No. :", data.passportNo);
setT("Date of Birth :", data.dob);
setT("Date of Passport Expiry :", data.passportExpiry);
setT("Email Address :", data.email);
setT("Confirm Email Address :", data.email);
setT("Mobile No. :", data.mobile);
setS("Nationality / Citizenship :", data.nationality);
setS("Place of Birth :", data.placeOfBirth);
setS("Sex :", data.sex);
setS("Country / Region Code :", data.countryCode);
// 2. Traveling Information Section
setT("Date of Arrival :", data.arrivalDate);
setT("Date of Departure :", data.departureDate);
setT("Transportation No. :", data.transportNo || "BUS");
setS("Mode of Travel :", data.modeOfTravel);
setS("Last Port of Embarkation", data.lastPort);
setS("Accommodation of Stay :", data.accommodation);
// 3. Address Section
const aL = findLbl("Address (In Malaysia)");
if (aL) {
const rI = aL.closest('tr')?.querySelectorAll('input[type="text"]');
if (rI && rI.length >= 2) {
rI[0].value = data.address1;
rI[0].dispatchEvent(new Event('input', { bubbles: true }));
rI[1].value = d.address2;
rI[1].dispatchEvent(new Event('input', { bubbles: true }));
}
}
setT("Postcode :", data.postcode);
setS("State :", data.state);
setTimeout(() => {
setS("City :", data.city);
console.log(`Form filled successfully for: ${data.name}`);
}, 600);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment