Last active
September 6, 2023 17:40
-
-
Save smkplus/dcb40b8834d45b60614d677108f39556 to your computer and use it in GitHub Desktop.
Jalali Trello Use InjectCode to use this
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
// ==UserScript== | |
// @name New Jalali Date for Trello | |
// @namespace Seyed Morteza Kamali | |
// @description Jalali date updated for Trello with support for all formats | |
// @include https://trello.com/* | |
// @include http://trello.com/* | |
// @version 0.0.2 beta | |
// ==/UserScript== | |
fetch('https://unpkg.com/jalali-moment/dist/jalali-moment.browser.js') | |
.then(response => response.text()) | |
.then(jalaliMomentScript => { | |
eval(jalaliMomentScript); | |
setInterval(() => { | |
// Handle start date | |
document.querySelectorAll('.js-start-date-badge').forEach(startDateElement => { | |
const textContent = startDateElement.textContent; | |
// Check if the textContent includes a month abbreviation (e.g., "Sep 5" or "Oct 11") | |
const monthMatch = textContent.match(/(\w{3} \d{1,2})/); | |
if (monthMatch) { | |
const monthText = monthMatch[1]; | |
const momentDate = moment(monthText, 'MMM D'); // Assuming no year, adjust the date format as needed | |
const jalaliDate = momentDate.locale('fa').format('D MMM'); // Adjust the Jalali date format as needed | |
startDateElement.textContent = jalaliDate; | |
} | |
}); | |
// Handle other date elements, including date ranges | |
document.querySelectorAll('.js-due-date-text:not([jalalized]), .action-card:not([jalalized]), .date:not([jalalized]), .js-date-text:not([jalalized])').forEach(item => { | |
const textContent = item.innerText; | |
// Check for date range format (e.g., "Oct 18 - Oct 26") | |
const dateRangeMatch = textContent.match(/(\w{3} \d\d?) - (\w{3} \d\d?)/); | |
if (dateRangeMatch) { | |
const startDate = moment(dateRangeMatch[1], 'MMM D'); | |
const endDate = moment(dateRangeMatch[2], 'MMM D'); | |
const jalaliStartDate = startDate.locale('fa').format('D MMM'); | |
const jalaliEndDate = endDate.locale('fa').format('D MMM'); | |
item.innerHTML = `<span>${jalaliStartDate} ${jalaliEndDate}</span>`; | |
} else { | |
const momentDate = moment(textContent, 'MMM D, YYYY'); // Adjust the date format as needed | |
const jalaliDate = momentDate.locale('fa').format('D MMM'); // Adjust the Jalali date format as needed | |
item.innerHTML = `<span>${jalaliDate}</span>`; | |
} | |
}); | |
}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment