User:Plutus/test.js

mw.loader.using(['mediawiki.util', 'mediawiki.api'], function () { // 1. Add a link to the toolbox mw.util.addPortletLink( '

mw.loader.using(['mediawiki.util', 'mediawiki.api'], function () {
    // 1. Add a link to the toolbox
    mw.util.addPortletLink(
        'p-tb',
        mw.util.getUrl('User:Cactusisme/Add Text'),
        'Add Text to Pages',
        't-addtext',
        'Open Add Text panel'
    );

    // 2. Check if we're on the tool page
    if (mw.config.get('wgPageName') === 'User:Cactusisme/Add_Text') {
        var $content = $('#mw-content-text');
        $content.empty(); // Clear existing content

        // Inject form UI
        $content.append(`
            <h2>Add Text to Multiple Pages</h2>
            <div id="add-text-tool">
                <label><b>Text to add:</b></label><br>
                <textarea id="addtext-text" rows="5" style="width:100%"></textarea><br><br>

                <label><b>Pages (one per line):</b></label><br>
                <textarea id="addtext-pages" rows="10" style="width:100%"></textarea><br><br>

                <button id="addtext-submit">Add Text</button>
                <div id="addtext-status" style="margin-top:1em;"></div>
            </div>
        `);

        var api = new mw.Api();

        function editPage(title, text) {
            return api.get({
                action: 'query',
                prop: 'revisions',
                rvprop: 'content',
                titles: title,
                formatversion: 2
            }).then(function (data) {
                var page = data.query.pages[0];
                var newContent = (page.missing ? '' : page.revisions[0].content) + '\n' + text;
                return api.edit(title, function () {
                    return {
                        text: newContent,
                        summary: 'Added text via Add Text tool'
                    };
                });
            });
        }

        $('#addtext-submit').on('click', function () {
            var text = $('#addtext-text').val().trim();
            var pages = $('#addtext-pages').val().split('\n').map(p => p.trim()).filter(Boolean);

            if (!text || pages.length === 0) {
                alert('Please enter both text and at least one page.');
                return;
            }

            var $status = $('#addtext-status').empty().text('Processing...');

            var promises = pages.map(function (title) {
                return editPage(title, text).then(function () {
                    $status.append(`<div>✔ Edited ${mw.html.escape(title)}</div>`);
                }).catch(function (err) {
                    $status.append(`<div>❌ Failed to edit ${mw.html.escape(title)}: ${err}</div>`);
                });
            });

            Promise.all(promises).then(function () {
                $status.append('<div><b>All done!</b></div>');
            });
        });
    }
});

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.