User:Euphoria/common.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
fix
Cleanup
Tag: Blanked
 
(60 intermediate revisions by the same user not shown)
Line 1: Line 1:
//<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>

Latest revision as of 07:52, 3 October 2025