Skip to main content
SADA
  • Home
  • All courses
  • More
English ‎(en)‎
English ‎(en)‎ Français ‎(fr)‎ Português - Portugal ‎(pt)‎ العربية ‎(ar)‎
SADA
Home All courses
  1. Home
  2. Courses

Smart Africa Digital Academy

Expand all

WARDIP Learning Pathways

Data Centers and Cloud Computing

Data Management and Analytics

Broadband and 5G

Greening with Digital

You are not logged in. (Log in)
Data retention summary
Get the mobile app
Moodle Multi-Course Enrollment Script document.addEventListener('DOMContentLoaded', function() { console.log('Script loaded, checking body classes:', document.body.className); // Only run on activity pages (path-mod) if (document.body.className.includes('path-mod')) { console.log('On activity page, looking for title...'); // Try to find the activity/page title from various possible locations let activityTitle = ''; // Look for title in the hidden header first (this should be the activity title) const headerTitle = document.querySelector('.page-header-headings h1, .page-header-headings h2, .course-header-txt h1, .course-header-txt h2'); if (headerTitle) { activityTitle = headerTitle.textContent.trim(); console.log('Found title in header:', activityTitle); } // Fallback: try to get activity title from page title if (!activityTitle) { const pageTitle = document.title; console.log('Page title:', pageTitle); // Extract activity name from title (format usually "Activity: Course | Site") const titleParts = pageTitle.split('|')[0].split(':'); if (titleParts.length > 0) { activityTitle = titleParts[0].trim(); console.log('Extracted from page title:', activityTitle); } } // Another fallback: look for activity title in main content area if (!activityTitle) { const mainTitle = document.querySelector('#region-main h1, #region-main h2, .activity-header h1, .activity-header h2'); if (mainTitle) { activityTitle = mainTitle.textContent.trim(); console.log('Found title in main content:', activityTitle); } } // Final fallback: use a generic title if (!activityTitle) { activityTitle = 'Page Content'; console.log('Using fallback title'); } // Create the new header const newHeader = document.createElement('div'); newHeader.className = 'custom-course-header'; newHeader.innerHTML = `

${activityTitle}

`; // Insert the new header at the top of the main content area const mainContent = document.querySelector('#page-content, #page, main, .main-content, #region-main'); if (mainContent) { mainContent.insertBefore(newHeader, mainContent.firstChild); console.log('Header inserted into main content'); } else { // Fallback: insert after body opening document.body.insertBefore(newHeader, document.body.firstChild); console.log('Header inserted at body start'); } console.log('Custom header created with title:', activityTitle); } else { console.log('Not on activity page, script not running'); } }); // Robust mlang processor for SADA - handles dynamic content (function() { 'use strict'; function getCurrentLanguage() { // Get language from Moodle's M.cfg if (typeof M !== 'undefined' && M.cfg && M.cfg.language) { console.log('Language from M.cfg:', M.cfg.language); return M.cfg.language; } // Check URL parameter const urlParams = new URLSearchParams(window.location.search); const langParam = urlParams.get('lang'); if (langParam) { console.log('Language from URL:', langParam); return langParam; } console.log('Using default language: en'); return 'en'; } function processMlangTags() { const currentLang = getCurrentLanguage(); console.log('=== Processing mlang tags for language:', currentLang, '==='); // Look specifically for elements containing mlang patterns const elementsWithMlang = []; // Use a more comprehensive search const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_TEXT, function(node) { return node.textContent.includes('{mlang') ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT; } ); let textNode; while (textNode = walker.nextNode()) { elementsWithMlang.push(textNode); } console.log('Found', elementsWithMlang.length, 'text nodes with mlang tags'); let processedCount = 0; elementsWithMlang.forEach(function(textNode, index) { const originalText = textNode.textContent; console.log('Processing node', index + 1, ':', originalText); // Pattern to match: {mlang en}content{mlang}{mlang fr}content{mlang} const fullPattern = /(\{mlang\s+\w+\}[^{]*\{mlang\})+/g; const matches = originalText.match(fullPattern); if (matches) { let newText = originalText; matches.forEach(function(fullMatch) { console.log('Found mlang block:', fullMatch); // Extract individual segments const segmentPattern = /\{mlang\s+(\w+)\}([^{]*)\{mlang\}/g; const segments = []; let segmentMatch; // Reset regex segmentPattern.lastIndex = 0; while ((segmentMatch = segmentPattern.exec(fullMatch)) !== null) { segments.push({ lang: segmentMatch[1].trim(), content: segmentMatch[2] }); } console.log('Extracted segments:', segments); // Find appropriate content let replacement = ''; // Try current language first const currentLangSegment = segments.find(s => s.lang === currentLang); if (currentLangSegment) { replacement = currentLangSegment.content; console.log('Using current language content:', replacement); } // Fallback to English if not current language else if (currentLang !== 'en') { const englishSegment = segments.find(s => s.lang === 'en'); if (englishSegment) { replacement = englishSegment.content; console.log('Using English fallback:', replacement); } } // Last resort: first available if (!replacement && segments.length > 0) { replacement = segments[0].content; console.log('Using first available content:', replacement); } // Replace in the text newText = newText.replace(fullMatch, replacement); console.log('Replaced with:', replacement); }); // Update the text node textNode.textContent = newText; processedCount++; console.log('Updated node text to:', newText); } }); console.log('=== Completed processing. Updated', processedCount, 'nodes ==='); return processedCount; } // Multiple initialization strategies function initialize() { console.log('mlang processor initializing...'); // Strategy 1: Immediate processing setTimeout(function() { console.log('Strategy 1: Immediate processing'); processMlangTags(); }, 100); // Strategy 2: After a longer delay for dynamic content setTimeout(function() { console.log('Strategy 2: Delayed processing'); processMlangTags(); }, 2000); // Strategy 3: After page fully loads window.addEventListener('load', function() { setTimeout(function() { console.log('Strategy 3: After window load'); processMlangTags(); }, 500); }); // Strategy 4: Set up mutation observer const observer = new MutationObserver(function(mutations) { let shouldProcess = false; mutations.forEach(function(mutation) { if (mutation.type === 'childList') { mutation.addedNodes.forEach(function(node) { if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.TEXT_NODE) { const textContent = node.textContent || ''; if (textContent.includes('{mlang')) { console.log('Mutation observer detected mlang content'); shouldProcess = true; } } }); } }); if (shouldProcess) { setTimeout(function() { console.log('Strategy 4: Mutation observer triggered'); processMlangTags(); }, 300); } }); observer.observe(document.body, { childList: true, subtree: true, characterData: true }); console.log('All strategies initialized'); } // Manual refresh function window.refreshMlangContent = function() { console.log('=== MANUAL REFRESH TRIGGERED ==='); const count = processMlangTags(); console.log('Manual refresh completed. Processed', count, 'elements.'); return count; }; // Debug function to find mlang content window.findMlangContent = function() { console.log('=== SEARCHING FOR MLANG CONTENT ==='); const allText = document.body.textContent; if (allText.includes('{mlang')) { console.log('Found {mlang} in page text content'); // Find specific elements const allElements = document.querySelectorAll('*'); const elementsWithMlang = []; allElements.forEach(function(el, index) { if (el.textContent && el.textContent.includes('{mlang')) { elementsWithMlang.push({ element: el, tagName: el.tagName, className: el.className, textContent: el.textContent }); } }); console.log('Elements containing mlang:', elementsWithMlang); return elementsWithMlang; } else { console.log('No {mlang} found in page content'); return []; } }; // Start when ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initialize); } else { initialize(); } })();
Powered by Moodle