User:AmigoCreeper/common.js

// Buttons for editing summaries if (typeof pointSummaryButtonsA == 'undefined') { window.pointSummaryButtonsA = ','; } function insertSummary ( txt ) { if ( typeof txt !== 'string' ) { txt = this.title; }	var vv = $( 'input[name="wpSummary"]' ).val; if ( vv.indexOf( txt ) !== -1 ) { return; }	if ( /[^,; \(\/]$/.test( vv ) && !/talk\]\]\)$/.test(vv) ) { vv += pointSummaryButtonsA; }	if ( /[^ \(]$/.test( vv ) ) {		vv += ' ';	}	$( 'input[name="wpSummary"]' ).val( vv + txt ); } function SumButton ( btn, txt ) {	$( '' + btn + '' )		.appendTo( '#userSummaryButtonsA' )		.click( insertSummary ); } function sumButtons {	var frm = document.getElementById( 'editform' );	if ( !mw.config.get( 'wgArticleId' ) || !frm || $( frm.wpSection ).val === 'new' ) {		return;	}	mw.util.addCSS( '\ #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 }' );	$( ' ' ).insertAfter( '#wpSummary' );	$.each( [		'Adding interwiki (pt)', 'Fixing', 'Updating', 'vandalism' ],		function ( i, s ) { SumButton( s.replace( /\|.*/,  ), s.replace( /\|/,  ) ); }	); }

$.when(	mw.loader.using( 'ext.wikiEditor' ),	$.ready ).then( sumButtons );

function addInterwikiPt { let txt = $("#wpTextbox1"); let str = txt.val; let title = mw.config.get("wgPageName").replace(/\_/g, " "); console.log(title); let regex = /\[\[([a-z]{2}):(.+?)\]\](\n)?/gim; let match; let matches = [];

while ((match = regex.exec(str))) { matches.push(match[0]); }   matches.push("[\[pt:]]\n"); matches.push("[\[en:" + title + "]]\n"); matches.sort; txt.val(txt.val.replace(regex, "")); txt.val(txt.val + matches.join("")); }

if (mw.config.get('wgAction') == 'edit' && mw.config.get('wgArticleId')) { if (mw.config.get('wgTitle').startsWith("Launcher")) { $('input[name="wpSummary"]').val('Adding interwiki (pt)'); }   $("#userSummaryButtonsA a:first").click(addInterwikiPt); $("#wpSave").click(function {       $("#wpTextbox1").val($("#wpTextbox1").val.replace(/\[\[en:(.+?)\]\](\n)?/gim, ""));    }); }