User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
Tooltip added
mw.notify
Line 3:
const pagePrefix = 'User:Euphoria/TestVfD';
 
// Only run on relevant pages in view mode
if (!mw.config.get('wgPageName').startsWith(pagePrefix) || mw.config.get('wgAction') !== 'view') return;
 
Line 9 ⟶ 10:
const heading = this;
 
// Skip ifheadings wrappedalready inside a .vfd container
if ($(heading).closest('.vfd').length) return;
 
// Skip ifheadings nowithout wikilinks in this headinglinks
if (!$(heading).find('a').length) return;
 
Line 27 ⟶ 28:
const btn = document.createElement('button');
btn.textContent = actionObj.name.charAt(0).toUpperCase(); // D/K/N
btn.title = 'Close as ' + actionObj.name;
 
// Ultra-smallSmall inline button styling
btn.style.width = '16px';
btn.style.height = '16px';
Line 50 ⟶ 51:
if (!confirm('Are you sure you want to close as ' + actionObj.name + '?')) return;
 
//btn.disabled Disable= buttontrue; to// prevent double -clicks
btn.disabled = true;
 
const api = new mw.Api();
 
// Step 1: GetFetch discussion page content
api.get({
action: 'query',
Line 72 ⟶ 71:
const discussionNewContent = topText + content.trim() + bottomText;
 
// Step 2: Edit discussion page
api.postWithToken('csrf', {
action: 'edit',
Line 82 ⟶ 81:
const link = $(heading).find('a').first();
if (!link.length) {
alertmw.notify('Cannot find target article link!', in{title: heading!'VfDcloser', type: 'error'});
location.reload();
return;
Line 89 ⟶ 88:
 
if (actionObj.name === 'delete') {
// Delete target article and talk page
api.postWithToken('csrf', {action: 'delete', title: targetPage, reason: '[[' + mw.config.get('wgPageName') + ']]'})
.done(() action:=> 'delete',{
title const talkPage = 'Talk:' + targetPage,;
reason: '[[' + mwapi.config.getpostWithToken('wgPageNamecsrf'), +{action: ']]delete', title: talkPage, reason: 'Parent page deleted via VfD'})
}) .done(() => {
const talkPage = mw.notify('Talk:Discussion closed and "' + targetPage + '" deleted with talk page.', {title: 'VfDcloser', type: 'success'});
api location.postWithTokenreload('csrf', {);
action }).fail(err => mw.notify('Error deleting talk page: 'delete + JSON.stringify(err), {title: 'VfDcloser', type: 'error'}));
}).fail(err => mw.notify('Error deleting page: ' + JSON.stringify(err), {title: talkPage'VfDcloser', type: 'error'}));
reason: 'Parent page deleted via VfD'
}).done(() => {
alert('Discussion closed and "' + targetPage + '" along with its talk page deleted.');
location.reload();
}).fail(err => alert('Error deleting talk page: ' + err));
}).fail(err => alert('Error deleting page: ' + err));
} else {
// Keep / No consensus: update target and talk page
api.get({
action: 'query',
Line 154 ⟶ 147:
minor: true
}).done(() => {
alertmw.notify('Discussion closed and "' + targetPage + '" updated. Talk page updated.', {title: 'VfDcloser', type: 'success'});
location.reload();
}).fail(err => alertmw.notify('Error editing talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'}));
});
}).fail(err => alertmw.notify('Error editing article: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'}));
});
}
}).fail(err => alertmw.notify('Error editing discussion page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error'}));
});
});