Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
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.
/* * addToolbarButtons.js * version 2013-11-02 * * This function lets you add function-calling buttons * to the toolbar above the textarea, * regardless of whether the user is using the old toolbar, * or the "enhanced editing" WikiEditor toolbar. * (The visual editor is not supported). * * Home: //en.wikipedia.org/wiki/User:V111P/js/addToolbarButtons * You can use this code under the license CC0 */// add a single button or several buttons from the supplied array// or else add all buttons specified in the array window.toolbarButtonsToAddmediaWiki.libs.addToolbarButtons=window.addToolbarButtons=function(props){"use strict";if($.inArray(mw.config.get('wgAction'),['edit','submit'])==-1)return;// not source-editing a pageif(!props||props[0]){vararr=props||window.toolbarButtonsToAdd||[];$.each(arr,function(i,val){if(typeofval=='object'&&!val[0])mediaWiki.libs.addToolbarButtons(val);});arr.length=0;return;}varbutton={id:'',tooltip:'',section:'main',group:'insert',iconUrl:'//upload.wikimedia.org/wikipedia/commons/'+'thumb/1/1a/White_pog.svg/22px-White_pog.svg.png'}$.extend(button,props||{});functionerror(msg){if(window.console&&console.error)console.error('addToolbarButtons.js: '+msg);}if(!button.id){error('No button id specified.');return;}if($('#'+button.id)[0]){error('An element with id '+button.id+' already exists on the page.');return;}if(!props.iconUrl&&!props.iconUrlClassic)button.iconUrlClassic='//upload.wikimedia.org/wikipedia/commons/e/ec/Button_base.png';button.before=(typeofbutton.before=='string'?button.before:'');button.between=(typeofbutton.between=='string'?button.between:'');button.after=(typeofbutton.after=='string'?button.after:'');button.inserts=(button.before+button.between+button.after).length>0;if(!button.callback&&!button.inserts){error('Neither a callback function nor characters to insert specified.');return;}// add button to the new, WikiEditor, toolbarfunctioncustomizeBetaToolbar(){vartools={};tools[button.id]={label:button.tooltip,type:'button',icon:button.iconUrl,action:{type:(button.inserts?'encapsulate':'callback'),execute:(button.inserts?void(0):button.callback),options:(button.inserts?{pre:button.before,peri:button.between,post:button.after}:void(0))}};$('#wpTextbox1').wikiEditor('addToToolbar',{'section':button.section,'group':button.group,'tools':tools});varbtn=$('.tool-button[rel="'+button.id+'"]').attr('id',button.id);if(button.inserts&&button.callback)btn.click(button.callback);}mw.loader.using('user.options',function(){if(mw.user.options.get('usebetatoolbar')){mw.loader.using('ext.wikiEditor.toolbar',function(){$(customizeBetaToolbar);});}});if($('#'+button.id).size()==0){// add a button to the classic toolbarmw.loader.using('mediawiki.action.edit',function(){vartempButtonId=button.id+(!button.inserts?'TempButton':'');mw.toolbar.addButton((button.iconUrlClassic||button.iconUrl),button.tooltip,button.before,button.after,button.between,tempButtonId,tempButtonId);if(button.inserts){button.callback&&$('#'+button.id).click(button.callback);}else{var$tempButton=$('#'+tempButtonId);if($tempButton[0]){// clone the button to remove added event handlers// if not done the selection in the textarea is collapsed// before the callback function is calledvarnewB=$tempButton[0].cloneNode();newB.id=button.id;$tempButton.after(newB).remove();$(newB).click(button.callback);}}});}}mediaWiki.libs.addToolbarButtons.version=1000;try{// $() doesn't work after errors from other scripts, so try directly first:mediaWiki.libs.addToolbarButtons();}catch(e){// error - page still loading$(mediaWiki.libs.addToolbarButtons);}