Jump to content

MediaWiki:Common.js: Difference between revisions

From Once Human Guide
No edit summary
No edit summary
Line 1: Line 1:
mw.loader.using('mediawiki.util').then(function () {
    $(function () {
        // Rename Discussion → Discord
        const talkTab = document.querySelector('#ca-talk a');
        const talkItem = document.querySelector('#ca-talk');
        if (talkTab) {
            talkTab.textContent = 'Discord';
            talkTab.href = 'https://discord.gg/FZtkXeGeUA';
            talkTab.target = '_blank';
            talkTab.rel = 'noopener noreferrer';
            talkTab.addEventListener('click', function (e) {
                e.preventDefault();
                window.open('https://discord.gg/FZtkXeGeUA', '_blank');
            });
        }
        // Add Road Map BEFORE Discord
        const tabList = document.querySelector('#p-associated-pages .vector-menu-content-list, #p-namespaces .vector-menu-content-list');
        if (tabList && !document.getElementById('ca-roadmap')) {
            const li = document.createElement('li');
            li.id = 'ca-roadmap';
            li.className = talkItem ? talkItem.className.replace(/\bselected\b|\bactive\b/g, '').trim() : 'mw-list-item';
            const a = document.createElement('a');
            a.href = 'https://ohwikiguide.com/index.php/Road_Map';
            const span = document.createElement('span');
            span.textContent = 'Road Map';
            a.appendChild(span);
            li.appendChild(a);
            if (talkItem) {
                tabList.insertBefore(li, talkItem);
            } else {
                tabList.appendChild(li);
            }
        }
    });
});
mw.loader.using('mediawiki.util').then(function () {
mw.loader.using('mediawiki.util').then(function () {
   $(function () {
   $(function () {
Line 62: Line 17:
       }
       }


       // Create dropdown
       // ===== CREATE DROPDOWN =====
       const select = document.createElement('select');
       const select = document.createElement('select');
       select.style.padding = '6px';
       select.style.padding = '6px';
Line 78: Line 33:
       });
       });


       // Create output panel
       // ===== CREATE OUTPUT PANEL =====
       const output = document.createElement('div');
       const output = document.createElement('div');
      output.style.marginLeft = '20px';
       output.style.padding = '12px';
       output.style.padding = '12px';
       output.style.border = '1px solid #444';
       output.style.border = '1px solid #444';
       output.style.background = '#111';
       output.style.background = '#111';
       output.style.width = '250px';
       output.style.width = '300px';
      output.style.marginTop = '0px';
       output.innerHTML = 'Provide Hide Perk information Here';
       output.innerHTML = 'Provide Hide Perk information Here';


       // Layout wrapper
       // ===== LEFT COLUMN =====
    const wrapper = document.createElement('div');
      const left = document.createElement('div');
wrapper.style.display = 'flex';
 
wrapper.style.gap = '20px';
      const leftLabel = document.createElement('div');
wrapper.style.alignItems = 'flex-start';
      leftLabel.textContent = 'Hide';
      leftLabel.style.marginBottom = '6px';
      leftLabel.style.fontWeight = 'bold';


// LEFT SIDE (Dropdown + Label)
      left.appendChild(leftLabel);
const left = document.createElement('div');
      left.appendChild(select);


const leftLabel = document.createElement('div');
      // ===== RIGHT COLUMN =====
leftLabel.textContent = 'Hide';
      const right = document.createElement('div');
leftLabel.style.marginBottom = '6px';
leftLabel.style.fontWeight = 'bold';


left.appendChild(leftLabel);
      const rightLabel = document.createElement('div');
left.appendChild(select);
      rightLabel.textContent = 'Perks';
      rightLabel.style.marginBottom = '6px';
      rightLabel.style.fontWeight = 'bold';


// RIGHT SIDE (Output + Label)
      right.appendChild(rightLabel);
const right = document.createElement('div');
      right.appendChild(output);


const rightLabel = document.createElement('div');
      // ===== WRAPPER (LAYOUT) =====
rightLabel.textContent = 'Perks';
      const wrapper = document.createElement('div');
rightLabel.style.marginBottom = '6px';
      wrapper.style.display = 'flex';
rightLabel.style.fontWeight = 'bold';
      wrapper.style.gap = '40px';
      wrapper.style.alignItems = 'flex-start';


right.appendChild(rightLabel);
      wrapper.appendChild(left);
right.appendChild(output);
      wrapper.appendChild(right);


// Add both sides
      container.appendChild(wrapper);
wrapper.appendChild(left);
wrapper.appendChild(right); container.appendChild(wrapper);


       // Change handler
       // ===== CHANGE HANDLER =====
       select.addEventListener('change', function () {
       select.addEventListener('change', function () {
         const val = this.value;
         const val = this.value;
Line 138: Line 92:
   });
   });
});
});
console.log("COMMON JS LOADED");

Revision as of 14:11, 21 April 2026

mw.loader.using('mediawiki.util').then(function () {
  $(function () {

    document.querySelectorAll('.mw-dropdown-ui').forEach(container => {

      let raw = container.getAttribute('data-options');
      if (!raw) return;

      let data;

      try {
        data = JSON.parse(raw);
      } catch (e) {
        console.error('Dropdown JSON error:', e);
        container.innerHTML = '<span style="color:red;">Invalid dropdown data</span>';
        return;
      }

      // ===== CREATE DROPDOWN =====
      const select = document.createElement('select');
      select.style.padding = '6px';

      const defaultOption = document.createElement('option');
      defaultOption.value = '';
      defaultOption.textContent = 'Select one';
      select.appendChild(defaultOption);

      Object.keys(data).forEach(key => {
        const opt = document.createElement('option');
        opt.value = key;
        opt.textContent = data[key].label;
        select.appendChild(opt);
      });

      // ===== CREATE OUTPUT PANEL =====
      const output = document.createElement('div');
      output.style.padding = '12px';
      output.style.border = '1px solid #444';
      output.style.background = '#111';
      output.style.width = '300px';
      output.innerHTML = 'Provide Hide Perk information Here';

      // ===== LEFT COLUMN =====
      const left = document.createElement('div');

      const leftLabel = document.createElement('div');
      leftLabel.textContent = 'Hide';
      leftLabel.style.marginBottom = '6px';
      leftLabel.style.fontWeight = 'bold';

      left.appendChild(leftLabel);
      left.appendChild(select);

      // ===== RIGHT COLUMN =====
      const right = document.createElement('div');

      const rightLabel = document.createElement('div');
      rightLabel.textContent = 'Perks';
      rightLabel.style.marginBottom = '6px';
      rightLabel.style.fontWeight = 'bold';

      right.appendChild(rightLabel);
      right.appendChild(output);

      // ===== WRAPPER (LAYOUT) =====
      const wrapper = document.createElement('div');
      wrapper.style.display = 'flex';
      wrapper.style.gap = '40px';
      wrapper.style.alignItems = 'flex-start';

      wrapper.appendChild(left);
      wrapper.appendChild(right);

      container.appendChild(wrapper);

      // ===== CHANGE HANDLER =====
      select.addEventListener('change', function () {
        const val = this.value;

        if (!val || !data[val]) {
          output.innerHTML = 'Provide Hide Perk information Here';
          return;
        }

        output.innerHTML =
          '<b>' + data[val].label + '</b><br><br>' +
          data[val].content;
      });

    });

  });
});