User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
No edit summary
Tag: Manual revert
fix
Line 4: Line 4:
const currentPage = mw.config.get('wgPageName').replace(/_/g, ' ');
const currentPage = mw.config.get('wgPageName').replace(/_/g, ' ');


if (!currentPage.startsWith(pagePrefix + '/') || mw.config.get('wgAction') !== 'view') return;
if ((!currentPage.startsWith(pagePrefix + '/') && currentPage !== pagePrefix) || mw.config.get('wgAction') !== 'view') return;


const api = new mw.Api();
const api = new mw.Api();
Line 33: Line 33:
// Handle VfD action for a target page
// Handle VfD action for a target page
function handleAction(targetPage, actionName) {
function handleAction(targetPage, actionName) {
// 🔹 if we are on the main VfD page, close the subpage instead
apiHelper.fetch(currentPage, discussionContent => {
const pageToEdit = (currentPage === pagePrefix) ? pagePrefix + '/' + targetPage : currentPage;
// Prompt user for an optional comment

apiHelper.fetch(pageToEdit, discussionContent => {
const userComment = prompt('Add an additional comment (optional):', '');
const userComment = prompt('Add an additional comment (optional):', '');
const commentText = userComment ? ` ${userComment}` : '';
const commentText = userComment ? ` ${userComment}` : '';
Line 40: Line 42:
const newDiscussion = `{{subst:vt|${actionName}.${commentText} --~~~~}}\n${discussionContent}\n{{subst:vb}}`;
const newDiscussion = `{{subst:vt|${actionName}.${commentText} --~~~~}}\n${discussionContent}\n{{subst:vb}}`;


apiHelper.edit(currentPage, newDiscussion, `Closed as ${actionName} ([[User:Euphoria/VfDcloser|VfDcloser]])`, () => {
apiHelper.edit(pageToEdit, newDiscussion, `Closed as ${actionName} ([[User:Euphoria/VfDcloser|VfDcloser]])`, () => {
if (actionName === 'delete') {
if (actionName === 'delete') {
deletePageAndTalk(targetPage);
deletePageAndTalk(targetPage);
Line 164: Line 166:
if (categories.includes('VfD archive entries')) return;
if (categories.includes('VfD archive entries')) return;


if (currentPage === pagePrefix) {
$('#mw-content-text').find('h2').each(function () {
// 🔹 Main page: attach buttons to transcluded discussions
const headingText = $(this).text().trim();
$('#mw-content-text').find('.mw-transclusion').each(function () {
if (!headingText) return;
createButtonsForHeading(this, headingText);
const link = $(this).find('a').first().attr('title');
if (link && link.startsWith(pagePrefix + '/')) {
});
const targetPage = link.replace(pagePrefix + '/', '');
const heading = $(this).find('h2').first()[0];
if (heading) {
createButtonsForHeading(heading, targetPage);
}
}
});
} else {
// 🔹 Subpages: original behavior
$('#mw-content-text').find('h2').each(function () {
const headingText = $(this).text().trim();
if (!headingText) return;
createButtonsForHeading(this, headingText);
});
}
});
});
});
});