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.
// Add Templates section to 2010 wikitext editor toolbar// Place this code in your common.js file$(document).ready(function(){// Only run on edit pages with the 2010 wikitext editor during preview and submitvaraction=mw.config.get('wgAction');if((action==='edit'||action==='submit')&&$('#wpTextbox1').length&&$('.wikiEditor-ui-toolbar').length){// Wait for WikiEditor to be fully loadedmw.hook('wikiEditor.toolbarReady').add(function(){addTemplatesSection();});// Fallback if hook doesn't firesetTimeout(function(){if(!$('#wikiEditor-section-templates').length){addTemplatesSection();}},1000);}functionaddTemplatesSection(){// Add Templates tab to the toolbarvar$tabs=$('.wikiEditor-ui-toolbar .tabs');if($tabs.length&&!$('#wikiEditor-section-templates').length){// Create the Templates tabvar$templatesTab=$('<span>').addClass('tab tab-templates').attr('rel','templates').html('<a class="skin-invert" tabindex="0" role="button" aria-expanded="false" aria-controls="wikiEditor-section-templates">Templates</a>');// Add tab to the toolbar$tabs.append($templatesTab);// Create the Templates section contentvar$templatesSection=$('<div>').addClass('toolbar section section-templates section-hidden').attr({'rel':'templates','id':'wikiEditor-section-templates','aria-expanded':'false'});// Create template buttons groupvar$templateGroup=$('<div>').addClass('group group-templates').attr('rel','templates');// Add group label$templateGroup.append('<span class="label">Warning templates</span>');// Create uw-3rr buttonvar$uw3rrButton=$('<span>').addClass('tool oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-frameless oo-ui-iconElement oo-ui-buttonWidget').attr('rel','uw-3rr').html('<a class="oo-ui-buttonElement-button" role="button" title="3RR warning template" tabindex="0" rel="nofollow">'+'<span class="oo-ui-iconElement-icon oo-ui-icon-alert"></span>'+'<span class="oo-ui-labelElement-label">{{uw-3rr}}</span>'+'<span class="oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator"></span>'+'</a>');// Add click handler for the button$uw3rrButton.on('click',function(e){e.preventDefault();insertTemplate('{{uw-3rr}}');});// Assemble the section$templateGroup.append($uw3rrButton);$templatesSection.append($templateGroup);// Add section to the toolbar sections container$('.wikiEditor-ui-toolbar .sections').append($templatesSection);// Add tab click handler$templatesTab.on('click',function(e){e.preventDefault();// Hide all other sections and remove current class from tabs$('.wikiEditor-ui-toolbar .section').removeClass('section-visible').addClass('section-hidden').attr('aria-expanded','false');$('.wikiEditor-ui-toolbar .tab a').removeClass('current');// Show templates section and mark tab as current$templatesSection.removeClass('section-hidden').addClass('section-visible').attr('aria-expanded','true');$(this).find('a').addClass('current');});// Add handlers for other tabs to hide templates section$('.wikiEditor-ui-toolbar .tab').not($templatesTab).on('click',function(){$templatesSection.removeClass('section-visible').addClass('section-hidden').attr('aria-expanded','false');$templatesTab.find('a').removeClass('current');});}}functioninsertTemplate(template){// Check if CodeMirror is activeif($('.cm-editor').length&&$('.cm-content').length){// CodeMirror is active - use CodeMirror APIvarcmEditor=$('.cm-editor')[0];if(cmEditor&&cmEditor.CodeMirror){varcm=cmEditor.CodeMirror;varcursor=cm.getCursor();cm.replaceRange(template,cursor);cm.setCursor(cursor.line,cursor.ch+template.length);cm.focus();}}else{// Fallback to regular textareavartextArea=$('#wpTextbox1')[0];if(textArea){varstartPos=textArea.selectionStart;varendPos=textArea.selectionEnd;vartextBefore=textArea.value.substring(0,startPos);vartextAfter=textArea.value.substring(endPos);textArea.value=textBefore+template+textAfter;textArea.selectionStart=textArea.selectionEnd=startPos+template.length;textArea.focus();}}}});