User:Fred Gandt/previewCategoryDupeArgs.js

/* EXPERIMENTAL IN DEVELOPMENT - USE WITH CAUTION! */

( function( DOM_w, DOM_d ) {	var ctgry = "Category:Pages_using_duplicate_arguments_in_template_calls",		smmry = "Removed first instances of duplicate template parameters" +			" using previewCategoryDupeArgs.js (alpha in development)",		eById = function( id ) { return DOM_d.getElementById( id ); };	$( DOM_d ).ready( function { var WP_summary = eById( "wpSummary" ); if ( mw.config.get( "wgPageName" ) === ctgry ) { var trgts = [].slice.call( DOM_d.getElementById( "mw-pages" ).getElementsByClassName( "mw-content-ltr" )[ 0 ].getElementsByTagName( "a" ) ), trgt, ctrgt, smmrycmpnnt = encodeURIComponent( smmry ), urls = location.origin + "/w/index.php?title=", urle = "&action=edit&preview=yes&summary=" + smmrycmpnnt; for ( trgt in trgts ) { ctrgt = trgts[ trgt ]; ctrgt.href = urls + mw.util.wikiUrlencode( ctrgt.textContent ) + urle; ctrgt.setAttribute( "target", "_blank" ); }		} else if ( WP_summary && WP_summary.value === smmry ) { var prvwnt = DOM_d.getElementsByClassName( "previewnote" )[ 0 ], wrnngs = prvwnt.getElementsByTagName( "p" ); if ( wrnngs[ 1 ] ) { var txtbx = eById( "wpTextbox1" ), raw = txtbx.value, wrnng, cwrnng, mtch, tmplt, dplct, pttrn, ndx, subbfr, subftr, offndr; prvwnt.removeChild( wrnngs[ 0 ] ); prvwnt.removeChild( prvwnt.getElementsByTagName( "hr" )[ 0 ] ); prvwnt.removeChild( eById( "mw-previewheader" ) ); eById( "wikiEditor-ui-toolbar" ).appendChild( prvwnt ); eById( "wpMinoredit" ).checked = true; eById( "editform" ).scrollIntoView; for ( wrnng in wrnngs ) { if ( wrnngs.hasOwnProperty( wrnng ) ) { cwrnng = wrnngs[ wrnng ]; cwrnng.style = "text-indent:1em;"; tmplt = ( /Template:([^]+)$/gi ).exec( cwrnng.getElementsByTagName( "a" )[ 0 ].title )[ 1 ].toLowerCase; dplct = ( /"([^"]+)/gi ).exec( cwrnng.textContent )[ 1 ].toLowerCase; pttrn = new RegExp( "(\\{\\{\\s*" + tmplt + "[^\\}]+?(\\|\\s*" + dplct + "\\s*\\=[^\\|\\}]+?)\\|[^\\}]*?\\|[^\\w\\d]*?" + dplct + "\\s*\\=[^]+?\\}\\})", "gi" ); while ( !!( mtch = pttrn.exec( raw ) ) ) { nst = mtch[ 1 ]; offndr = mtch[ 2 ]; ndx = mtch.index + nst.indexOf( offndr ); if ( confirm( offndr + "\n\n" + nst + "\n\n" ) ) { subbfr = raw.substr( 0, ndx ); subftr = raw.substr( ndx + offndr.length ); txtbx.value = subbfr + subftr; }						}					}				}			}		}	} ); } ( window, document ) );