MediaWiki:Gadget-newTopicOnTop.js
Билгалдаккхар: Ӏалашйинчул тӀаьхьа браузеран кеш дӀайаккха йезаш хила мега, хийцамаш ган.
- Firefox / Safari: ГӀирсийн панелехь Shift-дӀа а лаьцна Керладаккхар тӀетаӀайе, йа Ctrl+F5 йаCtrl+R (Mac-хь ⌘+R) тӀетаӀайе.
- Google Chrome:Ctrl+Shift+R тӀетаӀайе (⌘+Shift+R Mac тӀехь)
- Edge: Ctrl дӀа а лаьцна, Refresh тӀе Ӏоттало йа Ctrl+F5 тӀе Ӏоттало.
- Opera: Ctrl+F5 тӀетаӀайе.
( function () {
var isVe = false;
function main() {
var decodedQuery, textboxContent, textboxContentWithoutComments,
$textbox = $( '#wpTextbox1' ),
$summary = $( '#wpSummary' ),
summary = $summary.val();
function transferHeadingToSummary() {
var matches, heading, summary,
textboxContent = $textbox.textSelection( 'getContents' );
// Remove HTML comments
textboxContent = textboxContent && textboxContent.replace( /<!--[^]*?-->/g, '' );
matches = textboxContent && textboxContent.match( /^==(.+)==/m );
if ( !matches ) {
return;
}
heading = matches[ 1 ]
// Constructs like [[Namespace:Page|<empty string>]]
.replace( /\[\[:?(?:[^:|[\]<>]+?:)?([^|[\]<>]+)\|\]\]/g, '$1' )
// Extract displayed text from wikilinks
.replace( /\[\[:?(?:[^|[\]<>]+\|)?(.+?)\]\]/g, '$1' )
// Extract displayed text from links
.replace( /\[https?:\/\/[^[\]<>" ]+ *([^\]]*)\]/g, '$1' )
// Remove bold
.replace( /'''(.+?)'''/g, '$1' )
// Remove italics
.replace( /''(.+?)''/g, '$1' )
// Remove opening tags (won't work with <smth param=">">, but wikiparser fails too)
.replace( /<\w+(?: [\w ]+?=[^<>]+?| ?\/?)>/g, '' )
// Remove closing tags
.replace( /<\/\w+ ?>/g, '' )
// Remove multiple spaces
.replace( / {2,}/g, ' ' )
.trim();
if ( !heading ) {
return;
}
if ( isVe ) {
$summary = $( '.ve-ui-mwSaveDialog-summary textarea' );
}
summary = $summary.val();
if ( summary === undefined ) {
return;
}
$summary
.val( /\/\*.*\*\//.test( summary ) ?
'/* ' + heading + ' */' + summary.substr( summary.indexOf( '*/' ) + 2 ) :
'/* ' + heading + ' */ ' + summary
)
.trigger( 'change' );
}
try {
decodedQuery = decodeURIComponent( location.search );
} catch ( e ) {}
if ( decodedQuery &&
$textbox.length &&
( /[?&]summary=\/\*[+ ]*\*\//.test( decodedQuery ) ||
( mw.config.get( 'wgAction' ) === 'submit' &&
summary !== undefined &&
/\/\*\s*\*\//.test( summary )
)
)
) {
if ( mw.config.get( 'wgAction' ) !== 'submit' ) {
textboxContent = $textbox.textSelection( 'getContents' );
// Remove HTML comments
textboxContentWithoutComments = textboxContent && textboxContent.replace( /<!--[^]*?-->/g, '' );
if ( !/^==.+==/m.test( textboxContentWithoutComments ) ) {
$textbox
.focus()
.textSelection( 'setContents',
// '' for isVe until T198010 (clause 2) is fixed
textboxContent + '\n== ==' + ( isVe ? '' : '\n' )
)
.textSelection( 'setSelection', { start: $textbox.textSelection( 'getContents' ).length - 4 } );
}
}
// Workaround until T197632 is fixed. The handler will run twice in most cases.
// ".CodeMirror-code" for Chrome, focusin on ".editOptions" for Firefox.
$textbox.add( '.CodeMirror-code' ).blur( transferHeadingToSummary );
$( '.editOptions' ).focusin( transferHeadingToSummary );
mw.hook( 've.saveDialog.stateChanged' ).add( transferHeadingToSummary );
}
}
mw.hook( 'wikipage.editform' ).add( main );
mw.hook( 've.activationComplete' ).add( function () {
isVe = true;
main();
} );
}() );