User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix Tag: Reverted |
fix Tag: Reverted |
||
Line 3:
const pagePrefix = 'User:Euphoria/TestVfD';
if (!mw.config.get('wgPageName').startsWith(pagePrefix) || mw.config.get('wgAction') !== 'view') return;
$(async function () {
$('#mw-content-text').find('h2, h3').each(function () {
const heading = this;
Line 13 ⟶ 14:
if ($(heading).closest('.vfd').length) return;
// Collect section text (everything until next h2/h3)
let sectionText = '';
sectionText +=
}▼
// Only add buttons if section contains [[TargetPage]] link
▲ if (!sectionText.match(/\[\[([^\]]+)\]\]/)) return;
const container = document.createElement('span');
container.style.marginLeft = '6px';
const actions = [
{ name: 'delete', color: '#e74c3c' }, // red
{ name: 'keep', color: '#27ae60' }, // green
{ name: 'no consensus', color: '#f1c40f' } // yellow
];
actions.forEach
const btn = document.createElement('button');
btn.textContent = actionObj.name.charAt(0).toUpperCase(); // D/K/N
// Ultra-small styling▼
Object.assign(btn.style, {
width: '16px',
Line 55 ⟶ 56:
});
// Hover effect▼
btn.addEventListener('mouseenter', () => btn.style.filter = 'brightness(1.3)');
btn.addEventListener('mouseleave', () => btn.style.filter = 'brightness(1)');
e.preventDefault();
if (!confirm('Are you sure you want to close as ' + actionObj.name + '?')) return;
buttons.forEach(b => b.disabled = true);
btn.textContent = '…'; // processing indicator
const data = await api.get({▼
action: 'query',▼
prop: 'revisions',▼
titles: mw.config.get('wgPageName'),▼
rvprop: 'content',▼
format: 'json'▼
});▼
▲ // Step 1: Get discussion page content
▲ api.get({
▲ action: 'query',
▲ prop: 'revisions',
▲ titles: mw.config.get('wgPageName'),
▲ rvprop: 'content',
▲ format: 'json'
}).done(function (data) {▼
const pages = data.query.pages;
const pageId = Object.keys(pages)[0];
let content = pages[pageId].revisions[0]['*'];
const discussionNewContent = `{{subst:vt|${actionObj.name}. --~~~~}}\n${content.trim()}\n{{subst:vb}}`;
//
// Step 2: Edit discussion page▼
action: 'edit',
title: mw.config.get('wgPageName'),
Line 91 ⟶ 90:
minor: true,
bot: true
})
alert('Cannot find target article in heading!');▼
▲ return;
// 3️⃣ Handle target
if (actionObj.name === 'delete')
} else
}
▲ });
buttons.forEach(b => b.textContent = b.textContent.charAt(0).toUpperCase());
});
container.appendChild(btn);
});
Line 116 ⟶ 113:
});
//
async function deletePageAndTalk(api, targetPage) {
});
const talkPage = 'Talk:' + targetPage;
await api.postWithToken('csrf', {
action: 'delete',
title: talkPage,
reason: 'Parent page deleted via VfD closure [[' + mw.config.get('wgPageName') + ']]',
bot: true
})
alert('Discussion closed and "'
}
▲ }
}
async function keepOrNoConsensus(api, targetPage, actionName) {▼
try {
▲ function keepOrNoConsensus(api, targetPage, actionName) {
}).done(function (articleData) {▼
const articlePages = articleData.query.pages;
const articleId = Object.keys(articlePages)[0];
Line 152 ⟶ 153:
articleContent = articleContent.replace(/\{\{vfd-new\}\}/gi, '').trim();
await api.postWithToken('csrf', {
action: 'edit',
title: targetPage,
Line 159 ⟶ 160:
minor: true,
bot: true
})
▲ .fail(err => alert('Error editing article: ' + err));
}
}
async function updateTalkPage(api, targetPage, actionName) {
const talkPage = 'Talk:' + targetPage;
const talkData = await api.get({
action: 'query',
prop: 'revisions',
titles: talkPage,
rvprop: 'content',
format: 'json'
const talkPages = talkData.query.pages;
const talkId = Object.keys(talkPages)[0];
Line 184 ⟶ 190:
}
await api.postWithToken('csrf', {
action: 'edit',
title: talkPage,
Line 191 ⟶ 197:
minor: true,
bot: true
})
alert('Discussion closed and "'
▲ });
} catch (err) {
alert('Error editing talk page: ' + err);
}
}
});
});
| |||