User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
fix |
||
Line 7:
const api = new mw.Api();
// --- Universal API
function apiEdit(title, content, summary, callback) {
api.postWithToken('csrf', { action: 'edit', title, text: content, summary, minor: true })
Line 14:
}
function apiDelete(title, reason, callback) {
api.postWithToken('csrf', { action: 'delete', title, reason })
Line 21 ⟶ 20:
}
function fetchPage(title, callback) {
api.get({ action: 'query', prop: 'revisions', titles: title, rvslots: 'main', rvprop: 'content', format: 'json' })
Line 39 ⟶ 37:
if (actionName === 'delete') {
// Delete target
apiDelete(targetPage, `[[${currentPage}]]`, () => {
apiDelete('Talk:' + targetPage, 'Parent page deleted via VfD', () => {
mw.notify('Discussion closed. Page and talk page deleted.', { title: 'VfDcloser', type: 'success', timeout: 1500 });
setTimeout(() => location.reload(), 1500);
});
} else {
mw.notify('Discussion closed. Page deleted.', { title: 'VfDcloser', type: 'success', timeout: 1500 });
setTimeout(() => location.reload(), 1500);
}
});
});
} else {
// Keep / No Consensus:
fetchPage(targetPage, targetContent => {
targetContent = targetContent.replace(/\{\{vfd-new\}\}/gi, '').trim();
Line 105 ⟶ 111:
btn.addEventListener('mouseenter', () => btn.style.filter = 'brightness(1.3)');
btn.addEventListener('mouseleave', () => btn.style.filter = 'brightness(1)');
btn.addEventListener('click', e => {
e.preventDefault();
| |||