User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
fix
fix
Line 7: Line 7:
const api = new mw.Api();
const api = new mw.Api();


// --- Universal API edit helper ---
// --- Universal API helpers ---
function apiEdit(title, content, summary, callback) {
function apiEdit(title, content, summary, callback) {
api.postWithToken('csrf', { action: 'edit', title, text: content, summary, minor: true })
api.postWithToken('csrf', { action: 'edit', title, text: content, summary, minor: true })
Line 14: Line 14:
}
}


// --- Universal delete helper ---
function apiDelete(title, reason, callback) {
function apiDelete(title, reason, callback) {
api.postWithToken('csrf', { action: 'delete', title, reason })
api.postWithToken('csrf', { action: 'delete', title, reason })
Line 21: Line 20:
}
}


// --- Fetch page content helper ---
function fetchPage(title, callback) {
function fetchPage(title, callback) {
api.get({ action: 'query', prop: 'revisions', titles: title, rvslots: 'main', rvprop: 'content', format: 'json' })
api.get({ action: 'query', prop: 'revisions', titles: title, rvslots: 'main', rvprop: 'content', format: 'json' })
Line 39: Line 37:


if (actionName === 'delete') {
if (actionName === 'delete') {
// Delete target and talk page
// Delete target page
apiDelete(targetPage, `[[${currentPage}]]`, () => {
apiDelete(targetPage, `[[${currentPage}]]`, () => {
apiDelete('Talk:' + targetPage, 'Parent page deleted via VfD', () => {
// Check if talk page exists before deleting
mw.notify('Discussion closed. Page and talk page deleted.', { title: 'VfDcloser', type: 'success', timeout: 1500 });
fetchPage('Talk:' + targetPage, talkContent => {
setTimeout(() => location.reload(), 1500);
if (talkContent) {
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 {
} else {
// Keep / No Consensus: clean target page and update talk page
// Keep / No Consensus: update target page and talk page
fetchPage(targetPage, targetContent => {
fetchPage(targetPage, targetContent => {
targetContent = targetContent.replace(/\{\{vfd-new\}\}/gi, '').trim();
targetContent = targetContent.replace(/\{\{vfd-new\}\}/gi, '').trim();
Line 105: Line 111:
btn.addEventListener('mouseenter', () => btn.style.filter = 'brightness(1.3)');
btn.addEventListener('mouseenter', () => btn.style.filter = 'brightness(1.3)');
btn.addEventListener('mouseleave', () => btn.style.filter = 'brightness(1)');
btn.addEventListener('mouseleave', () => btn.style.filter = 'brightness(1)');

btn.addEventListener('click', e => {
btn.addEventListener('click', e => {
e.preventDefault();
e.preventDefault();