MediaWiki:Common.js

From UO Renaissance Wiki
Revision as of 13:27, 8 September 2026 by Samorite (talk | contribs) (Add script for skills dropdown in Compendium sidebar)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.
/* UO Renaissance Wiki Common.js */
(function() {
  function initSkillsDropdown() {
    var compendiumPortal = document.getElementById('p-Compendium');
    if (!compendiumPortal) return;

    var skillsLi = compendiumPortal.querySelector('li#n-Skills') ||
                   compendiumPortal.querySelector('li#n-Skills-Overview') ||
                   compendiumPortal.querySelector('a[href*="/wiki/index.php/Skills"]')?.closest('li');

    if (skillsLi && !skillsLi.querySelector('.uor-skills-dropdown-wrap')) {
      var wrap = document.createElement('div');
      wrap.className = 'uor-skills-dropdown-wrap';
      wrap.innerHTML = '<select class="uor-skills-dropdown-select" aria-label="Select Skill Section">' +
        '<option value="/wiki/index.php/Skills">Skill Sections...</option>' +
        '<option value="/wiki/index.php/Skills#Combat">Combat</option>' +
        '<option value="/wiki/index.php/Skills#Crafting">Crafting</option>' +
        '<option value="/wiki/index.php/Skills#Creatures">Creatures</option>' +
        '<option value="/wiki/index.php/Skills#Lore_&_Knowledge">Lore & Knowledge</option>' +
        '<option value="/wiki/index.php/Skills#Miscellaneous">Miscellaneous</option>' +
        '<option value="/wiki/index.php/Skills#Rogue">Rogue</option>' +
        '<option value="/wiki/index.php/Spells">Spells & Magic</option>' +
      '</select>';

      var select = wrap.querySelector('select');
      var currentPath = window.location.pathname + window.location.hash;
      for (var i = 0; i < select.options.length; i++) {
        if (select.options[i].value && currentPath.indexOf(select.options[i].value) !== -1) {
          select.selectedIndex = i;
          break;
        }
      }

      select.addEventListener('change', function() {
        if (this.value) {
          window.location.href = this.value;
        }
      });

      skillsLi.appendChild(wrap);
    }
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initSkillsDropdown);
  } else {
    initSkillsDropdown();
  }
})();