User:BrownHairedGirl/CiteParamDashes.js

// Install with: // // or with //

// This script is hacked from User:DannyS712/Draft no cat.js // If forking this script, please note our contributions / give us credit

if ( mw.config.get( 'wgNamespaceNumber' ) === 0) { mw.loader.using( 'mediawiki.util', function {    $(document).ready( function  { var link = mw.util.addPortletLink( 'p-cactions', '#', 'CiteParamDashes', 'ca-citeparamdashes', 'CiteParamDashes'); $( link ).click( function ( event ) {           event.preventDefault;            tag_citeparamdashes;        } ); } ); } ); }

function tag_citeparamdashes { var edit_summary = " dashes to cite parameters accessdate, archivedate, archiveurl, (using a script) to avoid the T291704 problem with InternetArchiveBot";

var send_req = { action: 'query', titles: mw.config.get( 'wgPageName' ), prop: 'revisions', intoken: 'edit', rvprop: 'content', indexpageids: 1, dataType: 'xml', format: 'xml' };	var wgPageName = mw.config.get( 'wgPageName' ); $.get( mw.config.get( 'wgScriptPath' ) + '/api.php', send_req, function( response ) {	   var text = $( response ).find( 'rev' ).text;	    var citeParamsReplaced = 0;	    var newText = text	    		.replace(/(\|\s*)accessdate/gi, function(match, p1) { citeParamsReplaced += 1; return p1 + "access-date"; }	   			);	    newText = newText	    		.replace(/(\|\s*)archivedate/gi, function(match, p1) { citeParamsReplaced += 1; return p1 + "archive-date"; }	   			);	    newText = newText	    		.replace(/(\|\s*)archiveurl/gi, function(match, p1) { citeParamsReplaced += 1; return p1 + "archive-url"; }	   			);	if (text == newText) {		// nothing was changed		alert("No dashes need to be added to cite parameters.")		return;	}	if (confirm("" + wgPageName + ": " + citeParamsReplaced + " cite parameters lack dashes.\n\nAdd the dashes?")) {		var submit = {					action: 'edit',					pageid: mw.config.get( 'wgArticleId' ),					text: newText,					summary: "Added " + citeParamsReplaced + edit_summary,					minor: true,					token: mw.user.tokens.get( 'csrfToken' )				};	    $.when( $.post( mw.config.get( 'wgScriptPath' ) + '/api.php', submit, function( response ){ } ) ).done( function { location.reload;} );	}	} ); }