User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
Undo revision 66512 by Euphoria (talk)
Tag: Undo
No edit summary
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)
// Look for all h2 headings (works on both main page and subpages)
$('#mw-content-text').find('h2').each(function () {
$('#mw-content-text').find('h2').each(function () {
const headingText = $(this).text().trim();
const heading = $(this);
if (!headingText) return;
const link = heading.find('a').first();


let targetPage = headingText;
// Only add buttons if the heading contains a link
if (!link.length) return;

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


const targetPage = link.attr('title'); // Use the linked page as target
createButtonsForHeading(this, targetPage);
createButtonsForHeading(this, targetPage);
});
});