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.
///////////////////////////////////////////////////////////////////////////////
//    This code is cobbled together from various examples and libraries.     //
//It is not designed for use by any other user, as some things are hardcoded.//
//               There's probably a better way of doing this.                //
///////////////////////////////////////////////////////////////////////////////

/* This section adds a toolbox link to file pages. */
mw.loader.using( 'mediawiki.util', function () {

    // Wait for the page to be parsed
	$(document).ready( function () { 
		if ( mw.config.get( 'wgCanonicalNamespace' ) === 'File') {
	        var acmtcLink = mw.util.addPortletLink( 'p-tb', '#', 'Commons Ready', 'ca-acmtc', 'Mark for Commons'); 
	        $( acmtcLink ).click( function ( event ) {
	            event.preventDefault();
	            editPage({
					title: mw.config.get( 'wgPageName' ),
					text: '{'+"{Copy to Wikimedia Commons|human=AntiCompositeNumber}} \n",
					summary: 'Preparing to move to Commons using [[User:AntiCompositeNumber/quicktag.js]]'
				});
	        });
	    }
	});
});
/* This section uses AJAX to add <nowiki>{{Copy to Wikimedia Commons|human=AntiCompositeNumber}}</nowiki> to the page when the link is clicked */ 
function editPage( info ) {
	$.ajax({
		url: mw.util.wikiScript( 'api' ),
		type: 'POST',
		dataType: 'json',
		data: {
			format: 'json',
			action: 'edit',
			title: info.title,
			prependtext: info.text,
			summary: info.summary,
			token: mw.user.tokens.get( 'editToken' )
		}
	})
	.done (function( data ) {
		if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
			patrolPage();
			setTimeout(function(){ location.reload(); }, 3000);

		} else {
			alert( 'The edit query returned an error. =(' );
		}
	})
	.fail ( function() {
		alert( 'The ajax request failed.' );
	});
}
/* The page is patrolled for good measure. 
This section taken from Twinkle's library. */
var patrolPage = function() {
	// There's no patrol link on page, so we can't patrol
	if ( !$( '.patrollink' ).length ) {
		return;
	}

	// Extract the rcid token from the "Mark page as patrolled" link on page
	var patrolhref = $( '.patrollink a' ).attr( 'href' ),
		rcid = mw.util.getParamValue( 'rcid', patrolhref );

	if ( rcid ) {

		var patrolstat = new Morebits.status( 'Marking page as patrolled' );

		var wikipedia_api = new Morebits.wiki.api( 'doing...', {
			action: 'patrol',
			rcid: rcid,
			token: mw.user.tokens.get( 'patrolToken' )
		}, null, patrolstat );

		// We don't really care about the response
		wikipedia_api.post();
	}
};