MediaWiki

Difference between revisions of "Common.js"

From Shadow Era Wiki

m
m
 
(123 intermediate revisions by one user not shown)
Line 1: Line 1:
"use strict";
+
// -----------------------------
 +
// Random Card: This script randomly selects a SE card in the Main Page.
 +
// -----------------------------
 +
document.addEventListener('DOMContentLoaded', function() {
 +
    var cardData = {
 +
        "se": 202, // Number of cards in the 'se' set
 +
        "ex": 152,
 +
        "sf": 202,
 +
        "ll": 202,
 +
        "cp": 61,
 +
        "rr": 200
 +
    };
  
/* ----------------------------- */
+
    var prefixes = Object.keys(cardData); // Get prefixes of the card data
/* Fonctionnalité de Pliage pour les Templates Hide */
+
/* ----------------------------- */
+
  
 +
    var randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)];
 +
   
 +
    var maxNumber = cardData[randomPrefix];
 +
   
 +
    var randomIndex = Math.floor(Math.random() * maxNumber) + 1;
 +
   
 +
    var formattedNumber = randomIndex.toString().padStart(3, '0');
 +
   
 +
    var cardImageUrl = 'https://www.shadowera.com/cards/' + randomPrefix + formattedNumber + '.jpg';
 +
   
 +
    var cardImage = document.getElementById('randomCard');
 +
    if (cardImage) {
 +
        cardImage.src = cardImageUrl; // Set the image source
 +
        cardImage.alt = randomPrefix + formattedNumber + '.jpg';
 +
    }
 +
});
 +
// -----------------------------
 +
// Background Wiki image and Skin:
 +
// This script applies the background image and overlay styles to the wiki body.
 +
// Changes color in different area and set index to objects.
 +
// -----------------------------
 
$(document).ready(function() {
 
$(document).ready(function() {
     // Sélectionner tous les boutons de pliage
+
     // Background Image for the wiki
     $('.hide-toggle-button').each(function() {
+
     $('body').css({
         var button = $(this);
+
         'background-image': 'url("https://www.shadowera.com/landing/img/developers.jpg")',
         var content = button.next('.hide-toggle-content');
+
         'background-size': 'cover',
 +
        'background-attachment': 'fixed',
 +
        'background-repeat': 'no-repeat'
 +
    });
  
        // Gérer le clic sur le bouton
+
    // Add main Overlay
        button.click(function() {
+
    $('body').append('<div class="overlay"></div>');
            content.slideToggle(200, function() {
+
    $('.overlay').css({
                // Changer le texte du bouton en fonction de l'état
+
        'position': 'absolute',
                if (content.is(':visible')) {
+
        'top': '55px', 
                    button.text('[Collapse]');
+
        'left': '1%',
                } else {
+
        'width': '98%',
                    button.text('[Expand]');
+
        'background-color': 'rgba(24, 29, 35, 0.9)',
                }
+
        'z-index': '1',
            });
+
        'pointer-events': 'none',
         });
+
         'border-radius': '10px'
 
     });
 
     });
});
 
  
/* ----------------------------- */
+
    // Adjust the height of the main overlay to reach the bottom of the page
/* General Browser Cache Bypass Instructions */
+
    function adjustOverlayHeight() {
/* Instructions for refreshing the page cache for different browsers */
+
        var documentHeight = $(document).height();
/* ----------------------------- */
+
        var overlayStart = $('.overlay').position().top;
 +
        var overlayHeight = documentHeight - overlayStart;
 +
        $('.overlay').css('height', overlayHeight + 'px');
 +
    }
  
//Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
+
    adjustOverlayHeight();
//Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
+
//Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
+
//Opera: Clear the cache in Tools → Preferences
+
  
/* ----------------------------- */
+
    $(window).resize(function() {
/* Collapsible Tables Feature */
+
        adjustOverlayHeight();
/* Enables collapsible tables for better organization and allows users to show or hide table contents */
+
    });
/* ----------------------------- */
+
  
var autoCollapse = 2;
+
    // Check if the current page is Common.css or Common.js
var collapseCaption = 'hide';
+
    var currentPage = mw.config.get('wgPageName');
var expandCaption = 'show';
+
    if (currentPage === 'MediaWiki:Common.css' || currentPage === 'MediaWiki:Common.js') {
 +
        // Add the second overlay for specific pages with the same parameters as the main overlay
 +
        $('body').append('<div class="overlay-common"></div>');
 +
        $('.overlay-common').css({
 +
            'position': 'absolute',
 +
            'top': '55px',
 +
            'left': '1%',
 +
            'width': '98%',
 +
            'background-color': 'rgba(48, 57, 66, 0.5)',
 +
            'z-index': '1',
 +
            'pointer-events': 'none',
 +
            'border-radius': '10px'
 +
        });
  
/**
+
        // Adjust the height of the overlay to reach the bottom of the page
* Function to collapse the table rows
+
        function adjustOverlayHeightCommon() {
* @param {number} tableIndex
+
            var documentHeight = $(document).height();
*/
+
            var overlayStart = $('.overlay-common').position().top;  
function collapseTable(tableIndex) {
+
            var overlayHeight = documentHeight - overlayStart;
    var Button = document.getElementById('collapseButton' + tableIndex);
+
            $('.overlay-common').css('height', overlayHeight + 'px');  
    var Table = document.getElementById('collapsibleTable' + tableIndex);
+
        }
  
    if (!Table || !Button) {
+
        adjustOverlayHeightCommon();
         return false;
+
 
 +
        $(window).resize(function() {
 +
            adjustOverlayHeightCommon();
 +
         });
 
     }
 
     }
 +
});
  
    var Rows = Table.rows;
+
// Apply style to wiki content: This section applies styles to the main content area of the wiki.
 +
$('#mw-content-text').css({
 +
    'position': 'relative',
 +
    'color': 'white',
 +
    'padding': '20px'
 +
});
  
    if (Button.firstChild.data == collapseCaption) {
+
// Apply styles to headings
        for (var i = 1; i < Rows.length; i++) {
+
$('.mw-headline').css({
            Rows[i].style.display = 'none';
+
    'color': 'white'
        }
+
});
        Button.firstChild.data = expandCaption;
+
    } else {
+
        for (var i = 1; i < Rows.length; i++) {
+
            Rows[i].style.display = Rows[0].style.display;
+
        }
+
        Button.firstChild.data = collapseCaption;
+
    }
+
}
+
  
/**
+
// Render comments text in <span> elements with class co1 in light gray color
* Creates a click handler for table collapse/expand
+
$('.co1').css({
* @param {number} tableIndex
+
     'color': '#b3b3b3'
*/
+
});
function createClickHandler(tableIndex) {
+
     return function (e) {
+
        e.preventDefault();
+
        collapseTable(tableIndex);
+
    };
+
}
+
  
/**
+
// Set the title color to white
* Adds collapse buttons to all tables with the 'collapsible' class
+
$('.title').css({
*/
+
     'color': 'white',
function createCollapseButtons() {
+
     'position': 'relative',
     var tableIndex = 0;
+
     'z-index': '7'
     var NavigationBoxes = {};
+
});
     var Tables = document.getElementsByTagName('table');
+
  
    for (var i = 0; i < Tables.length; i++) {
+
// Make the tagline less bright
        if ($(Tables[i]).hasClass('collapsible')) {
+
$('#tagline').css({
            var HeaderRow = Tables[i].getElementsByTagName('tr')[0];
+
    'color': 'rgba(255, 255, 255, 0.5)'
            if (!HeaderRow) {
+
});
                continue;
+
            }
+
            var Header = HeaderRow.getElementsByTagName('th')[0];
+
            if (!Header) {
+
                continue;
+
            }
+
  
            NavigationBoxes[tableIndex] = Tables[i];
+
// Set the text color of abbr elements to white
            Tables[i].setAttribute('id', 'collapsibleTable' + tableIndex);
+
$('.minoredit').css({
 +
    'color': 'white',
 +
    'position': 'relative',
 +
    'z-index': '7'
 +
});
  
            var Button = document.createElement('span');
+
// Set the text color of <code> elements to white
            var ButtonLink = document.createElement('a');
+
$('code').css({
            var ButtonText = document.createTextNode(collapseCaption);
+
    'color': 'white',
 +
    'position': 'relative',
 +
    'z-index': '7'
 +
});
  
            Button.style.styleFloat = 'right';
+
// Set the text color of specific <label> element in black
            Button.style.cssFloat = 'right';
+
$('#mw-editpage-watch').css({
            Button.style.fontWeight = 'normal';
+
    'color': 'black'
            Button.style.textAlign = 'right';
+
});
            Button.style.width = '6em';
+
  
            ButtonLink.style.color = Header.style.color;
+
// Set the text color of specific <label> element in black
            ButtonLink.setAttribute('id', 'collapseButton' + tableIndex);
+
$('#mw-editpage-minoredit').css({
            $(ButtonLink).on('click', createClickHandler(tableIndex));
+
    'color': 'black'
            ButtonLink.appendChild(ButtonText);
+
});
  
            Button.appendChild(document.createTextNode('['));
+
// Set the text color of specific <label> element in black
            Button.appendChild(ButtonLink);
+
$('label[for="wpSummary"]').css({
            Button.appendChild(document.createTextNode(']'));
+
    'color': 'black'
 +
});
  
            Header.insertBefore(Button, Header.childNodes[0]);
+
// Set the text color of all other <label> elements with the for attribute to white
            tableIndex++;
+
$('label[for]').not('#mw-editpage-watch, #mw-editpage-minoredit, label[for="wpSummary"]').css({
        }
+
    'color': 'white'
    }
+
});
  
    // Collapse all tables if the conditions are met (autocollapse or collapsed class)
+
// Set the text color of all <p> elements in the #editpage-copywarn div to black
    for (var i = 0; i < tableIndex; i++) {
+
$('#editpage-copywarn p').css({
        if ($(NavigationBoxes[i]).hasClass('collapsed') ||
+
    'color': 'black'
            (tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass('autocollapse'))
+
});
        ) {
+
            collapseTable(i);
+
        }
+
    }
+
}
+
  
// Run the collapse button creation function on page load
+
// Change the color of elements <span> with the class mw-plusminus-neg
$(createCollapseButtons);
+
$('.mw-plusminus-neg').css({
 +
    'color': '#e88c18'
 +
});
  
/* ----------------------------- */
+
// Change the color of elements <a> with the class mw-userlink
/* Custom Script for Highlighting Backticks */
+
$('.mw-userlink').css({
/* Applies custom visual styles to text wrapped in backticks without altering the content */
+
    'color': '#e88c18'
/* ----------------------------- */
+
});
 +
 
 +
// Change the color of elements <a> with the class new
 +
$('a.new[title="User talk:Blopi (page does not exist)"]').css({
 +
    'color': '#e88c18'
 +
});
 +
 
 +
// Target the bold <b> text
 +
$('#editpage-copywarn b').css({
 +
    'color': 'black'
 +
});
 +
 
 +
// Render Subcategories the same color as tagline
 +
$('h2').css({
 +
    'color': 'rgba(255, 255, 255, 0.8)'
 +
});
 +
 
 +
// Set the text color of <span> elements with the class mw-plusminus-pos to light green
 +
$('.mw-plusminus-pos').css({
 +
    'color': '#66ff66'
 +
});
 +
 
 +
// Render Subcategories the same color as tagline
 +
$('h4').css({
 +
    'color': 'rgba(255, 255, 255, 0.8)'
 +
});
 +
 
 +
// Render Subcategories the same color as tagline
 +
$('h5').css({
 +
    'color': 'orange',
 +
    'position': 'relative',
 +
    'z-index': '7'
 +
});
 +
 
 +
// Change the color of table cells
 +
$('table, td, th').css({
 +
    'background-color': '#1c242c',
 +
    'color': 'white',
 +
    'border': '1px solid #3a3e42'
 +
});
 +
 
 +
// Change the color of <h3> to be the same as the tagline
 +
$('h3').css({
 +
    'color': 'rgba(255, 255, 255, 0.5)'
 +
});
 +
 
 +
// Load the collapsible module from MediaWiki to make sections collapsible.
 +
mw.loader.load('mediawiki.collapsible');
 +
 
 +
// This function displays or hides an element with the specified ID.
 +
function toggleContent(id) {
 +
    var element = document.getElementById(id);
 +
    if (element.style.display === 'none' || element.style.display === '') {
 +
        element.style.display = 'table-row-group'; // Show the element
 +
    } else {
 +
        element.style.display = 'none'; // Hide the element
 +
    }
 +
}
  
 +
// -----------------------------
 +
// Script for Highlighting Backticks
 +
// Applies custom visual styles to text wrapped in backticks without altering the content
 
// This script waits for the document to fully load, and applies a visual style  
 
// This script waits for the document to fully load, and applies a visual style  
// to any text that is surrounded by backticks (` `), without altering the content.
+
// to any text that is surrounded by backticks (` `), without altering the content in previous.
 +
// -----------------------------
  
 
document.addEventListener('DOMContentLoaded', function () {
 
document.addEventListener('DOMContentLoaded', function () {
Line 155: Line 251:
 
     }
 
     }
  
     /**
+
     //
    * Function to highlight text between backticks by wrapping it in a span element
+
    // Function to highlight text between backticks by wrapping it in a span element
    * @param {string} text
+
    // @param {string} text
    * @returns {string}
+
    // @returns {string}
    */
+
    //
 
     function highlightBackticks(text) {
 
     function highlightBackticks(text) {
 
         const backtickRegex = /`([^`]+)`/g; // Matches text between backticks
 
         const backtickRegex = /`([^`]+)`/g; // Matches text between backticks
 
         const styledText = text.replace(backtickRegex, function (match, p1) {
 
         const styledText = text.replace(backtickRegex, function (match, p1) {
             return '<span class="backtick-style">' + p1 + '</span>';
+
             return '<span class="backtick-style">' + p1 + '</span>';  
 
         });
 
         });
         return styledText;
+
         return styledText; // Return the modified text
 
     }
 
     }
  
     /**
+
     //
    * Traverse all text nodes and apply the backtick highlighting
+
    // Traverse all text nodes and apply the backtick highlighting
    * @param {Node} node
+
    // @param {Node} node
    */
+
    //
 
     function traverseTextNodes(node) {
 
     function traverseTextNodes(node) {
         if (node.nodeType === 3 && node.nodeValue.includes('`')) { // Only process text nodes
+
         if (node.nodeType === 3 && node.nodeValue.includes('`')) {  
             const span = document.createElement('span');
+
             const span = document.createElement('span');  
             span.innerHTML = highlightBackticks(node.nodeValue);
+
             span.innerHTML = highlightBackticks(node.nodeValue);  
             node.parentNode.replaceChild(span, node);
+
             node.parentNode.replaceChild(span, node);  
         } else if (node.nodeType === 1 && node.childNodes) { // Traverse element children
+
         } else if (node.nodeType === 1 && node.childNodes) {
             node.childNodes.forEach(traverseTextNodes);
+
             node.childNodes.forEach(traverseTextNodes);  
 
         }
 
         }
 
     }
 
     }
Line 185: Line 281:
 
     traverseTextNodes(document.body);
 
     traverseTextNodes(document.body);
 
});
 
});
 
console.log('Backtick script loaded');
 
 
/* ----------------------------- */
 
/* Force CSS Rules Dynamically */
 
/* Injects CSS with higher priority for overriding styles, especially the list indentations */
 
/* ----------------------------- */
 
 
// Using MediaWiki's loader to inject custom CSS with high priority
 
mw.loader.using('mediawiki.util', function () {
 
    var css = '.mw-parser-output ul ul, .mw-parser-output ul ol, .mw-parser-output ol ul, .mw-parser-output ol ol {' +
 
        'padding-left: 0 !important;' +
 
        'margin-left: 0 !important;' +
 
        '}';
 
    mw.util.addCSS(css);
 
});
 
 
/* ----------------------------- */
 
/* Collapsible Content Sections */
 
/* Enables hide/collapse functionality for content sections */
 
/* ----------------------------- */
 
 
// Fonction pour ajouter des boutons de pliage aux sections de contenu
 
$(document).ready(function() {
 
    $('.collapsible-section').each(function(index) {
 
        var section = $(this);
 
        // Créer le bouton de pliage
 
        var toggleButton = $('<button type="button" class="toggle-button">hide</button>');
 
        // Insérer le bouton au début de la section
 
        section.prepend(toggleButton);
 
        // Cacher le contenu initialement si nécessaire
 
        if (section.hasClass('collapsed')) {
 
            section.find('.section-content').hide();
 
            toggleButton.text('show');
 
        }
 
        // Ajouter l'événement de clic pour le bouton
 
        toggleButton.on('click', function() {
 
            var content = section.find('.section-content');
 
            content.toggle();
 
            // Mettre à jour le texte du bouton
 
            if (content.is(':visible')) {
 
                toggleButton.text('hide');
 
            } else {
 
                toggleButton.text('show');
 
            }
 
        });
 
    });
 
});
 
"use strict";
 
 
/* ----------------------------- */
 
/* Collapsible Content Sections */
 
/* Enables hide/collapse functionality for content sections */
 
/* ----------------------------- */
 
 
// Fonction pour ajouter le comportement pliable aux sections
 
$(document).ready(function() {
 
    $('.collapsible-section').each(function() {
 
        var section = $(this);
 
        var header = section.find('.toggle-header');
 
        var content = section.find('.toggle-content');
 
 
        // Initialiser l'état en fonction de la classe 'collapsed'
 
        if (section.hasClass('collapsed')) {
 
            content.hide();
 
        }
 
 
        // Ajouter l'événement de clic au titre
 
        header.click(function() {
 
            content.slideToggle(200);
 
            section.toggleClass('collapsed');
 
        });
 
    });
 
});
 
/* Ajustement de la mise en page pour les petits écrans (comme les téléphones mobiles) */
 
@media only screen and (max-width: 600px) {
 
    /* Rendre les tableaux wikitable plus flexibles en prenant toute la largeur de l'écran */
 
    .wikitable {
 
        width: 100% !important;
 
    }
 
    /* Réduire la taille des grandes images à 100px pour mieux les adapter aux petits écrans */
 
    img {
 
        width: 100px; /* Réduire la taille des images */
 
    }
 
}
 

Latest revision as of 17:26, 12 October 2024

// -----------------------------
// Random Card: This script randomly selects a SE card in the Main Page.
// -----------------------------
document.addEventListener('DOMContentLoaded', function() {
    var cardData = {
        "se": 202, // Number of cards in the 'se' set
        "ex": 152,
        "sf": 202,
        "ll": 202,
        "cp": 61,
        "rr": 200
    };
 
    var prefixes = Object.keys(cardData); // Get prefixes of the card data
 
    var randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)];
 
    var maxNumber = cardData[randomPrefix]; 
 
    var randomIndex = Math.floor(Math.random() * maxNumber) + 1;
 
    var formattedNumber = randomIndex.toString().padStart(3, '0'); 
 
    var cardImageUrl = 'https://www.shadowera.com/cards/' + randomPrefix + formattedNumber + '.jpg';
 
    var cardImage = document.getElementById('randomCard'); 
    if (cardImage) {
        cardImage.src = cardImageUrl; // Set the image source
        cardImage.alt = randomPrefix + formattedNumber + '.jpg';
    }
});
// -----------------------------
// Background Wiki image and Skin:
// This script applies the background image and overlay styles to the wiki body.
// Changes color in different area and set index to objects.
// -----------------------------
$(document).ready(function() {
    // Background Image for the wiki
    $('body').css({
        'background-image': 'url("https://www.shadowera.com/landing/img/developers.jpg")',
        'background-size': 'cover',
        'background-attachment': 'fixed',
        'background-repeat': 'no-repeat'
    });
 
    // Add main Overlay
    $('body').append('<div class="overlay"></div>'); 
    $('.overlay').css({
        'position': 'absolute',
        'top': '55px',  
        'left': '1%', 
        'width': '98%',
        'background-color': 'rgba(24, 29, 35, 0.9)', 
        'z-index': '1', 
        'pointer-events': 'none', 
        'border-radius': '10px' 
    });
 
    // Adjust the height of the main overlay to reach the bottom of the page
    function adjustOverlayHeight() {
        var documentHeight = $(document).height(); 
        var overlayStart = $('.overlay').position().top; 
        var overlayHeight = documentHeight - overlayStart;
        $('.overlay').css('height', overlayHeight + 'px'); 
    }
 
    adjustOverlayHeight(); 
 
    $(window).resize(function() {
        adjustOverlayHeight();
    });
 
    // Check if the current page is Common.css or Common.js
    var currentPage = mw.config.get('wgPageName');
    if (currentPage === 'MediaWiki:Common.css' || currentPage === 'MediaWiki:Common.js') {
        // Add the second overlay for specific pages with the same parameters as the main overlay
        $('body').append('<div class="overlay-common"></div>'); 
        $('.overlay-common').css({
            'position': 'absolute', 
            'top': '55px', 
            'left': '1%', 
            'width': '98%', 
            'background-color': 'rgba(48, 57, 66, 0.5)', 
            'z-index': '1',
            'pointer-events': 'none',
            'border-radius': '10px' 
        });
 
        // Adjust the height of the overlay to reach the bottom of the page
        function adjustOverlayHeightCommon() {
            var documentHeight = $(document).height(); 
            var overlayStart = $('.overlay-common').position().top; 
            var overlayHeight = documentHeight - overlayStart;
            $('.overlay-common').css('height', overlayHeight + 'px'); 
        }
 
        adjustOverlayHeightCommon();
 
        $(window).resize(function() {
            adjustOverlayHeightCommon();
        });
    }
});
 
// Apply style to wiki content: This section applies styles to the main content area of the wiki.
$('#mw-content-text').css({
    'position': 'relative',
    'color': 'white', 
    'padding': '20px'
});
 
// Apply styles to headings
$('.mw-headline').css({
    'color': 'white'
});
 
// Render comments text in <span> elements with class co1 in light gray color
$('.co1').css({
    'color': '#b3b3b3'
});
 
// Set the title color to white
$('.title').css({
    'color': 'white',
    'position': 'relative',
    'z-index': '7'
});
 
// Make the tagline less bright
$('#tagline').css({
    'color': 'rgba(255, 255, 255, 0.5)'
});
 
// Set the text color of abbr elements to white
$('.minoredit').css({
    'color': 'white',
    'position': 'relative',
    'z-index': '7'
});
 
// Set the text color of <code> elements to white
$('code').css({
    'color': 'white',
    'position': 'relative',
    'z-index': '7'
});
 
// Set the text color of specific <label> element in black
$('#mw-editpage-watch').css({
    'color': 'black'
});
 
// Set the text color of specific <label> element in black
$('#mw-editpage-minoredit').css({
    'color': 'black'
});
 
// Set the text color of specific <label> element in black
$('label[for="wpSummary"]').css({
    'color': 'black'
});
 
// Set the text color of all other <label> elements with the for attribute to white
$('label[for]').not('#mw-editpage-watch, #mw-editpage-minoredit, label[for="wpSummary"]').css({
    'color': 'white'
});
 
// Set the text color of all <p> elements in the #editpage-copywarn div to black
$('#editpage-copywarn p').css({
    'color': 'black'
});
 
// Change the color of elements <span> with the class mw-plusminus-neg
$('.mw-plusminus-neg').css({
    'color': '#e88c18'
});
 
// Change the color of elements <a> with the class mw-userlink
$('.mw-userlink').css({
    'color': '#e88c18'
});
 
// Change the color of elements <a> with the class new
$('a.new[title="User talk:Blopi (page does not exist)"]').css({
    'color': '#e88c18'
});
 
// Target the bold <b> text
$('#editpage-copywarn b').css({
    'color': 'black'
});
 
// Render Subcategories the same color as tagline
$('h2').css({
    'color': 'rgba(255, 255, 255, 0.8)'
});
 
// Set the text color of <span> elements with the class mw-plusminus-pos to light green
$('.mw-plusminus-pos').css({
    'color': '#66ff66'
});
 
// Render Subcategories the same color as tagline
$('h4').css({
    'color': 'rgba(255, 255, 255, 0.8)'
});
 
// Render Subcategories the same color as tagline
$('h5').css({
    'color': 'orange',
    'position': 'relative',
    'z-index': '7'
});
 
// Change the color of table cells
$('table, td, th').css({
    'background-color': '#1c242c',
    'color': 'white',
    'border': '1px solid #3a3e42'
});
 
// Change the color of <h3> to be the same as the tagline
$('h3').css({
    'color': 'rgba(255, 255, 255, 0.5)'
});
 
// Load the collapsible module from MediaWiki to make sections collapsible.
mw.loader.load('mediawiki.collapsible');
 
// This function displays or hides an element with the specified ID.
function toggleContent(id) {
    var element = document.getElementById(id);
    if (element.style.display === 'none' || element.style.display === '') {
        element.style.display = 'table-row-group'; // Show the element
    } else {
        element.style.display = 'none'; // Hide the element
    }
}
 
// -----------------------------
// Script for Highlighting Backticks
// Applies custom visual styles to text wrapped in backticks without altering the content
// This script waits for the document to fully load, and applies a visual style 
// to any text that is surrounded by backticks (` `), without altering the content in previous.
// -----------------------------
 
document.addEventListener('DOMContentLoaded', function () {
    // Check if we are in edit mode (to avoid changing the editor content)
    if (document.querySelector('#wpTextbox1') !== null) {
        return; // Do nothing in edit mode
    }
 
    //
    // Function to highlight text between backticks by wrapping it in a span element
    // @param {string} text
    // @returns {string}
    //
    function highlightBackticks(text) {
        const backtickRegex = /`([^`]+)`/g; // Matches text between backticks
        const styledText = text.replace(backtickRegex, function (match, p1) {
            return '<span class="backtick-style">' + p1 + '</span>'; 
        });
        return styledText; // Return the modified text
    }
 
    //
    // Traverse all text nodes and apply the backtick highlighting
    // @param {Node} node
    //
    function traverseTextNodes(node) {
        if (node.nodeType === 3 && node.nodeValue.includes('`')) { 
            const span = document.createElement('span'); 
            span.innerHTML = highlightBackticks(node.nodeValue); 
            node.parentNode.replaceChild(span, node); 
        } else if (node.nodeType === 1 && node.childNodes) {
            node.childNodes.forEach(traverseTextNodes); 
        }
    }
 
    // Apply the changes to the entire body
    traverseTextNodes(document.body);
});