Jump to content

MediaWiki:Common.js

Revision as of 12:39, 24 December 2025 by Rbutcher (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.
/* Any JavaScript here will be loaded for all users on every page load. */
// Vector 2022: for logged-out users on desktop, OPEN the menu and PIN it (real left sidebar)
(function () {
  if (mw.config.get('wgUserName')) return; // logged-out only

  function click(sel) {
    const el = document.querySelector(sel);
    if (el) { el.click(); return true; }
    return false;
  }

  function forceRealSidebar() {
    if (!window.matchMedia('(min-width: 1120px)').matches) return;

    // 1) Ensure the menu is opened (your install uses a checkbox toggle)
    const cb = document.getElementById('vector-main-menu-dropdown-checkbox');
    if (cb) {
      cb.checked = true;
      cb.dispatchEvent(new Event('change', { bubbles: true }));
    }

    // 2) Click the PIN button (this is what makes it a real left sidebar)
    // Try the standard selector first; keep fallbacks for version differences.
    click('[data-event-name="pinnable-header.vector-main-menu.pin"]') ||
    click('[data-event-name="pinnable-header.vector-main-menu.unpin"]') ||
    click('#vector-main-menu-pinned-container button');
  }

  const obs = new MutationObserver(() => {
    if (document.documentElement.classList.contains('vector-animations-ready')) {
      forceRealSidebar();
      setTimeout(forceRealSidebar, 250);
      setTimeout(forceRealSidebar, 1000);
      obs.disconnect();
    }
  });

  obs.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
  window.addEventListener('load', forceRealSidebar);
})();