User:Spacebirdy/quickcentralauth.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*************
*** Add "quick access" boxes on Special:CentralAuth
*** by [[m:user:Pathoschild]]
*************/
function add_QuickCentralAuth() {
        if(wgPageName=='Special:CentralAuth' && document.getElementById('delete-reason')) {
                /* grab body & token */
                var body      = document.getElementById('bodyContent');
                var token     = body.innerHTML.match(/name="wpEditToken"[^>]+value="([^"]+)/)[1];
                var user_name = document.getElementById('target').value;
 
                /* generate 'Quick Access' section */
                function new_form(wpmethod, text_label) {
                        return '<form method="POST" action="http://meta.wikimedia.org/w/index.php?title=Special:CentralAuth&amp;target=' + encodeURIComponent(user_name) + '">'
                                + '<input name="wpMethod" type="hidden" value="' + wpmethod + '" />'
                                + '<input name="wpEditToken" type="hidden" value="' + token + '" />'
                                + '<label for="' + wpmethod + '-reason">Ástæða:</label> <input name="reason" size="" value="" id="' + wpmethod + '-reason" />'
                                + '<input type="submit" value="' + text_label + '" />'
                                + '</form>';
                }
 
                /* generate quick access section */
                var quick_access = '<div style="padding:0.5em; border:1px solid #000;"><b>Quick access for "' + user_name + '":</b><br />Enter a reason in the box next to the button.'
                        + new_form('delete', 'Eyða')
                        + new_form('lockandhide', 'Læsa og fela')
                        + new_form('lock', 'Læsa')
                        + '</div>';
 
                /* add */
                var siteNotice = document.getElementById('contentSub');
                siteNotice.innerHTML += quick_access;
        }
}
$(function() {add_QuickCentralAuth()});