MediaWiki:Common.js

From Lenn's Fun Stuff

Revision as of 00:10, 12 March 2026 by LennLeaf (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.
/* Dark Mode Toggle - Robust Version */
$(function() {
    // 1. Create the toggle link
    var $toggle = $('<li id="pt-darkmode"><span><a href="#">Toggle Dark Mode</a></span></li>');
    
    // 2. Add it to the top right menu
    $('#p-personal ul').append($toggle);

    // 3. The Click Function
    $toggle.on('click', function(e) {
        e.preventDefault();
        $('body').toggleClass('dark-mode');
        
        // Save the setting so it stays when you refresh
        var isDark = $('body').hasClass('dark-mode');
        localStorage.setItem('wiki-dark-mode', isDark ? 'enabled' : 'disabled');
        console.log('Dark mode is now: ' + (isDark ? 'ON' : 'OFF'));
    });

    // 4. Check for saved preference on page load
    if (localStorage.getItem('wiki-dark-mode') === 'enabled') {
        $('body').addClass('dark-mode');
    }
});