User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
fix
No edit summary
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
// If on main page, close the subpage instead
const pageToEdit = (currentPage === pagePrefix) ? pagePrefix + '/' + targetPage : currentPage;
const pageToEdit = (currentPage === pagePrefix) ? pagePrefix + '/' + targetPage : currentPage;


Line 166: Line 166:
if (categories.includes('VfD archive entries')) return;
if (categories.includes('VfD archive entries')) return;


// ✅ Look for all h2 headings (works on both main page and subpages)
if (currentPage === pagePrefix) {
$('#mw-content-text').find('h2').each(function () {
// 🔹 Main page: attach buttons to transcluded discussions
$('#mw-content-text').find('.mw-transclusion').each(function () {
const headingText = $(this).text().trim();
if (!headingText) return;

let targetPage = headingText;

// On main page, detect the linked subpage if heading contains a link
if (currentPage === pagePrefix) {
const link = $(this).find('a').first().attr('title');
const link = $(this).find('a').first().attr('title');
if (link && link.startsWith(pagePrefix + '/')) {
if (link && link.startsWith(pagePrefix + '/')) {
const targetPage = link.replace(pagePrefix + '/', '');
targetPage = link.replace(pagePrefix + '/', '');
const heading = $(this).find('h2').first()[0];
if (heading) {
createButtonsForHeading(heading, targetPage);
}
}
}
});
}

} else {
createButtonsForHeading(this, targetPage);
// 🔹 Subpages: original behavior
});
$('#mw-content-text').find('h2').each(function () {
const headingText = $(this).text().trim();
if (!headingText) return;
createButtonsForHeading(this, headingText);
});
}
});
});
});
});