Jump to content

MediaWiki:Common.js

From Once Human Guide
Revision as of 18:31, 21 April 2026 by Bones (talk | contribs)

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.
mw.loader.using('mediawiki.util').then(function () {
  $(function () {

    let selectedLeft = null;
    let selectedRight = null;

    /* TABS */
    document.querySelectorAll('.mw-tab-buttons').forEach(group => {
      const buttons = group.querySelectorAll('.mw-tab-btn');

      buttons.forEach(btn => {
        btn.addEventListener('click', function () {
          const tabId = this.dataset.tab;
          const container = group.closest('.mw-tab-content') || document;

          container.querySelectorAll('.mw-tab-content').forEach(c => c.style.display = 'none');
          container.querySelectorAll('.mw-tab-btn').forEach(b => b.classList.remove('active'));

          this.classList.add('active');

          const target = container.querySelector('#' + tabId);
          if (target) target.style.display = 'block';
        });
      });

      if (buttons.length > 0) buttons[0].click();
    });

    /* DROPDOWNS */
    function initDropdown(container) {
      const label = container.dataset.label;
      const options = JSON.parse(container.dataset.options);

      const wrapper = document.createElement('div');
      const button = document.createElement('button');
      const list = document.createElement('div');

      button.textContent = label;
      list.style.display = 'none';

      Object.keys(options).forEach(key => {
        const item = document.createElement('div');
        item.textContent = options[key].label;

        item.onclick = function () {
          button.textContent = options[key].label;
          list.style.display = 'none';

          if (container.classList.contains('combo-left')) selectedLeft = key;
          if (container.classList.contains('combo-right')) selectedRight = key;

          updateCombo();
        };

        list.appendChild(item);
      });

      button.onclick = function () {
        list.style.display = list.style.display === 'none' ? 'block' : 'none';
      };

      wrapper.appendChild(button);
      wrapper.appendChild(list);

      container.innerHTML = '';
      container.appendChild(wrapper);
    }

    document.querySelectorAll('.mw-dropdown-ui').forEach(initDropdown);

    /* RESULT LOGIC */
    function updateCombo() {
      const result = document.getElementById('combo-result');

      if (!selectedLeft || !selectedRight) {
        result.style.display = 'none';
        return;
      }

      result.style.display = 'block';

      if (selectedLeft === 'flame_resonance' && selectedRight === 'burn') {
        result.innerHTML = "Max Burn Stack +2, Burn Duration -20%. Flash Effect: Burn DMG +5%";
      } else {
        result.innerHTML = "No data for this combination.";
      }
    }

  });
});