Skip to content

Instantly share code, notes, and snippets.

@jdlrobson
Created August 3, 2012 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdlrobson/3252773 to your computer and use it in GitHub Desktop.
Save jdlrobson/3252773 to your computer and use it in GitHub Desktop.
This is a hacked up greasemonkey script that navigates to problematic pages and replaces inline styles with classes - run it on a page with links to articles with inline styles 2 column layouts it will then fix those up and you simply have to click save t
// ==UserScript==
// @name Cleanup
// @namespace /
// @description aasas
// @include http://en.wikipedia.org/*
// @include http://www.mediawiki.org/wiki/List_of_Problematic_portal_pages_with_two_column_layouts
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
var ta = $( '[name=wpTextbox1]' );
if( ta.length === 0 && window.location.href.indexOf( 'mediawiki.org' ) > -1 ) {
jQuery( '#content ul a' ).each( function(i, el) {
if( $( el ).parent( 'del' ).length === 0 && !$( el ).hasClass( 'external' ) ) {
$( el ).css( 'color', 'red' );
window.open( $( el ).attr( 'href' ) + '?action=edit' );
}
} );
}
if( ta.length > 0 && $( '#wikiDiff' ).length === 0 ) {
var R = 'class="portal-column-right"',
R_narrow = 'class="portal-column-right-narrow"',
L_big = 'class="portal-column-left-wide"',
L = 'class="portal-column-left"';
ta.each( function( i, el ) {
var val = $( el ).val(), initialLength = val.length;
val = val.replace( /style\="float:right; width:43%"/g, 'class="portal-column-right"' );
val = val.replace( /style\="float:left; width:56%;"/g, 'class="portal-column-left"' );
val = val.replace( /style\="float:left; width:58%;"/g, 'class="portal-column-left"' );
val = val.replace( /style\="width:41%; float:right;"/g, 'class="portal-column-right"' );
val = val.replace( /style\="float:left; width:54%;"/g, 'class="portal-column-left"' );
val = val.replace( /style\="float:right; width:45%"/g, 'class="portal-column-right"' );
val = val.replace( /style\="float:left; width:55%;"/g, 'class="portal-column-left"' );
val = val.replace( /style\="float:right; width:44%"/g, 'class="portal-column-right"' );
val = val.replace( /style\="width:44%; float:right;"/g, 'class="portal-column-right"' );
val = val.replace( /style\="float:left; width:50%;"/g, 'class="portal-column-left"' );
val = val.replace( /style\="width:49%; float:right;"/g, 'class="portal-column-right"' );
val = val.replace( /style\="float:left; width:49%"/g, L );
val = val.replace( /style\="float:right; width:43%"/g, R );
val = val.replace( /style\="float:left; width:55%"/, L );
val = val.replace( /style\="float:right; width:50%/, R );
val = val.replace( /style\="float:left; width:45%"/, L );
val = val.replace( /style\="float:right; width:41%"/, R );
val = val.replace( /style\="float:right; width:30%"/, R_narrow );
val = val.replace( /style\="float:left; width:58%"/, L );
val = val.replace( /style\="float:right; width:41%"/, R );
val = val.replace( /style\="float:left; width:25%"/, L ); // yeh i know...
val = val.replace( /style\="float:left; width:45%/, L );
val = val.replace( /style\="float:right; width:30%"/, R_narrow );
var match = val.match( /width: ?[0-9][0-9]%/ );
if( val.length === initialLength && !match ) {
window.close();
} else if( !match ){
$( el ).val( val );
$( '#wpDiff' ).trigger( 'click' );
}
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment