User:Fred Gandt/previewCategoryDupeArgs.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Fred Gandt/previewCategoryDupeArgs. |
/* 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 [[" + ctgry + "|duplicate template parameters" +
"]] using [[User:Fred Gandt/previewCategoryDupeArgs.js|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 ) );