User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
fix |
||
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 headings already inside a .vfd container
if ($(heading).closest('.vfd').length) return;
// Skip headings without links
if (!$(heading).find('a').length) return;
Line 16 ⟶ 20:
const actions = [
{name: 'delete', color: '#e74c3c'}, // red
{name: 'keep', color: '#27ae60'}, // green
{name: 'no consensus', color: '#f1c40f'} // yellow
];
Line 27 ⟶ 31:
// Small inline button styling
btn.style.height
btn.style.fontSize
btn.style.padding
btn.style.marginRight
btn.style.border
btn.style.borderRadius
btn.style.backgroundColor =
btn.style.color =
btn.style.cursor
btn.style.verticalAlign
btn.style.transition
btn.addEventListener('mouseenter', () => btn.style.filter='brightness(1.3)');
Line 49 ⟶ 51:
if (!confirm('Are you sure you want to close as ' + actionObj.name + '?')) return;
btn.disabled = true; // prevent double-clicks
const api = new mw.Api();
// Fetch discussion page content
api.get({
action: 'query',
Line 64 ⟶ 67:
let content = pages[pageId].revisions[0].slots.main['*'];
const
const bottomText = '\n{{subst:vb}}';
const discussionNewContent = topText + content.trim() + bottomText;
// Edit discussion page
api.postWithToken('csrf', {
action: 'edit',
Line 75 ⟶ 81:
const link = $(heading).find('a').first();
if (!link.length) {
mw.notify('Cannot find target page link!', {title: 'VfDcloser', type: 'error', timeout:
return;
}
const targetPage = link.attr('title') || link.text().trim();
if (!targetPage) {
mw.notify('Cannot determine target page title!', {title: 'VfDcloser', type: 'error', timeout:
return;
}
if (actionObj.name === 'delete') {
// Delete target page
api.postWithToken('csrf', {action: 'delete', title: targetPage, reason: '[[' + mw.config.get('wgPageName') + ']]'})
.done(() => {
const talkPage = 'Talk:' + targetPage;
// Check if talk page exists before deletion
api.get({action: 'query', titles: talkPage, format: 'json'}).done(data => {
const talkPages = data.query.pages;
Line 96 ⟶ 104:
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:
location.reload();
}).fail(err => mw.notify('Error deleting talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout:
} else {
mw.notify('Discussion closed. Page deleted.', {title: 'VfDcloser', type: 'success', timeout:
location.reload();
}
});
}).fail(err => mw.notify('Error deleting page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout:
} else {
// Keep / No consensus: update target and talk page
api.get({
action: 'query',
Line 140 ⟶ 148:
let talkContent = '';
if (talkId !== '-1' && talkPages[talkId].revisions) {
talkContent =
talkContent = '{{vfd-kept-new}}\n' + talkContent.trim();
} else {
talkContent = '{{vfd-kept-new}}';
Line 152 ⟶ 161:
minor: true
}).done(() => {
mw.notify('Discussion closed. Page and talk page updated.', {title: 'VfDcloser', type: 'success', timeout:
location.reload();
}).fail(err => mw.notify('Error editing talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout:
});
}).fail(err => mw.notify('Error editing page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout:
});
}
}).fail(err => mw.notify('Error editing discussion page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout:
});
});
| |||