/** * SMP Tag Helper * * Automatically converts SMP tags to glossary links * Usage: Term Name * * This script: * 1. Scans the page for data-smp attributes * 2. Fetches the glossary data * 3. Converts tags to linked terms with tooltips */ (function() { 'use strict'; const GLOSSARY_URL = '/glossary/glossary-data.json'; let glossaryData = null; // Load glossary data async function loadGlossary() { try { const response = await fetch(GLOSSARY_URL); if (!response.ok) throw new Error('Failed to load glossary'); glossaryData = await response.json(); processTags(); } catch (error) { console.warn('SMP Tag Helper: Could not load glossary', error); } } // Process all SMP tags function processTags() { if (!glossaryData) return; const tags = document.querySelectorAll('[data-smp]'); tags.forEach(tag => { const termId = tag.getAttribute('data-smp'); const term = glossaryData.terms.find(t => t.id === termId); if (term) { // Create link const link = document.createElement('a'); link.href = '/glossary/#' + termId; link.className = 'smp-tag'; link.innerHTML = tag.innerHTML; link.setAttribute('data-term', termId); // Add tooltip link.title = term.short; // Replace original element tag.parentNode.replaceChild(link, tag); } }); } // Initialize if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', loadGlossary); } else { loadGlossary(); } })();