Jump to content

MediaWiki:Common.js: Difference between revisions

From Doom Relics
No edit summary
Tag: Replaced
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* 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);
})();
setTimeout(() => {
  // your pin/open calls here
}, 13000);

Revision as of 13:16, 24 December 2025

/* Any JavaScript here will be loaded for all users on every page load. */