Jump to content

User:Fred Gandt/moveFailedModuleTestsToTop.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$( document ).ready( () => {
	"use strict";
	if ( mw.config.get( "wgNamespaceNumber" ) == 829 ) {
		// get all results tables
		const ALL_RESULTS = Array.from( document.querySelectorAll( ".wikitable.unit-tests-result" ) );
		if ( ALL_RESULTS.length ) {
			console.log( "ALL_RESULTS: ", ALL_RESULTS );
			// get contiguous blocks of result tables
			const BLOCKS = [];
			ALL_RESULTS.forEach( ( table, i ) => {
				if ( !~ALL_RESULTS.indexOf( table.nextElementSibling ) ) {
					BLOCKS.push( [ ...ALL_RESULTS.splice( 0, i + 1 ) ] );
				}
			} );
			console.log( "BLOCKS: ", BLOCKS );
			BLOCKS.forEach( block => {
				block.forEach( result => {
					if ( result.querySelector( 'img[alt]:not([alt="check"])' ) ) {
						block[ 0 ].before( result );
					}
				} );
			} );
		}
	}
} );