User:Euphoria/common.js

From Test Wiki
Revision as of 08:10, 25 September 2025 by Euphoria (talk | contribs) (fix)
Jump to navigation Jump to search

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//<nowiki>
mw.loader.using('mediawiki.util', function () {
    if (mw.config.get('wgPageName').startsWith('User:Euphoria/TestVfD/')) {

        function addClosureButton(label, action) {
            mw.util.addPortletLink(
                'p-cactions',
                '#',
                label,
                'ca-close-' + action.replace(/\s+/g, '-'),
                'Close this VfD as ' + action
            ).addEventListener('click', function (e) {
                e.preventDefault();
                redirectToEdit(action);
            });
        }

        // Add buttons
        addClosureButton('Close as delete', 'delete');
        addClosureButton('Close as keep', 'keep');
        addClosureButton('Close as no consensus', 'no consensus');

        function redirectToEdit(action) {
            var page = mw.config.get('wgPageName');
            var topText = '{{subst:vt|' + action + '. --~~~~}}\n\n';
            var bottomText = '\n\n{{subst:vb}}';
            var summary = 'Closed as ' + action;

            // Build edit URL with prefill
            var editUrl = mw.util.getUrl(page, {
                action: 'edit',
                prefill: topText + bottomText,
                summary: summary
            });

            // Redirect to edit page
            window.location.href = editUrl;
        }

    }
});
//</nowiki>