User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
fix
fix
Line 10:
const heading = this;
 
// Skip headings already inside a .vfd container or without links
if ($(heading).closest('.vfd').length) return;
 
// Skip headings without links
if (!$(heading).find('a').length) return;
 
Line 20 ⟶ 18:
 
const actions = [
{name: 'delete', color: '#e74c3c'}, // red
{name: 'keep', color: '#27ae60'}, // green
{name: 'no consensus', color: '#f1c40f'} // yellow
];
 
actions.forEach(function(actionObj) {
const btn = document.createElement('button');
btn.textContent = actionObj.name.charAt(0).toUpperCase(); // D/K/N
btn.title = 'Close as ' + actionObj.name;
 
// Small inline buttonButton styling
btn.style.width = '16px';
btn.style.height = '16px';
Line 51 ⟶ 49:
if (!confirm('Are you sure you want to close as ' + actionObj.name + '?')) return;
 
btn.disabled = true; // prevent double-clicks
const api = new mw.Api();
 
Line 67 ⟶ 65:
let content = pages[pageId].revisions[0].slots.main['*'];
 
const topTextdiscussionNewContent = '{{subst:vt|' + actionObj.name + '. --~~~~}}\n' + content.trim() + '\n{{subst:vb}}';
const bottomText = '\n{{subst:vb}}';
const discussionNewContent = topText + content.trim() + bottomText;
 
// Edit discussion page
Line 81 ⟶ 77:
const link = $(heading).find('a').first();
if (!link.length) {
mw.notify('Cannot find target page link!', {title: 'VfDcloser', type: 'error', timeout: 20001500});
setTimeout(() => location.reload(), 20001500);
return;
}
Line 88 ⟶ 84:
const targetPage = link.attr('title') || link.text().trim();
if (!targetPage) {
mw.notify('Cannot determine target page title!', {title: 'VfDcloser', type: 'error', timeout: 20001500});
setTimeout(() => location.reload(), 20001500);
return;
}
Line 98 ⟶ 94:
.done(() => {
const talkPage = 'Talk:' + targetPage;
 
// Check if talk page exists
api.get({action: 'query', titles: talkPage, format: 'json'}).done(data => {
const talkPages = data.query.pages;
Line 105 ⟶ 99:
 
if (talkId !== "-1") {
// Check ifDelete talk page if exists
api.postWithToken('csrf', {action: 'delete', title: talkPage, reason: 'Parent page deleted via VfD'})
.done(() => {
mw.notify('Discussion closed. Page and talk page deleted.', {title: 'VfDcloser', type: 'success', timeout: 20001500});
setTimeout(() => location.reload(), 20001500);
}).fail(err => mw.notify('Error deleting talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 50001500}));
} else {
mw.notify('Discussion closed. Page deleted.', {title: 'VfDcloser', type: 'success', timeout: 20001500});
setTimeout(() => location.reload(), 20001500);
}
});
}).fail(err => mw.notify('Error deleting page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 50001500}));
} else {
// Keep / No consensus: update targetpage and talk page
api.get({
action: 'query',
Line 164 ⟶ 159:
minor: true
}).done(() => {
mw.notify('Discussion closed. Page and talk page updated.', {title: 'VfDcloser', type: 'success', timeout: 20001500});
setTimeout(() => location.reload(), 20001500);
}).fail(err => mw.notify('Error editing talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 50001500}));
});
}).fail(err => mw.notify('Error editing page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 50001500}));
});
}
}).fail(err => mw.notify('Error editing discussion page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 50001500}));
});
});