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 loadOnEdit { 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(/\|/, ));        }    );

function addInterwikiPt { var txt = $('#wpTextbox1'); var str = txt.val; var title = mw.config.get('wgPageName').replace(/\_/g, ' '); var regex = /\[\[([a-z]{2}):(.+?)\]\](\n)?/gim; var match; var 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('')); }   $('#userSummaryButtonsA a:first').click(addInterwikiPt); $('#wpSave').click(function {       $('#wpTextbox1').val($('#wpTextbox1').val.replace(/\[\[en:(.+?)\]\](\n)?/gim, ''));        if ($('input[name="wpSummary"]').val == "Adding interwiki (pt)") {            var ptArticleName = $('#wpTextbox1').val.match(/\[\[pt:(.+?)\]\]$/gim);            $('input[name="wpSummary"]').val('Adding interwiki ' + ptArticleName);        }    }); }

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