User:Habst/dl.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Habst/dl. |
{
const cityNameTo = {
"xiamen": {
"countryCodeAlpha2": "cn",
"timeZone": "Asia/Shanghai"
},
"shanghai": {
"countryCodeAlpha2": "cn",
"timeZone": "Asia/Shanghai"
},
"doha": {
"countryCodeAlpha2": "qa",
"timeZone": "Asia/Qatar"
},
"rabat": {
"countryCodeAlpha2": "ma",
"timeZone": "Africa/Casablanca"
},
"eugene": {
"countryCodeAlpha2": "us",
"timeZone": "America/Los_Angeles"
},
"oslo": {
"countryCodeAlpha2": "no",
"timeZone": "Europe/Oslo"
},
"stockholm": {
"countryCodeAlpha2": "se",
"timeZone": "Europe/Stockholm"
},
"paris": {
"countryCodeAlpha2": "fr",
"timeZone": "Europe/Paris"
},
"monaco": {
"countryCodeAlpha2": "mc",
"timeZone": "Europe/Monaco"
},
"london": {
"countryCodeAlpha2": "gb",
"timeZone": "Europe/London"
},
"lausanne": {
"countryCodeAlpha2": "ch",
"timeZone": "Europe/Zurich"
},
"silesia": {
"countryCodeAlpha2": "pl",
"timeZone": "Europe/Warsaw"
},
"rome": {
"countryCodeAlpha2": "it",
"timeZone": "Europe/Rome"
},
"zurich": {
"countryCodeAlpha2": "ch",
"timeZone": "Europe/Zurich"
},
"brussels": {
"countryCodeAlpha2": "be",
"timeZone": "Europe/Brussels"
}
};
function inTz(dateString, targetTimeZone) {
const localDate = new Date(dateString);
if (isNaN(localDate)) throw new Error("Invalid date string");
const options = {
timeZone: targetTimeZone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
};
const targetDateString = localDate.toLocaleString("en-US", options);
const parsedTargetDate = new Date(targetDateString);
const diffMs = localDate.getTime() - parsedTargetDate.getTime();
return new Date(localDate.getTime() + diffMs);
}
const months = {
Jan: 1, Feb: 2, Mar: 3, Apr: 4, May: 5, Jun: 6,
Jul: 7, Aug: 8, Sep: 9, Oct: 10, Nov: 11, Dec: 12,
};
const city = 'xiamen';
const url = '';
const tz = cityNameTo[city].timeZone;
Object.fromEntries([...document.querySelectorAll('[data-row=time]')].map(eDiv => {
const evt = eDiv.querySelectorAll('div')[2].innerText;
if (['U23', 'National'].some(k => evt.includes(k))) return [];
const pv = prop => window.getComputedStyle(eDiv).getPropertyValue(prop).slice(1, -1);
const time = inTz(`${pv('--date-venue')} 2025 ${pv('--time-venue')}`, tz);
const entrants = [...eDiv.nextElementSibling.querySelectorAll('.grid')]
.filter(x => !x.classList.contains('font-medium'))
.map(entDiv => {
const entCols = [...entDiv.querySelectorAll('div')];
const [nat, athName, sb, pb] = entCols.map(d => d.innerText.trim());
const id = entDiv.querySelector('a').href.split('/').at(-1);
const words = athName.split(' ');
const firstMixedCase = words.findIndex(w => w.toUpperCase() !== w);
const lastName = words.slice(0, firstMixedCase).join(' ');
const firstName = words.slice(firstMixedCase).join(' ');
return {
pb, sb, nat, id,
firstName, lastName,
}
});
return [evt, {
date: time,
url,
entrants,
}];
}).filter(x => x.length));
}