User:RansomTime/common.js

From LoadingReadyWiki
Revision as of 10:01, 13 July 2016 by RansomTime (talk | contribs) (scripts)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
function queryString( p ) {
    var    re = RegExp('[&?]' + p + '=([^&]*)'),
        matches;
    if ( matches = re.exec( document.location ) ) {
        try {
            return decodeURI(matches[1]);
        } catch ( e ) {
        }
    }
    return null;
}

importScriptURI('http://janitor.wikia.com/index.php?title=User:RansomTime/scripts.js&action=raw&ctype=text/javascript');
importScriptURI('http://dev.wikia.com/index.php?title=MediaWiki:AjaxRC/code.js&action=raw&ctype=text/javascript');

importScriptURI('//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js' + '&action=raw&ctype=text/javascript');
var changeLogoLink = function() {
    $('#p-logo a').attr('href', '/wiki/Special:RecentChanges');
};
addOnloadHook(changeLogoLink);

if( wgCanonicalSpecialPageName === 'Contributions' ) {
  /*
   * Ez Userrights
   * @Author RansomTime
   *
   * Queries the API for the user groups of a user, and places it on their contribs masthead
   * Monobook only.
   * I think there's a script that does this for Oasis already and does it with those little
   * Floaty header things. If not then the API query stuff works - just find an id to put it on and this
   * script will work for that.
  */
  $(function() {
      var capFirstLtr = function(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
    };
 
    var user = mw.html.escape( $( 'input[name="target"]' ).val() );
    var query = {};
    query.list = "users";
    query.ususers = user;
    query.usprop = "groups";
    var api = new mw.Api();
    api.get(query).done(function(data) {
      var res = "";
      console.log(data);
      if (data && data.query && data.query.users) {
        for (var idx in data.query.users[0].groups) {
          right = data.query.users[0].groups[idx];
          if (right === "*" || right === "user" || right === "poweruser" || right === "autoconfirmed") { continue; }
          if (right === "wikiastars") { right = "star"; }
          if (right === "vstf") { right = "VSTF"; }
 
          if (res === "") {
            res += capFirstLtr(right);
          } else {
            res += "/" + capFirstLtr(right);
          }
 
        }
      }
      if (res !== "") {
        $('#firstHeading').html("Special:Contributions/" + user + " (" + res + ")");
      } else {
        $('#firstHeading').html("Special:Contributions/" + user);
      }
    });
  });
}