User:Sohom Datta/page-status-highlighter.js

(function {

function load { var $anchorTagsJquery = $( '.mw-datatable > tbody > tr > td.TablePager_col_title > a:nth-child(1)' ); var pageList = []; var $anchorTags = $anchorTagsJquery.toArray; $anchorTags.forEach( function ( elem ) {           pageList.push( $( elem ).attr( 'title' ) );        }.bind( this )    ); var api = new mw.Api; var chunkedArray = []; for ( var i = 0; i < pageList.length; i += 50 ) { chunkedArray.push( pageList.slice( i, i + 50 ) ); }

for ( var i = 0; i < chunkedArray.length; i++ ) { var chunk = chunkedArray[i]; api.post( {           action: 'query',            prop: 'proofread',            titles: chunk.join( '|' ),            formatversion: 2,            format: 'json'        } ).done( function ( data ) {            var pages = data.query.pages;            for ( var i = 0; i < pages.length; i++ ) {                var page = pages[i];                if ( page.proofread ) {                    var $selectedAnchorTags = $anchorTags.filter( function ( elem ) { return $( elem ).attr( 'title' ) === page.title; } );                   for ( var j = 0; j < $selectedAnchorTags.length; j++ ) {                        var $anchorTag = $selectedAnchorTags[j];                        var $td = $anchorTag.parentElement;                        if ( page.proofread.quality === 4 ) {                            $td.style.backgroundColor = '#90ff90';                        } else if ( page.proofread.quality === 3 ) {                            $td.style.backgroundColor = '#ffe867';                        } else if ( page.proofread.quality === 2 ) {                            $td.style.backgroundColor = '#b0b0ff';                        } else if ( page.proofread.quality === 1 ) {                            $td.style.backgroundColor = '#ffa0a0';                        } else {                            $td.style.backgroundColor = '#ddd';                        }                    }                } }       }.bind( this ) );    } } mw.loader.using( 'mediawiki.api' ).then( function  { if ( mw.config.get( 'wgPageName' ).startsWith( 'Special:LintErrors' ) ) { window.addEventListener( 'load', function {            load;        } ); if ( document.readyState === 'complete' || document.readyState === 'interactive' ) { load; }   } } );

} );