User:Euphoria/common.js: Difference between revisions
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 () { |
||
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') { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
// Store the content in localStorage |
|||
const topText = '{{subst:vt|' + action + '. --~~~~}}\n\n'; |
|||
| ⚫ | |||
| ⚫ | |||
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 no consensus', 'no consensus'); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
redirectToEdit(action); |
|||
| ⚫ | |||
} |
} |
||
// |
// 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; |
|||
var editUrl = mw.util.getUrl(page, { |
|||
if (summaryBox && storedSummary) { |
|||
summaryBox.value = storedSummary; |
|||
} |
|||
| ⚫ | |||
// |
// 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>