User:Ricewind/common.js: Difference between revisions

From Melvor Idle
No edit summary
No edit summary
Line 3: Line 3:


     // Function to get the introductory paragraph
     // Function to get the introductory paragraph
    function getIntroText(content) {
function getIntroText(content) {
        var $content = $('<div>').html(content);
    var $content = $('<div>').html(content);
        // Remove everything after the first paragraph
    // Try to find the first paragraph or other elements
        var $paragraphs = $content.find('p');
    var $intro = $content.find('p, ul, ol, table').first();
        if ($paragraphs.length > 0) {
    if ($intro.length > 0) {
            return $paragraphs.first().html();
        return $intro.html();
        }
        return '';
     }
     }
    // If no suitable content is found, return a default message
    return '<p>No introductory text available.</p>';
}


     // Modify the popup content
     // Modify the popup content

Revision as of 13:09, 19 July 2024

mw.hook('pp.render').add(function(popup) {
    var $popupContent = popup.$body;

    // Function to get the introductory paragraph
function getIntroText(content) {
    var $content = $('<div>').html(content);
    // Try to find the first paragraph or other elements
    var $intro = $content.find('p, ul, ol, table').first();
    if ($intro.length > 0) {
        return $intro.html();
    }
    // If no suitable content is found, return a default message
    return '<p>No introductory text available.</p>';
}

    // Modify the popup content
    var introText = getIntroText($popupContent.html());
    $popupContent.html(introText);
});