MediaWiki:Gadget-AbsyFancyBoxy.js: различия между версиями

Нет описания правки
А если через утилиту /n?
Строка 37: Строка 37:
         if ( w === 0 && h === 0 ) return false;
         if ( w === 0 && h === 0 ) return false;
         return w < MIN_IMAGE_SIZE && h < MIN_IMAGE_SIZE;
         return w < MIN_IMAGE_SIZE && h < MIN_IMAGE_SIZE;
    }
    // Извлекаем текст подписи, сохраняя <br> как \n (без innerHTML)
    function getCaptionText( el ) {
        var clone = el.cloneNode( true );
        // Заменяем <br> на текстовый маркер переноса
        clone.querySelectorAll( 'br' ).forEach( function ( br ) {
            br.replaceWith( document.createTextNode( '\n' ) );
        } );
        return clone.textContent
            .replace( /\s+/g, ' ' )
            .replace( /\s*\n\s*/g, '\n' )
            .trim();
     }
     }


Строка 44: Строка 57:
             var galleryText = galleryItem.querySelector( '.gallerytext' );
             var galleryText = galleryItem.querySelector( '.gallerytext' );
             if ( galleryText && galleryText.textContent.trim() ) {
             if ( galleryText && galleryText.textContent.trim() ) {
                 return galleryText.textContent.trim();
                 return getCaptionText( galleryText );
             }
             }
         }
         }
Строка 51: Строка 64:
             var thumbCaption = container.querySelector( '.thumbcaption, figcaption' );
             var thumbCaption = container.querySelector( '.thumbcaption, figcaption' );
             if ( thumbCaption && thumbCaption.textContent.trim() ) {
             if ( thumbCaption && thumbCaption.textContent.trim() ) {
                 return thumbCaption.textContent.trim();
                 return getCaptionText( thumbCaption );
             }
             }
         }
         }
Строка 265: Строка 278:
         imgElement.alt = item.caption || '';
         imgElement.alt = item.caption || '';


         // Подпись: поддерживаем <br> без innerHTML (безопасно от XSS)
         // Подпись: переносы \n превращаем в настоящие <br> (безопасно)
         captionElement.textContent = '';
         captionElement.textContent = '';
         var captionText = item.caption || '';
         var captionText = item.caption || '';
         if ( captionText ) {
         if ( captionText ) {
             var parts = captionText.split( /<br\s*\/?>/i );
             var parts = captionText.split( '\n' );
             parts.forEach( function ( part, i ) {
             parts.forEach( function ( part, i ) {
                 if ( i > 0 ) captionElement.appendChild( document.createElement( 'br' ) );
                 if ( i > 0 ) captionElement.appendChild( document.createElement( 'br' ) );