User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
fix
Cleanup
Tag: Blanked
 
(59 intermediate revisions by the same user not shown)
Line 1: Line 1:
//<nowiki>
mw.loader.using('mediawiki.util', function () {
const pagePrefix = 'User:Euphoria/TestVfD/';

if (mw.config.get('wgPageName').startsWith(pagePrefix)) {

// Page view buttons
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();

const topText = '{{subst:vt|' + action + '. --~~~~}}\n';
const bottomText = '\n{{subst:vb}}';
const summary = 'Closed as ' + action;

localStorage.setItem('vfdPrefillContent', JSON.stringify({ top: topText, bottom: bottomText }));
localStorage.setItem('vfdPrefillSummary', summary);

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

}

// Edit page prefill
if (mw.config.get('wgAction') === 'edit') {
const textbox = document.getElementById('wpTextbox1');
const summaryBox = document.getElementById('wpSummary');

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

if (stored) {
const { top, bottom } = JSON.parse(stored);

// Remove leading/trailing blank lines from existing content
const content = textbox.value.replace(/^\s+/, '').replace(/\s+$/, '');

// Insert top + content + bottom with proper spacing
textbox.value = top + content + bottom;

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

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

}
});
//</nowiki>