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
Object.assign(btn.style,.width = {'16px';
btn.style.height width:= '16px',;
btn.style.fontSize height:= '16px65%',;
btn.style.padding fontSize:= '65%0',;
btn.style.marginRight padding:= '03px',;
btn.style.border marginRight:= '3pxnone',;
btn.style.borderRadius border:= 'none2px',;
btn.style.backgroundColor = borderRadius: '2px',actionObj.color;
btn.style.color = backgroundColor: actionObj.color,'#fff';
btn.style.cursor color:= '#fffpointer',;
btn.style.verticalAlign cursor:= 'pointermiddle',;
btn.style.transition verticalAlign:= 'middle0.15s',;
transition: '0.15s'
});
 
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 discussionNewContenttopText = '{{subst:vt|' + actionObj.name + '. --~~~~}}\n' + content.trim() + '\n{{subst:vb}}';
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: 35005000});
return;
}
 
const targetPage = link.attr('title') || link.text().trim();
if (!targetPage) {
mw.notify('Cannot determine target page title!', {title: 'VfDcloser', type: 'error', timeout: 35005000});
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: 35005000});
location.reload();
}).fail(err => mw.notify('Error deleting talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 35005000}));
} else {
mw.notify('Discussion closed. Page deleted.', {title: 'VfDcloser', type: 'success', timeout: 35005000});
location.reload();
}
});
}).fail(err => mw.notify('Error deleting page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 35005000}));
} 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 = '{{vfd-kept-new}}\n' + talkPages[talkId].revisions[0].slots.main['*'].trim();
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: 35005000});
location.reload();
}).fail(err => mw.notify('Error editing talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 35005000}));
});
}).fail(err => mw.notify('Error editing page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 35005000}));
});
}
}).fail(err => mw.notify('Error editing discussion page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 35005000}));
});
});