Jump to content

User:Polygnotus/Scripts/ExtraButtons.js

From Wikipedia, the free encyclopedia
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.
//I should be able to combine these
//colours are weird in dark mode

//https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization

// <nowiki>
if (['edit', 'submit'].indexOf(mw.config.get('wgAction')) !== -1) {
  mw.hook('wikiEditor.toolbarReady').add(function($textarea) {
    
    $textarea.wikiEditor('addToToolbar', {
      section: 'advanced',
      group: 'insert',
      tools: {
        welcomeButton: {
          label: 'Welcome',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/6/6f/Handshake_icon_BLACK_and_WHITE.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{subst:' + 'User:Polygnotus/Templates/welcome}} ~~' + '~~',
            }
          }
        },
        
        
   refIdeas: {
  type: 'element',
  filters: [ 'body.ns-1' ],
  element: function ( context ) {
    var button = new OO.ui.ButtonInputWidget( {
      label: '',
      icon: 'lightbulb',
      title: 'refideas'
    } );
    button.connect( null, {
      click: function ( e ) {
        var text = '{{refideas\n|1=\n}}';
        
        var textarea = context.$textarea[0];
        var start = textarea.selectionStart;
        var end = textarea.selectionEnd;
        var currentText = textarea.value;
        
        textarea.value = currentText.substring(0, start) + text + currentText.substring(end);
        textarea.selectionStart = textarea.selectionEnd = start + text.length;
        textarea.focus();
        
        $(textarea).trigger('input');
        
        $('#wpSummary').val('Added {{refideas}} template');
      }
    } );
    return button.$element;
  }
},
  
  
  
  
  wpPolicy: {
  label: 'WP Policy',
  filters: [ 'body.ns-3' ],
  type: 'button',
  icon: 'articles',
  action: {
    type: 'callback',
    execute: function( context ) {
      var policy = prompt('Enter Wikipedia policy/guideline abbreviation (e.g., NPOV, V, RS):');
      if (policy !== null && policy.trim() !== '') {
        var text = '== [[WP:' + policy.trim() + ']] ==\nPlease read [[WP:' + policy.trim() + ']], thanks and have a nice day, ~~~~';
        context.$textarea.textSelection('encapsulateSelection', {
          pre: text
        });
      }
    }
  }
},


        
        exlinkInBody: {
          label: 'ExternalLinkInBody',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: {
            src: '//upload.wikimedia.org/wikipedia/commons/0/05/IUCN_EX.svg',
            width: 26,
            height: 26
          },
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{subst:' + 'User:Polygnotus/Templates/exlink}} ~~' + '~~',
            }
          }
        },
        
        uwSpam: {
          label: 'UW-Spam',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/No-spam.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{subst:' + 'uw-spam}} ~~' + '~~',
            }
          }
        },
        
        teahouseButton: {
          label: 'Teahouse',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/0/0d/Questionmark_SVG_4.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: 'If you have any questions, the [[WP:TEAHOUSE]] is a great place to get answers.',
            }
          }
        },
        
        vand1Button: {
          label: 'Vandalism warning level 1',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/8/8a/Eo_circle_grey_number-1.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{subst:' + 'uw-vand1}} ~~' + '~~',
            }
          }
        },
        
        vand2Button: {
          label: 'Vandalism warning level 2',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/c/c7/Eo_circle_yellow_number-2.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{subst:' + 'uw-vand2}} ~~' + '~~',
            }
          }
        },
        
        vand3Button: {
          label: 'Vandalism warning level 3',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/c/c5/Eo_circle_deep-orange_number-3.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{subst:' + 'uw-vand3}} ~~' + '~~',
            }
          }
        },
        
        vand4Button: {
          label: 'Vandalism warning level 4',
          filters: [ 'body.ns-3' ],
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/c/cd/Eo_circle_red_number-4.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{subst:' + 'uw-vand4}} ~~' + '~~',
            }
          }
        }
      }
    });

  });
}

// </nowiki>