MediaWiki:Common.js

From Medalist Wiki
Revision as of 18:09, 6 February 2025 by Zhiktang (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. */
// MediaWiki:Common.js
mw.loader.using(['mediawiki.util', 'jquery'], function() {
    $(function() {
        // Create the HTML string for the toggle container
        var toggleHtml = 
            '<div class="toggle-container">' +
            '<div class="toggle-label">Select version:</div>' +
            '<button class="toggle-button anime-toggle">Anime</button>' +
            '<button class="toggle-button manga-toggle active">Manga</button>' +
            '</div>';
        
        // Insert the toggle container after the first heading
        $('#firstHeading').after(toggleHtml);
        
        // Set initial state
        $('body').addClass('show-manga');
        
        // Anime toggle click handler
        $('.anime-toggle').on('click', function() {
            $('.toggle-button').removeClass('active');
            $(this).addClass('active');
            $('body')
                .removeClass('show-manga')
                .addClass('show-anime');
            // Save preference in localStorage if available
            if (window.localStorage) {
                window.localStorage.setItem('contentPreference', 'anime');
            }
        });
        
        // Manga toggle click handler
        $('.manga-toggle').on('click', function() {
            $('.toggle-button').removeClass('active');
            $(this).addClass('active');
            $('body')
                .removeClass('show-anime')
                .addClass('show-manga');
            // Save preference in localStorage if available
            if (window.localStorage) {
                window.localStorage.setItem('contentPreference', 'manga');
            }
        });
        
        // Load saved preference if localStorage is available
        if (window.localStorage) {
            var savedPreference = window.localStorage.getItem('contentPreference');
            if (savedPreference === 'anime') {
                $('.anime-toggle').trigger('click');
            }
        }
    });
});