Jump to content

User:Frietjes/remove infoboxes.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Frietjes (talk | contribs) at 16:46, 4 February 2018. The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
// Experimental code
jQuery(document).ready(function($) {
mw.loader.using(['mediawiki.util']).done( function() {

function removeInfoboxes() {
    var tableIndex = 0;
    var infoboxBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;

    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( 'infobox' ) ) {
			var Rows = Tables[i].getElementsByTagName( 'tr' );
			for ( j = 0; j < Rows.length; j++) {
				var l = Rows[j].getElementsByTagName( 'th' )[0];
				var c = Rows[j].getElementsByTagName( 'td' )[0];
				if ( c && !l) {
					if( c.getElementsByTagName('img')[0] ) {
						var w = (c.getElementsByTagName('img')[0]).width;
						var idiv = document.createElement('div');
						idiv.className = "thumb tright";
						var d = document.createElement('div');
						d.className = "thumbinner";
						d.style.width = (w + 2) + 'px';
						d.innerHTML = c.innerHTML;
						var captions = d.getElementsByTagName('div');
						for ( k = 0; k < captions.length; k++) {
							(captions[k]).className = "thumbcaption";
						}
						idiv.appendChild(d);
						(Tables[i].parentElement).insertBefore(idiv, Tables[i]);
						break;
					}
				}
			}
			(Tables[i].parentElement).removeChild(Tables[i]);
        }
    }
}
 
$( removeInfoboxes );

});
});