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

м Отмена версии 101986, сделанной Pok (обсуждение)
Метка: отмена
м test
Метка: отменено
Строка 1352: Строка 1352:
     });
     });
}(jQuery, mediaWiki));
}(jQuery, mediaWiki));
// test
( function () {
    async function isAPNG( url ) {
        try {
            const resp = await fetch( url );
            const buf  = await resp.arrayBuffer();
            const data = new Uint8Array( buf );
            const acTL = [0x61,0x63,0x54,0x4C];
            for ( let i = 0; i < data.length - 4; i++ ) {
                if ( acTL.every( (b,j) => data[i+j] === b ) ) {
                    return true;
                }
            }
        } catch ( e ) {
            console.error( 'APNG check failed for', url, e );
        }
        return false;
    }
    $( function () {
        $( 'img[src$=".png"]' ).each( async function () {
            const $img = $( this );
            const src  = $img.attr( 'src' );
            if ( await isAPNG( src ) ) {
                const imgEl  = this;
                const canvas  = document.createElement( 'canvas' );
                canvas.width  = imgEl.naturalWidth;
                canvas.height = imgEl.naturalHeight;
                imgEl.parentNode.replaceChild( canvas, imgEl );
                canvas.getContext( '2d' ).drawImage( imgEl, 0, 0 );
            }
        } );
    } );
} )();