MediaWiki:Common.js

From Hidden Mickey Wiki

Revision as of 15:26, 18 September 2025 by Scokely (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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// JavaScript code to save checkbox state and restore it when the page loads
$(document).ready(function() {
    // Function to save the state of checkboxes to localStorage
    function saveCheckboxState() {
        $('input[type="checkbox"]').each(function() {
            localStorage.setItem($(this).attr('id'), $(this).prop('checked'));
        });
    }

    // Function to load the state of checkboxes from localStorage
    function loadCheckboxState() {
        $('input[type="checkbox"]').each(function() {
            const savedState = localStorage.getItem($(this).attr('id'));
            if (savedState !== null) {
                $(this).prop('checked', savedState === 'true');
            }
        });
    }

    // Load the saved checkbox state when the page is loaded
    loadCheckboxState();

    // Save the checkbox state whenever a checkbox is changed
    $('input[type="checkbox"]').change(function() {
        saveCheckboxState();
    });
});

// Adjust the search box width
$(document).ready(function () {
    $('#searchInput').css('width', '600px'); // Adjust width as needed
});

(function () {
  var box = document.createElement('div');
  box.id = 'mw-test-settings';
  box.style.position = 'absolute';
  box.style.top = '10px';
  box.style.right = '10px';
  box.style.background = 'white';
  box.style.border = '1px solid #ccc';
  box.style.padding = '4px';
  box.style.zIndex = 9999;

  var btn = document.createElement('button');
  btn.textContent = 'Settings ▾';

  var list = document.createElement('ul');
  list.style.listStyle = 'none';
  list.style.margin = '4px 0 0 0';
  list.style.padding = '0';
  list.style.display = 'none';

  ['Preferences', 'Watchlist'].forEach(function (txt) {
    var li = document.createElement('li');
    var a = document.createElement('a');
    a.textContent = txt;
    a.href = '/wiki/Special:' + txt;
    a.style.display = 'block';
    a.style.padding = '4px 8px';
    a.style.textDecoration = 'none';
    a.style.color = 'black';
    li.appendChild(a);
    list.appendChild(li);
  });

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

  box.appendChild(btn);
  box.appendChild(list);
  document.body.appendChild(box);
})();