Skip to content

Instantly share code, notes, and snippets.

@egeozcan
Last active September 29, 2021 04:51
Show Gist options
  • Save egeozcan/1883de5afe94777f757114710010879d to your computer and use it in GitHub Desktop.
Save egeozcan/1883de5afe94777f757114710010879d to your computer and use it in GitHub Desktop.
//to be used in https://tr.wikipedia.org/wiki/T%C3%BCrkiye_Cumhuriyet_Merkez_Bankas%C4%B1_ba%C5%9Fkanlar%C4%B1_listesi
function parseDate(dateStr) {
const [dayStr, monthStr, yearStr] = dateStr.split(" ");
const parsedDate = new Date(parseInt(yearStr), months.indexOf(monthStr), parseInt(dayStr));
return isNaN(parsedDate.getDay()) ? new Date() : parsedDate;
}
const months = ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'];
const table = document.getElementById("Merkez_Bankası_başkanları").closest("h2").nextElementSibling;
// ekstra sütun
[...table.rows].forEach((x, i) => x.append(document.createElement(i === 0 ? "th" : "td")));
table.querySelectorAll("tbody tr").forEach(row => {
const firstCell = row.children[0];
const cells = [...row.children];
if (firstCell.colSpan === 4) {
return;
}
if (firstCell.tagName === "TH") {
cells.pop().innerHTML = "Görev Süresi";
return;
}
const [, , startDateStr, endDateStr] = cells.map(x => x.innerText);
const diff = new Date(parseDate(endDateStr) - parseDate(startDateStr));
cells.pop().innerHTML = `${diff.getUTCFullYear() - 1970} yıl ${diff.getUTCMonth()} ay ${diff.getUTCDate() - 1} gün `;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment