Jump to content

User:Alex Great/common.js

From Wikipedia, the free encyclopedia
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.
//<nowiki>
/* Кнопки для описания правки */

function insertSummary ( txt ) {
	if ( typeof txt !== 'string' ) {
		txt = this.title;
	}
	var vv = $( '#wpSummary' ).val();
	if ( vv.indexOf( txt ) !== -1 ) {
		return;
	}
	if ( /[^,; \/]$/.test( vv ) ) {
		vv += ',';
	}
	if ( /[^ ]$/.test( vv ) ) {
		vv += ' ';
	}
	$( '#wpSummary' ).val( vv + txt );
}
 
function addSumButton ( btn, txt ) {
	$( '<a title="' + txt + '">' + btn + '</a>' )
		.appendTo( '#userSummaryButtonsA' )
		.click( insertSummary );
}
 
$( function() {
	var frm = document.getElementById( 'editform' );
	if ( !mw.config.get( 'wgArticleId' ) || !frm || $( frm.wpSection ).val() === 'new' ) {
		return;
	}
	mw.util.addCSS( '\
		input#wpSummary { margin-bottom: 0 }\
		#userSummaryButtonsA a { background:#cef; border:1px solid #adf; padding:0 2px;\
			margin:0 2px;cursor:pointer; font-size:86%; color:#666 }\
		#userSummaryButtonsA a:hover { background:#bdf; color:black; text-decoration:none }' );
	$( '<div id=userSummaryButtonsA />' ).insertAfter( '#wpSummary' );
	$.each(
		[
		'wiki|fication', 'stylization', 'minor| changes', 'ortho|graphy',
		'punctu|ation', 'reply', 'comment|ary', 'cat|egory', 'templat|ization', 'doc|umentation', 'deletion',
		'illustration', 'add|ition', 'specification', 'update', 'interwiki', 'vandalism'
		],
		function ( i, s ) {
			addSumButton( s.replace( /\|.*/, '' ), s.replace( /\|/, '' ) );
		}
	);
} );
//</nowiki>