MediaWiki:Timeless.js

From Ghost Theory Wiki
Revision as of 19:00, 15 December 2025 by PerilM (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.
/* Add custom classes to sidebar portlets */
document.querySelectorAll('#mw-panel .mw-portlet').forEach(portlet => {
  const header = portlet.querySelector('h3');
  if (header) {
    header.classList.add('portlet-header');
    const arrow = document.createElement('span');
    arrow.className = 'portlet-arrow';
    arrow.textContent = '▼';
    header.appendChild(arrow);
  }
});

/* Portlet Toggle */
document.querySelectorAll('.portlet-header').forEach(header => {
  header.addEventListener('click', function () {
    const portlet = this.closest('.mw-portlet');
    const body = portlet.querySelector('.mw-portlet-body');
    const arrow = this.querySelector('.portlet-arrow');

    body.classList.toggle('collapsed');
    arrow.classList.toggle('collapsed');
  });
});

/* Year Toggle */
document.querySelectorAll('#p-years .mw-portlet-body > ul > li').forEach(yearItem => {
  const header = yearItem.querySelector('a');
  if (!header) return;

  header.classList.add('year-header');

  const arrow = document.createElement('span');
  arrow.className = 'year-arrow';
  arrow.textContent = '▼';
  header.appendChild(arrow);

  const sublist = yearItem.querySelector('ul');
  if (sublist) {
    sublist.classList.add('year-content');
    sublist.style.display = 'none';

    header.addEventListener('click', function (e) {
      e.preventDefault();
      sublist.classList.toggle('expanded');
      arrow.classList.toggle('collapsed');
      sublist.style.display = sublist.classList.contains('expanded') ? 'block' : 'none';
    });
  }
});

/* Search Functionality */
document.querySelector('#p-search input')?.addEventListener('keyup', function (e) {
  const searchTerm = e.target.value.toLowerCase();
  document.querySelectorAll('#mw-panel a').forEach(link => {
    const text = link.textContent.toLowerCase();
    link.style.display = text.includes(searchTerm) ? 'block' : 'none';
  });
});