Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', function () {
     const btn = document.querySelector('.citizen-search-toggle');
    // Citizen search button
     const citizenToggle = document.querySelector('.citizen-search-toggle');


     // If the search button exists, create a hotkey to open it
     // Hotkey version (optional, keep it)
     if (btn) {
     document.addEventListener('keydown', function (e) {
        document.addEventListener('keydown', function (e) {
        if (e.altKey && e.shiftKey && e.key.toLowerCase() === 'f') {
            // Change this to any combo you want
            e.preventDefault();
            if (e.altKey && e.shiftKey && e.key.toLowerCase() === 'f') {
            if (citizenToggle) citizenToggle.click();
                e.preventDefault();
        }
                btn.click(); // Opens the Citizen search overlay
    });
            }
 
         });
    // Insert a visible UI button into the page
     }
    const btn = document.createElement('div');
    btn.className = 'custom-search-btn';
    btn.textContent = 'Search';
    btn.addEventListener('click', function () {
         if (citizenToggle) citizenToggle.click();
    });
 
    // Add it at the top of every page content
     const content = document.querySelector('#content, .mw-body');
    if (content) content.prepend(btn);
});
});

Revision as of 03:01, 8 November 2025

document.addEventListener('DOMContentLoaded', function () {
    // Citizen search button
    const citizenToggle = document.querySelector('.citizen-search-toggle');

    // Hotkey version (optional, keep it)
    document.addEventListener('keydown', function (e) {
        if (e.altKey && e.shiftKey && e.key.toLowerCase() === 'f') {
            e.preventDefault();
            if (citizenToggle) citizenToggle.click();
        }
    });

    // Insert a visible UI button into the page
    const btn = document.createElement('div');
    btn.className = 'custom-search-btn';
    btn.textContent = 'Search';
    btn.addEventListener('click', function () {
        if (citizenToggle) citizenToggle.click();
    });

    // Add it at the top of every page content
    const content = document.querySelector('#content, .mw-body');
    if (content) content.prepend(btn);
});