User:Euphoria/common.js

From Test Wiki
Revision as of 07:14, 25 September 2025 by Euphoria (talk | contribs) (fix)

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.
// [[User:Euphoria/common.js]] helper for VfD closures
mw.loader.using('mediawiki.util', function () {
    if (mw.config.get('wgPageName').startsWith('User:Euphoria/TestVfD/')) {
        // Add "Close as delete"
        mw.util.addPortletLink(
            'p-cactions',
            '#',
            'Close as delete',
            'ca-close-delete',
            'Close this VfD as delete'
        ).addEventListener('click', function (e) {
            e.preventDefault();
            insertClosure('delete');
        });

        // Add "Close as keep"
        mw.util.addPortletLink(
            'p-cactions',
            '#',
            'Close as keep',
            'ca-close-keep',
            'Close this VfD as keep'
        ).addEventListener('click', function (e) {
            e.preventDefault();
            insertClosure('keep');
        });

        // Add "Close as no consensus"
        mw.util.addPortletLink(
            'p-cactions',
            '#',
            'Close as no consensus',
            'ca-close-nc',
            'Close this VfD as no consensus'
        ).addEventListener('click', function (e) {
            e.preventDefault();
            insertClosure('no consensus');
        });

        function insertClosure(action) {
            var topText = '{{subst:vt|' + action + '. --[[User:Euphoria|Euphoria]] ([[User talk:Euphoria|talk]]) 07:08, 25 September 2025 (UTC)}}\n\n';
            var bottomText = '\n\n{{subst:vb}}';

            // Access the edit box
            var textbox = document.getElementById('wpTextbox1');
            if (!textbox) {
                alert('Edit box not found!');
                return;
            }

            // Insert templates at top and bottom
            textbox.value = topText + textbox.value + bottomText;

            // Prefill summary
            document.getElementById('wpSummary').value = 'Closed as ' + action;
        }
    }
});