Skip to content

Instantly share code, notes, and snippets.

@hosseinmasoomi
Created November 4, 2023 20:46
Show Gist options
  • Save hosseinmasoomi/0d5f873ec54e5538d3f46264c82d4126 to your computer and use it in GitHub Desktop.
Save hosseinmasoomi/0d5f873ec54e5538d3f46264c82d4126 to your computer and use it in GitHub Desktop.
api persian - shamsi calendar - holidays
Array.from(document.querySelectorAll("li[class='eventHoliday ']"), (node => ({
date:document.querySelector("input[type='text']").value +'/' + (Array.from(document.querySelectorAll("div[class='col-md-12']>div>div>span>span>span"), node => node.innerText).findIndex(x => x === node.innerText.split(" ")[1]) + 1).toString() + "/" + node.innerText.split(" ")[0].replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d)),
description: node.innerText.split(" ").slice(2).join(" ")
})))
@Kourva
Copy link

Kourva commented Apr 12, 2025

Thanks a lot!

(() => {
    const persianDigits = '۰۱۲۳۴۵۶۷۸۹';
    const faToEn = s => s.replace(/[۰-۹]/g, d => persianDigits.indexOf(d));

    const year = document.querySelector("input[type='text']")?.value ?? "1404";

    const monthElements = Array.from(document.querySelectorAll("div.col-md-12 > div > div > span > span > span"));
    const monthNames = monthElements.map(el => el.innerText.trim());

    const holidays = Array.from(document.querySelectorAll("li.eventHoliday")).map(node => {
        const parts = node.innerText.trim().split(/\s+/);
        if (parts.length < 3) return null;

        const day = faToEn(parts[0]);
        const monthName = parts[1];
        const desc = parts.slice(2).join(" ");
        const monthIndex = monthNames.findIndex(x => x === monthName) + 1;

        return {
            date: `${year}/${monthIndex}/${day}`,
            description: desc
        };
    }).filter(Boolean);

    console.log(JSON.stringify(holidays, null, 2));
    copy(holidays); 
})();

I think this is easiest way to get JSON output of the holidays. Just run the code on console of the target URL ( you can also select another year and get the data from it! ), maybe this helps...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment