User:Euphoria/common.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
fix
fix
Line 1: Line 1:
//<nowiki>
//<nowiki>
mw.loader.using('mediawiki.util', function () {
mw.loader.using('mediawiki.util', function () {
if (mw.config.get('wgPageName').startsWith('User:Euphoria/TestVfD/')) {
const pagePrefix = 'User:Euphoria/TestVfD/';

// Only run on relevant pages
if (mw.config.get('wgPageName').startsWith(pagePrefix)) {

// Buttons on page view
if (mw.config.get('wgAction') === 'view') {

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();

// Store the content in localStorage
const topText = '{{subst:vt|' + action + '. --~~~~}}\n\n';
const bottomText = '\n\n{{subst:vb}}';
const summary = 'Closed as ' + action;

localStorage.setItem('vfdPrefillContent', topText + bottomText);
localStorage.setItem('vfdPrefillSummary', summary);

// Redirect to edit page
window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' });
});
}

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


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
// On edit page: insert stored content
addClosureButton('Close as delete', 'delete');
if (mw.config.get('wgAction') === 'edit') {
const textbox = document.getElementById('wpTextbox1');
addClosureButton('Close as keep', 'keep');
const summaryBox = document.getElementById('wpSummary');
addClosureButton('Close as no consensus', 'no consensus');


function redirectToEdit(action) {
if (textbox) {
var page = mw.config.get('wgPageName');
const storedContent = localStorage.getItem('vfdPrefillContent');
var topText = '{{subst:vt|' + action + '. --~~~~}}\n\n';
const storedSummary = localStorage.getItem('vfdPrefillSummary');
var bottomText = '\n\n{{subst:vb}}';
var summary = 'Closed as ' + action;


// Build edit URL with prefill
if (storedContent) {
textbox.value = storedContent + textbox.value;
var editUrl = mw.util.getUrl(page, {
action: 'edit',
if (summaryBox && storedSummary) {
prefill: topText + bottomText,
summaryBox.value = storedSummary;
summary: summary
}
});


// Redirect to edit page
// Clear storage after use
localStorage.removeItem('vfdPrefillContent');
window.location.href = editUrl;
localStorage.removeItem('vfdPrefillSummary');
}
}
}
}



Revision as of 08:12, 25 September 2025

//<nowiki>
mw.loader.using('mediawiki.util', function () {
    const pagePrefix = 'User:Euphoria/TestVfD/';

    // Only run on relevant pages
    if (mw.config.get('wgPageName').startsWith(pagePrefix)) {

        // Buttons on page view
        if (mw.config.get('wgAction') === 'view') {

            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();

                    // Store the content in localStorage
                    const topText = '{{subst:vt|' + action + '. --~~~~}}\n\n';
                    const bottomText = '\n\n{{subst:vb}}';
                    const summary = 'Closed as ' + action;

                    localStorage.setItem('vfdPrefillContent', topText + bottomText);
                    localStorage.setItem('vfdPrefillSummary', summary);

                    // Redirect to edit page
                    window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' });
                });
            }

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

        }

        // On edit page: insert stored content
        if (mw.config.get('wgAction') === 'edit') {
            const textbox = document.getElementById('wpTextbox1');
            const summaryBox = document.getElementById('wpSummary');

            if (textbox) {
                const storedContent = localStorage.getItem('vfdPrefillContent');
                const storedSummary = localStorage.getItem('vfdPrefillSummary');

                if (storedContent) {
                    textbox.value = storedContent + textbox.value;
                    if (summaryBox && storedSummary) {
                        summaryBox.value = storedSummary;
                    }

                    // Clear storage after use
                    localStorage.removeItem('vfdPrefillContent');
                    localStorage.removeItem('vfdPrefillSummary');
                }
            }
        }

    }
});
//</nowiki>