MediaWiki:Minerva.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* All JavaScript here will be loaded for users of the MinervaNeue skin */ /* likeMarioWiki: Custom menu - DIAGNOSTIC VERSION (mobile.icons temporarily disabled) */ // Load only 'mediawiki.util' for now to test if links reappear $.when(mw.loader.using(['mediawiki.util']), $.ready).then(function() { // Removed 'mobile.icons' // var IconLoader = require('mobile.icons/IconLoader'); // Temporarily commented out var menu = 'p-personal'; if (mw.config.get('wgUserId')) { menu = document.getElementById('p-interaction') ? 'p-interaction' : 'p-navigation'; } function getSafeUrl(pageName) { var url = '#error-generating-url'; try { if (typeof mw !== 'undefined' && typeof mw.util !== 'undefined' && typeof mw.util.getUrl === 'function') { url = mw.util.getUrl(pageName); } else { console.warn('[Minerva.js] mw.util.getUrl not available, using basic fallback.'); var prefix = '/wiki/'; if (typeof mw !== 'undefined' && typeof mw.config !== 'undefined' && typeof mw.config.get === 'function') { prefix = mw.config.get('wgArticlePath', '/wiki/$1').replace('$1', ''); } else { console.warn('[Minerva.js] mw.config.get not available for wgArticlePath.'); } url = prefix + encodeURIComponent(pageName.replace(/ /g, '_')); } } catch (e) { console.error('[Minerva.js] Error within getSafeUrl for "' + pageName + '":', e); } return url; } function addIconAndLabelStructure(anchorElement, iconClass) { if (!anchorElement) { console.warn('[Minerva.js] addIconAndLabelStructure: anchorElement is invalid.'); return; } var originalText = anchorElement.textContent; anchorElement.innerHTML = ''; var iconSpan = document.createElement('span'); iconSpan.classList.add('mw-ui-icon', 'mw-ui-icon-element', iconClass); anchorElement.appendChild(iconSpan); var labelSpan = document.createElement('span'); labelSpan.classList.add('toggle-list-item__label'); labelSpan.textContent = originalText; anchorElement.appendChild(labelSpan); } // --- Add Categories section header --- var categoriesHeader = document.createElement('li'); categoriesHeader.classList.add('menu__item', 'menu__item--category', 'menu-header'); categoriesHeader.innerHTML = '<span class="menu-header-text">— CATEGORIES —</span>'; console.log('[Minerva.js] DIAGNOSTIC: Adding Categories header...'); // Add log document.getElementById(menu).appendChild(categoriesHeader); // --- Add links for Categories (structure + classes) --- var liLocation = mw.util.addPortletLink(menu, getSafeUrl('Animal_cruelty_cases_by_location'), 'By Location/地点'); if (liLocation) { liLocation.classList.add('toggle-list-item'); var anchorLocation = liLocation.getElementsByTagName('a')[0]; if (anchorLocation) { anchorLocation.classList.add('toggle-list-item__anchor'); addIconAndLabelStructure(anchorLocation, 'mw-ui-icon-minerva-mapPin'); // Use desired icon console.log('[Minerva.js] DIAGNOSTIC: Added By Location link.'); // Add log } } // Add similar logging for other links if you want detailed tracing var liSpecies = mw.util.addPortletLink(menu, getSafeUrl('Animal_cruelty_cases_by_species'), 'By Species/物种'); if (liSpecies) { liSpecies.classList.add('toggle-list-item'); var anchorSpecies = liSpecies.getElementsByTagName('a')[0]; if (anchorSpecies) { anchorSpecies.classList.add('toggle-list-item__anchor'); addIconAndLabelStructure(anchorSpecies, 'mw-ui-icon-minerva-mapPin'); console.log('[Minerva.js] DIAGNOSTIC: Added By Species link.'); } } var liYear = mw.util.addPortletLink(menu, getSafeUrl('Animal_cruelty_cases_by_year'), 'By Year/年份'); if (liYear) { liYear.classList.add('toggle-list-item'); var anchorYear = liYear.getElementsByTagName('a')[0]; if (anchorYear) { anchorYear.classList.add('toggle-list-item__anchor'); addIconAndLabelStructure(anchorYear, 'mw-ui-icon-minerva-mapPin'); console.log('[Minerva.js] DIAGNOSTIC: Added By Year link.'); } } // --- Add Resources section header --- var resourcesHeader = document.createElement('li'); resourcesHeader.classList.add('menu__item', 'menu__item--category', 'menu-header'); resourcesHeader.innerHTML = '<span class="menu-header-text">— RESOURCES —</span>'; console.log('[Minerva.js] DIAGNOSTIC: Adding Resources header...'); document.getElementById(menu).appendChild(resourcesHeader); // --- Add links for Resources (structure + classes) --- var liUseful = mw.util.addPortletLink(menu, getSafeUrl('Useful_links'), 'Useful links/实用链接'); if (liUseful) { liUseful.classList.add('toggle-list-item'); var anchorUseful = liUseful.getElementsByTagName('a')[0]; if (anchorUseful) { anchorUseful.classList.add('toggle-list-item__anchor'); addIconAndLabelStructure(anchorUseful, 'mw-ui-icon-minerva-link'); console.log('[Minerva.js] DIAGNOSTIC: Added Useful links.'); } } var liDocs = mw.util.addPortletLink(menu, getSafeUrl('Documentaries'), 'Documentaries/纪录片'); if (liDocs) { liDocs.classList.add('toggle-list-item'); var anchorDocs = liDocs.getElementsByTagName('a')[0]; if (anchorDocs) { anchorDocs.classList.add('toggle-list-item__anchor'); addIconAndLabelStructure(anchorDocs, 'mw-ui-icon-minerva-userContributions'); console.log('[Minerva.js] DIAGNOSTIC: Added Documentaries link.'); } } var liStudies = mw.util.addPortletLink(menu, getSafeUrl('Studies'), 'Studies/研究'); if (liStudies) { liStudies.classList.add('toggle-list-item'); var anchorStudies = liStudies.getElementsByTagName('a')[0]; if (anchorStudies) { anchorStudies.classList.add('toggle-list-item__anchor'); addIconAndLabelStructure(anchorStudies, 'mw-ui-icon-minerva-speechBubbles'); console.log('[Minerva.js] DIAGNOSTIC: Added Studies link.'); } } // --- Trigger IconLoader for newly added icons (Temporarily disabled) --- /* var menuSelector = '#' + menu + ' .mw-ui-icon-element'; var newIcons = document.querySelectorAll(menuSelector); if (newIcons.length > 0) { console.log('[Minerva.js] Found', newIcons.length, 'new icons to process.'); // IconLoader.add(newIcons); // Temporarily commented out // console.log('[Minerva.js] IconLoader.add() called.'); // Temporarily commented out } else { console.log('[Minerva.js] No new icons found to process with selector:', menuSelector); } */ console.log('[Minerva.js] DIAGNOSTIC: Custom menu script finished.'); // Add log }); // End of $.when()