[go: nahoru, domu]

Jump to content

User:Equazcion/NewSectionSummary.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.
if (  $('input[name="wpSection"][value="new"]').length > 0) { 
	preSum = $('#wpSummary').attr('value');
	
	$('#wpSummary').attr('value','').attr('name','wpSectionTitle');
	
	var summary = '<span class="mw-summary" id="wpSummaryLabel"><label for="wpSummary"><span style="text-align: left;">' + 
		'<a href="/wiki/Help:Edit_summary" title="">Edit summary</a> <small>(Briefly describe the changes you have made)' + 
		'</small></span></label></span><input id="wpSummary" class="mw-summary" name="wpSummary" value="" accesskey="b" ' + 
		'title="Enter a short summary [alt-shift-b]" spellcheck="true" size="60" tabindex="1" maxlength="255"></input>';
	$('.editOptions').prepend(summary);
	
	preSumReg = /\/\* (.*?) \*\/ (.*)/;
	var preSumRaw = preSumReg.exec(preSum);
	if (preSumRaw != null){
		
		$('[name="wpSectionTitle"]').attr('value', preSumRaw[1]);
		
		if (preSumRaw[2] == ''){ 
			$('[name="wpSummary"]').attr('value', 'new section');
		} else {
			$('[name="wpSummary"]').attr('value', preSumRaw[2]);
		}
		
		//$('.mw-content-ltr h2:first').html(preSumRaw[1]); 
	}
	
	var rawTitle = $('.mw-headline:first').html(); 
	var titleReg = /\/\* (.*?) \*\//; 
	var fixedTitle = titleReg.exec(rawTitle); 
	if (fixedTitle != null) $('.mw-headline:first').html(fixedTitle[1]); 
	
	$('#editform').submit(function(){
		var title = $('[name="wpSectionTitle"]').attr('value');
		var summary = ($('[name="wpSummary"]').attr('value') == '') ? 'new section': $('[name="wpSummary"]').attr('value');
		$('[name="wpSummary"]').attr('value', '/* ' + title + ' */ ' + summary); 
	});
}