User:Dr ishmael/monobook.js

From Guild Wars 2 Wiki
Jump to navigationJump to search

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.
function addStuffToSideBar()
{
  if (wgCanonicalSpecialPageName === 'Statistics') {
    $.ajax({ url: 'http://wiki.guildwars2.com/api.php?action=query&meta=siteinfo&siprop=statistics',
      success: function(data) {
        $('<tr class="mw-statistics-jobs"><td>Job queue</td><td class="mw-statistics-numbers">' + data.match(/jobs=&quot;(\d+)&quot;/i)[1].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</td></tr>').insertAfter('.mw-statistics-edits-average');
      }
    });
  }
  
  document.getElementById('n-recentchanges').firstChild.href = '/index.php?title=Special:RecentChanges&hidemyself=1&hidebots=';
  
  var comm = document.createElement('div');
  comm.id = "myWikiLinks";
  comm.className = "generated-sidebar portlet";
  comm.innerHTML = '<h5>Command center</h5>'+
    '<div id="commandCenterDiv" class="pBody"><ul>'+
    '<li id="n-abusefilter"><a href="/wiki/Special:AbuseFilter">AbuseFilter</a></li>'+
    '<li id="n-deletion"><a href="/wiki/Guild Wars 2 Wiki:Bots">Bots</a></li>'+
    '<li id="n-deletion"><a href="/wiki/Guild Wars 2 Wiki:List of candidates for deletion">Deletion</a></li>'+
    '<li id="n-export"><a href="/wiki/Special:Export">Export</a></li>'+
    '<li id="n-masterlog"><a href="/wiki/Special:Log">Master log</a></li>'+
    '<li id="n-sitenotice"><a href="/wiki/MediaWiki:Sitenotice" style="display:inline">Sitenotice</a> / <a href="/wiki/MediaWiki:Sitenotice_id" style="display:inline">id</a></li>'+
    '<li id="n-specialpages"><a href="/wiki/Special:SpecialPages">Special pages</a></li>'+
    '<li id="n-sysmsgs"><a href="/wiki/Special:Allmessages">System messages</a></li>'+
    '<li id="n-statsversion"><a href="/wiki/Special:Statistics" style="display:inline">Statistics</a> / <a href="/wiki/Special:Version" style="display:inline">Version</a></li>'+
    '</ul></div>';
  
  document.getElementById('p-search').parentNode.insertBefore(comm,document.getElementById('p-search'));
  
  var pref = document.createElement('div');
  pref.id = "p-prefixIndex";
  pref.className = "generated-sidebar portlet";
  pref.innerHTML = '<h5><label for="prefixInput">Search by prefix</label></h5>'+
    '<div id="prefixBody" class="pBody" style="text-align:center">'+
      '<form id="prefixform" action="/index.php">'+
        '<input type="hidden" name="title" value="Special:PrefixIndex">'+
        '<input type="search" id="prefixInput" name="prefix" title="Search by prefix" style="font-size:95%;width:10em">'+
        '<input type="submit" id="mw-prefixButton" class="searchButton" name="go" title="Search for all pages with this prefix" value="Go">'+
      '</form>'+
    '</div>';
  
  document.getElementById('p-Support').parentNode.insertBefore(pref,document.getElementById('p-Support'));
  
  if (window.location.href.indexOf('oldid=') >= 0) {
    document.getElementById('ca-edit').style.display = 'none';
  }
}

/***** Custom edit buttons ****/
var addExtraButtons = function(){
  mw.toolbar.addButton({
    imageFile: "http://upload.wikimedia.org/wikipedia/commons/2/23/Button_code.png",
    speedTip: "Code",
    tagOpen: "<code>",
    tagClose: "</code>",
    sampleText: "",
    imageId: 'button-code'
  });

  mw.toolbar.addButton({
    imageFile: "http://images2.wikia.nocookie.net/__cb20070405031754/central/images/7/73/Button_code_nowiki.png",
    speedTip: "Code+nowiki",
    tagOpen: "<code><nowiki>",
    tagClose: "</nowiki></code>",
    sampleText: "",
    imageId: 'button-code-nowiki'
  });

  mw.toolbar.addButton({
    imageFile: "http://upload.wikimedia.org/wikipedia/commons/1/1b/Button_hide_wiki_tag.png",
    speedTip: "HTML comment",
    tagOpen: "<!--",
    tagClose: "-->",
    sampleText: "",
    imageId: 'button-html-comment'
  });

  mw.toolbar.addButton({
    imageFile: "http://upload.wikimedia.org/wikipedia/commons/c/ce/Button_no_include.png",
    speedTip: "Noinclude",
    tagOpen: "<noinclude>",
    tagClose: "</noinclude>",
    sampleText: "",
    imageId: 'button-noinclude'
  });

  mw.toolbar.addButton({
    imageFile: "http://upload.wikimedia.org/wikipedia/commons/b/bf/Button_pagename.png",
    speedTip: "Pagename",
    tagOpen: "{{",
    tagClose: "subst:PAGENAME}}",
    sampleText: "",
    imageId: 'button-pagename'
  });

  mw.toolbar.addButton({
    imageFile: "http://upload.wikimedia.org/wikipedia/commons/c/c9/Button_strike.png",
    speedTip: "Strikethrough",
    tagOpen: "<s>",
    tagClose: "</s>",
    sampleText: "",
    imageId: 'button-strikethrough'
  });

  mw.toolbar.addButton({
    imageFile: "http://upload.wikimedia.org/wikipedia/commons/1/18/Button_quotes_2.png",
    speedTip: "Quote",
    tagOpen: "{{quote|",
    tagClose: "}}",
    sampleText: "",
    imageId: 'button-quote'
  });
};
 
if( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
  mw.loader.using( 'user.options', function () {
    if ( ! mw.user.options.get( 'usebetatoolbar' ) ) {
      mw.loader.using( 'mediawiki.action.edit', function() {
        $( addExtraButtons );
      });
    }
  });
}

/*** hideUser for RC ***/
/*** Author: User:Dr ishmael ***/
/* Notes:
  - Don't click on the Hide button - this will submit the RC filter form.
  - Instead, after typing in the text field, hit Tab to move focus to the button, then hit Space to activate the JavaScript without submitting the form.
 */
function hideUserWrapper()
{
    if (document.title.substring(0,14) == 'Recent changes') {
        var tables = document.getElementsByTagName('table');
        var RCinput;
        for (var i = 0; i < tables.length; i++) {
            if (tables[i].className == 'mw-recentchanges-table') {
                RCinput = tables[i];
                break;
            }
        }
    
        var uls = document.getElementsByTagName('ul');
        var RCuls = new Array();
        for (var i = 0; i < uls.length; i++) {
            if (uls[i].className == 'special') {
                RCuls.push(uls[i]);
            }
        }

        var myInput = document.createElement('input');
        myInput.type = 'text';
        myInput.id = 'hideUsername';
        myInput.name = 'hideUsername';

        var myLabel = document.createElement('label');
        myLabel.htmlFor = 'hideUsername';
        myLabel.innerHTML = "Hide user:";

        var mySubmit = document.createElement('input');
        mySubmit.type = 'button';
        mySubmit.value = 'Hide';
    
        var newRow = RCinput.insertRow(1);
        var newLabelCell = newRow.insertCell(0);
        var newInputCell = newRow.insertCell(1);

        newLabelCell.appendChild(myLabel);

        newInputCell.appendChild(myInput);
        newInputCell.appendChild(mySubmit);

        try { // non-IE
            mySubmit.addEventListener("click", function() { hideUser(RCuls) }, false);
        }
        catch(e) { // IE
            mySubmit.attachEvent("onclick", function(){ hideUser(RCuls) } );
        }
    }
}

function hideUser(RCuls)
{
    var usernames = document.getElementById('hideUsername').value.split(',');
    for (var j = 0; j < RCuls.length; j++) {
        var lis = RCuls[j].getElementsByTagName('li');
        for (var i = 0; i < lis.length; i++) {
            var ulUser;
            if (lis[i].innerHTML.substring(0,7) == '(diff |') /* New page creation entry */
                ulUser = lis[i].getElementsByTagName('a')[2].innerHTML;
            else if (lis[i].getElementsByTagName('a')[0].innerHTML == 'diff') /* Page edit entry */
                ulUser = lis[i].getElementsByTagName('a')[3].innerHTML;
            else  /* Log entry */
                ulUser = lis[i].getElementsByTagName('a')[1].innerHTML;

            if (new RegExp('^(' + usernames.join('|') + ')$').test(ulUser))
                lis[i].style.display = 'none';
            else
                lis[i].style.display = '';
        }
    }
}

$(function() {
    addStuffToSideBar();
    hideUserWrapper();
});