Jump to content

User:Ferix/monobook.js

From Wikipedia, the free encyclopedia
(Redirected from User:SJHawtin/monobook.js)
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.
// Name:          Wikipedia user menu
// Version:       0.4
// Description:   Adds personalised version of Template:Userinfo to all wikipedia user pages
//                removes the template from pages that already have it

$(function() {
  if (document.getElementById('TemplateUserinfo')) {
    var templateuserinfo=document.getElementById('TemplateUserinfo');
    var removetemplate=document.getElementById('bodyContent').removeChild(templateuserinfo);
  }
  //  var regex=/^User:([^\/]+)$/;
  //  var title=document.getElementsByTagName('h1')[0].firstChild.nodeValue;
  
  var regex=/^User:([^\/]+) - Wikipedia, the free encyclopedia$/;
  var title=document.title;
  
  if (title.match(regex)) {
    var rawusername=title.match(regex);
    var username=rawusername[1].replace(/ /, '_');
    
    function addUserMenu() {
      var body, menu, menulinkcontribs, menuspacercontribs, menulinkinteriot, menuspacerinteriot, menulinkimages, menuspacerimages, menulinkesu;
      body=document.getElementById('bodyContent');
      menu=document.createElement('div');
      menulinkcontribs=document.createElement('a');
      menulinkinteriot=document.createElement('a');
      menulinkimages=document.createElement('a');
      menulinkesu=document.createElement('a');
      menu.id='TemplateUserinfo';
      menu.setAttribute('class', 'plainlinks');
      menu.setAttribute('style', 'position: absolute; right: 1.15em; top: 1.3em; font-size: 90%;');
      menulinkcontribs.setAttribute('href', '/wiki/Special:Contributions/' + username + '');
      menulinkcontribs.setAttribute('class', 'external text');
      menulinkcontribs.setAttribute('title', '' + username + '\'s contributions');
      menulinkcontribstext=document.createTextNode('contributions');
      menulinkinteriot.setAttribute('href', 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?user=' + username + '&dbname=enwiki_p');
      menulinkinteriot.setAttribute('class', 'external text');
      menulinkinteriot.setAttribute('title', '' + username + '\'s edit count');
      menulinkinteriottext=document.createTextNode('edit count (interiot)');
      menulinkimages.setAttribute('href', 'http://tools.wikimedia.de/~daniel/WikiSense/Gallery.php?wikilang=en&wikifam=.wikipedia.org&img_user_text=' + username + '&order=-img_timestamp&order=-img_timestamp&format=html');
      menulinkimages.setAttribute('class', 'external text');
      menulinkimages.setAttribute('title', '' + username + '\'s uploaded images');
      menulinkimagestext=document.createTextNode('images');
      menulinkesu.setAttribute('href', 'http://www.math.ucla.edu/~aoleg/wp/rfa/edit_summary.cgi?user=' + username + '');
      menulinkesu.setAttribute('class', 'external text');
      menulinkesu.setAttribute('title', '' + username + '\'s edit summary usage');        
      menulinkesutext=document.createTextNode('edit summary usage');
      menulinkcontribs.appendChild(menulinkcontribstext);
      menulinkinteriot.appendChild(menulinkinteriottext);
      menulinkimages.appendChild(menulinkimagestext);
      menulinkesu.appendChild(menulinkesutext);
      menuspacercontribs=document.createTextNode(' | ');
      menuspacerinteriot=document.createTextNode(' | ');
      menuspacerimages=document.createTextNode(' | ');
      menu.appendChild(menulinkcontribs);
      menu.appendChild(menuspacercontribs);
      menu.appendChild(menulinkinteriot);
      menu.appendChild(menuspacerinteriot);
      menu.appendChild(menulinkimages);
      menu.appendChild(menuspacerimages);
      menu.appendChild(menulinkesu);
      body.appendChild(menu);
    }
    
    addOnloadHook(addUserMenu);
  }

});

// Description:   change the names of personal tools links and tabs
//                stolen from User:Trilobite/monobook.js

function changelinks() {
  if(!document.getElementById) { return; }
  if (document.createTextNode) {
    var mytalk, preferences, watchlist, mycontris, logout;
    mytalk=document.getElementById('pt-mytalk').firstChild.firstChild;
    mytalk.nodeValue='Talk';
    preferences=document.getElementById('pt-preferences').firstChild.firstChild;
    preferences.nodeValue='Preferences';
    watchlist=document.getElementById('pt-watchlist').firstChild.firstChild;
    watchlist.nodeValue='Watchlist';
    mycontris=document.getElementById('pt-mycontris').firstChild.firstChild;
    mycontris.nodeValue='Contributions';
    logout=document.getElementById('pt-logout').firstChild.firstChild;
    logout.nodeValue='Log out';
    
    if(document.getElementById('ca-nstab-user')) {
      var nstabuser=document.getElementById('ca-nstab-user').firstChild.firstChild;
      nstabuser.nodeValue='User';
    }
    if(document.getElementById('ca-talk')) {
      var talk=document.getElementById('ca-talk').firstChild.firstChild;
      talk.nodeValue='Talk';
    }
    if(document.getElementById('ca-edit')) {
      var edit=document.getElementById('ca-edit').firstChild.firstChild;
      edit.nodeValue='Edit';
    }
    if(document.getElementById('ca-viewsource')) {
      var viewsource=document.getElementById('ca-viewsource').firstChild.firstChild;
      viewsource.nodeValue='Source';
    }
    if(document.getElementById('ca-watch')) {
      var watch=document.getElementById('ca-watch').firstChild.firstChild;
      watch.nodeValue='Guard';
    }
    if(document.getElementById('ca-unwatch')) {
      var unwatch=document.getElementById('ca-unwatch').firstChild.firstChild;
      unwatch.nodeValue='Ignore';
    }
  }
  else {
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'Talk';
    document.getElementById('pt-preferences').firstChild.innerHTML = 'Preferences';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'Watchlist';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'Contributions';
    document.getElementById('pt-logout').firstChild.innerHTML = 'Log out';
    
    if(document.getElementById('ca-nstab-user')) {
      document.getElementById('ca-nstab-user').firstChild.innerHTML = 'User';
    }
    if(document.getElementById('ca-talk')) {
      document.getElementById('ca-talk').firstChild.innerHTML = 'Talk';
    }
    if(document.getElementById('ca-edit')) {
      document.getElementById('ca-edit').firstChild.innerHTML = 'Edit';
    }
    if(document.getElementById('ca-viewsource')) {
      document.getElementById('ca-viewsource').firstChild.innerHTML = 'Source';
    }
    if(document.getElementById('ca-watch')) {
      document.getElementById('ca-watch').firstChild.innerHTML = 'Guard';
    }
    if(document.getElementById('ca-unwatch')) {
      document.getElementById('ca-unwatch').firstChild.innerHTML = 'Ignore';
    }
  }
}

$(changelinks);


// Name:          Wikipedia Purge Tab
// Description:   Adds purge tab to Wikipedia pages
//                stolen from User:BesigedB/monobook.js

function addPurgeButton() {
  var href = document.location.href;
  if ( href.search( /[^:]*:\/\/en\.wikipedia\.org\/(wiki\/|w\/index\.php\?title=)([^&?]*)/ ) === 0 && document.getElementById('ca-history')) {    
    var historyHref = document.getElementById( "ca-history" ).firstChild.href;
    var div = document.getElementById( "p-cactions" );
    var ul = div.getElementsByTagName( "ul" )[0];
    var newLi = document.createElement( "li" );
    var newA = document.createElement( "a" );
    newA.setAttribute( "href" , historyHref.replace( "=history" , "=purge" ) );
    if (document.createTextNode) {
      var text = document.createTextNode( "Purge" );
      newA.appendChild( text );
    }
    else {
      newA.innerHTML='Purge';
    }
    newLi.appendChild( newA );
    ul.appendChild( newLi );
  }
}

$(addPurgeButton);