Jump to content

User:Frietjes/remove infoboxes.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 16:35, 4 February 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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' ) ) {
        	// (Tables[i].parentElement).insertBefore(Tables[i], document.createTextNode("FOOBAR"));
			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]).getAttribute('width');
						var idiv = document.createElement('div');
						idiv.className("thumb tright");
						var d = document.createElement('div');
						d.className = "thumbinner";
						d.innerHTML = c.innerHTML;
						idiv.appendChild(d);
						(Tables[i].parentElement).insertBefore(idiv, Tables[i]);
						break;
					}
				}
			}
			(Tables[i].parentElement).removeChild(Tables[i]);
        }
    }
}
 
$( removeInfoboxes );

});
});