(function() {
// We remove clearInterval to keep checking in case new cards load or data delay occurs
const checkInterval = setInterval(() => {
const list = window.expiring_courses;
// If data isn't here yet, just wait for the next tick
if (!list || list.length === 0) {
console.log("Waiting for Expiring Courses data...");
return;
}
// Find all course containers
const courseCards = document.querySelectorAll('.course-item-02');
if (courseCards.length === 0) return;
courseCards.forEach(card => {
// Avoid adding multiple badges to the same card
if (card.querySelector('.expiry-badge-custom')) return;
const anchor = card.querySelector('a');
const href = anchor ? anchor.getAttribute('href') : "";
if (!href) return;
// Extract the slug (e.g., "osak1") to ensure a match regardless of /take/ prefix
const courseSlug = href.split('/').filter(Boolean).pop();
// Find match in the PowerUp list
const courseData = list.find(c => c.card_url.includes(courseSlug));
if (courseData) {
const expiry = new Date(courseData.exp_ms * 1000);
const daysLeft = Math.ceil((expiry - new Date()) / (1000 * 60 * 60 * 24));
const badge = document.createElement('div');
badge.className = 'expiry-badge-custom'; // Marker to prevent duplicates
badge.innerHTML = `