User:Monster Domosed/common.js: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 69: Line 69:


return entries.map( function ( e ) {
return entries.map( function ( e ) {
return e.replace( /\s+/g, ' ' ).trim();
return e.replace( /\s+/g, ' ' ).trim();
} ).filter( Boolean );
} ).filter( Boolean );
}
}
Line 170: Line 168:


if ( kind === 'general' ) {
if ( kind === 'general' ) {
general.push( body );
general.push( body );
} else if ( kind === 'mode' ) {
} else if ( kind === 'mode' ) {
if ( !modes[ name ] ) {
if ( !modes[ name ] ) {
modes[ name ] = [];
modes[ name ] = [];
modeOrder.push( name );
modeOrder.push( name );
}
}
modes[ name ].push( body );
modes[ name ].push( body );
} else if ( kind === 'item' ) {
} else if ( kind === 'item' ) {
if ( !itemSections[ name ] ) {
if ( !itemSections[ name ] ) {
itemSections[ name ] = [];
itemSections[ name ] = [];
itemOrder.push( name );
itemOrder.push( name );
}
}
itemSections[ name ].push( body );
itemSections[ name ].push( body );
} else if ( kind === 'hero' ) {
} else if ( kind === 'hero' ) {
if ( !heroSections[ name ] ) {
if ( !heroSections[ name ] ) {
heroSections[ name ] = [];
heroSections[ name ] = [];
heroOrder.push( name );
heroOrder.push( name );
}
}
heroSections[ name ].push( body );
heroSections[ name ].push( body );
}
}
Line 204: Line 192:
var out = [];
var out = [];


// General
general.forEach( function ( entry ) {
general.forEach( function ( entry ) {
out.push( '* ' + entry );
out.push( '* ' + entry );
} );
} );


// Modes
modeOrder.forEach( function ( mode ) {
modeOrder.forEach( function ( mode ) {


Line 220: Line 206:
} );
} );


// Items
if ( itemOrder.length ) {
if ( itemOrder.length ) {


Line 237: Line 222:
}
}


// Heroes
if ( heroOrder.length ) {
if ( heroOrder.length ) {


Line 261: Line 245:


var app = document.getElementById( 'patchformatter' );
var app = document.getElementById( 'patchformatter' );
 
if ( !app ) return;
if ( !app ) {
return;
}


var inputWidget = new OO.ui.MultilineTextInputWidget( {
var inputWidget = new OO.ui.MultilineTextInputWidget( {
Line 323: Line 304:
outputWidget.setValue( result );
outputWidget.setValue( result );


status.setLabel( 'Done: ' + entries.length );
status.setLabel(
 
'Done: ' + entries.length +
} ).catch( function ( e ) {
' entries | ' +
heroes.length + ' heroes | ' +
abilities.length + ' abilities | ' +
items.length + ' items'
);


} ).catch( function () {
status.setLabel( 'Error' );
status.setLabel( 'Error' );
} );
} );
} );
} );


copyButton.on( 'click', function () {
copyButton.on( 'click', function () {
 
navigator.clipboard.writeText( outputWidget.getValue() );
navigator.clipboard.writeText(
outputWidget.getValue()
);
 
status.setLabel( 'Copied' );
status.setLabel( 'Copied' );
} );
} );
}
}


// ---- BOOT -----------------------------------------------------------
mw.loader.using( [
mw.loader.using( [
'oojs-ui-core',
'oojs-ui-core',