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;
if (!$(heading).find('a').length) return;
Line 20 ⟶ 18:
const actions = [
{name: 'delete', color: '#e74c3c'},
{name: 'keep', color: '#27ae60'},
{name: 'no consensus', color: '#f1c40f'}
];
actions.forEach(function(actionObj) {
const btn = document.createElement('button');
btn.textContent = actionObj.name.charAt(0).toUpperCase();
btn.title = 'Close as ' + actionObj.name;
//
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;
const api = new mw.Api();
Line 67 ⟶ 65:
let content = pages[pageId].revisions[0].slots.main['*'];
const
// 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:
setTimeout(() => location.reload(),
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:
setTimeout(() => location.reload(),
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") {
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:
setTimeout(() => 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:
setTimeout(() => location.reload(),
}
});
}).fail(err => mw.notify('Error deleting page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout:
} else {
// Keep / No consensus: update
api.get({
action: 'query',
Line 164 ⟶ 159:
minor: true
}).done(() => {
mw.notify('Discussion closed. Page and talk page updated.', {title: 'VfDcloser', type: 'success', timeout:
setTimeout(() => 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:
});
});
| |||