MediaWiki:Common.js: Difference between revisions

From Citypedia Online
Created page with "Any JavaScript here will be loaded for all users on every page load.: var cityBar = '<div id="city-nav-bar">' + '<a href="https://citypedia.online">🏠 Main</a>' + '<a href="https://mumbai.citypedia.online">🌊 Mumbai</a>' + '<a href="https://pune.citypedia.online">🏙️ Pune</a>' + '<a href="https://thane.citypedia.online">🌳 Thane</a>' + '</div>'; $(function() { $('body').prepend(cityBar); });"
 
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
var cityBar = '<div id="city-nav-bar">' +
/* Add a custom AI Stub Button to the toolbar */
    '<a href="https://citypedia.online">🏠 Main</a>' +
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
    '<a href="https://mumbai.citypedia.online">🌊 Mumbai</a>' +
    $textarea.wikiEditor( 'addToToolbar', {
    '<a href="https://pune.citypedia.online">🏙️ Pune</a>' +
        section: 'main',
    '<a href="https://thane.citypedia.online">🌳 Thane</a>' +
        group: 'insert',
    '</div>';
        tools: {
            "ai-stub": {
                label: 'Generate AI Stub',
                type: 'button',
                icon: 'https://upload.wikimedia.org/wikipedia/commons/1/12/Magic_wand_icon.png',
                action: {
                    type: 'callback',
                    execute: function() {
                        var topic = prompt("Enter the article topic:");
                        if (!topic) return;
                       
                        // Show a loading message
                        $textarea.textSelection('encapsulateSelection', { pre: "Generating stub for: " + topic + "...\n" });


$(function() {
                        // Call your AI backend/API here
     $('body').prepend(cityBar);
                        // For a live site, you'd use a secure proxy.
                        // For testing, you can call OpenAI directly (NOT RECOMMENDED FOR PUBLIC WIKIS)
                    }
                }
            }
        }
     });
});
});

Latest revision as of 04:29, 28 January 2026

/* Any JavaScript here will be loaded for all users on every page load. */
/* Add a custom AI Stub Button to the toolbar */
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
    $textarea.wikiEditor( 'addToToolbar', {
        section: 'main',
        group: 'insert',
        tools: {
            "ai-stub": {
                label: 'Generate AI Stub',
                type: 'button',
                icon: 'https://upload.wikimedia.org/wikipedia/commons/1/12/Magic_wand_icon.png',
                action: {
                    type: 'callback',
                    execute: function() {
                        var topic = prompt("Enter the article topic:");
                        if (!topic) return;
                        
                        // Show a loading message
                        $textarea.textSelection('encapsulateSelection', { pre: "Generating stub for: " + topic + "...\n" });

                        // Call your AI backend/API here
                        // For a live site, you'd use a secure proxy.
                        // For testing, you can call OpenAI directly (NOT RECOMMENDED FOR PUBLIC WIKIS)
                    }
                }
            }
        }
    });
});