MediaWiki:Gadget-UserDetails.js: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
m (importScriptURI -> mw.loader.load)
(callback wasn't working. see if getScript does)
Line 5: Line 5:
* Note, all are assumed false if omitted. All but 'groups' are assumed false if undefined.
* Note, all are assumed false if omitted. All but 'groups' are assumed false if undefined.
var showUserGroupSettings = {
var showUserGroupSettings = {
   'IP':true,
   'IP': true,
   'unregistered':true,
   'unregistered': true,
   'registered':true,
   'registered': true,
   'groups': true,
   'groups': true,
   'groupless': true,
   'groupless': true,
   'editcount':true,
   'editcount': true,
   'regdate':true,
   'regdate': true,
   'blocked':true
   'blocked': true
};
};
*/
*/
Line 18: Line 18:
/* default behavior */
/* default behavior */
var showUserGroupSettings = {
var showUserGroupSettings = {
   'IP':false,
   'IP': false,
   'unregistered':true,
   'unregistered': true,
   'registered':false,
   'registered': false,
   'groups': false,
   'groups': false,
   'groupless': false,
   'groupless': false,
   'editcount':true,
   'editcount': true,
   'regdate':false,
   'regdate': false,
   'blocked':true
   'blocked': true
};
};


if((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) && mw.config.get('wgTitle').indexOf('/') == -1 && (mw.config.get('wgAction') != 'edit' || mw.config.get('wgAction') != 'submit')) $(showUserGroups)
if((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) &&
  mw.config.get('wgTitle').indexOf('/') == -1 &&
  mw.config.get('wgAction') != 'edit' &&
  mw.config.get('wgAction') != 'submit') {
  $(showUserGroups);
}
 
function showUserGroups() {
function showUserGroups() {
   var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&callback=showUserGroupsCB&maxage=3600&smaxage=3600&usprop=blockinfo|groups|editcount|registration&list=users&ususers=' + encodeURIComponent(mw.config.get('wgTitle'));
   var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&maxage=3600&smaxage=3600&usprop=blockinfo|groups|editcount|registration&list=users&ususers=' + encodeURIComponent(mw.config.get('wgTitle'));
   mw.loader.load(url);
   mw.loader.getScript(url).then(function(obj) {
}
    var show = window.showUserGroupSettings || false;
    if(!obj['query'] || !obj['query']['users']) return
    var user = obj['query']['users'];
    if(user.length == 0) return
    user = user[0];
    var someHeading = document.getElementsByTagName('h1')[0] || document.getElementsByTagName('h2')[0]
    if(!someHeading) return
   
   
function showUserGroupsCB(obj) {
    var span = document.createElement('span');
  var show = window.showUserGroupSettings || false;
    var title = 'User:' + user['name'] + ' ';
  if(!obj['query'] || !obj['query']['users']) return
    var text = ' ';
  var user = obj['query']['users'];
  if(user.length == 0) return
  user = user[0];
  var someHeading = document.getElementsByTagName('h1')[0] || document.getElementsByTagName('h2')[0]
  if(!someHeading) return
   
   
  var span = document.createElement('span');
    if(user['invalid'] == '') {
  var title = 'User:' + user['name'] + ' ';
      if(show && show.IP) text += '[IP] '
  var text = ' ';
      else title += '[invalid or IP username] '
    } else if(user['missing'] == '') {
  if(user['invalid'] == '') {
      if(show && show.unregistered) text += '[doesn\'t exist] '
    if(show && show.IP) text += '[IP] '
      else title += '[not a registered name] '
    else title += '[invalid or IP username] '
  } else if(user['missing'] == '') {
    if(show && show.unregistered) text += '[doesn\'t exist] '
    else title += '[not a registered name] '
  } else {
    if(show && show.registered) text += '[exists] '
    else title += '[username registered] '
    if(user['groups']) {
      if(show && show.groups || !show) text += '[user,' + user['groups'] + '] '
      else title += '[' + user['groups'] + '] '
     } else {
     } else {
       if(show && show.groupless) text += '[user] '
       if(show && show.registered) text += '[exists] '
      else title += '[user] '
      else title += '[username registered] '
    }
      if(user['groups']) {
    if(user['editcount']) {
        if(show && show.groups || !show) text += '[user,' + user['groups'] + '] '
      if(show && show.editcount) text += '[' + user['editcount'] + ' edits] '
        else title += '[' + user['groups'] + '] '
      else title += '[' + user['editcount'] + ' edits] '
      } else {
    }
        if(show && show.groupless) text += '[user] '
    if(user['registration']) {
        else title += '[user] '
      if(show && show.regdate) text += '[created: ' + user['registration'].split('T')[0] + '] '
      }
      else title += '[created: ' + user['registration'] + '] '
      if(user['editcount']) {
    }
        if(show && show.editcount) text += '[' + user['editcount'] + ' edits] '
    if(user['blockedby']) {  
        else title += '[' + user['editcount'] + ' edits] '
      if(show && show.blocked) text += '[blocked] '
      }
      else text += '[currently blocked] '
      if(user['registration']) {
        if(show && show.regdate) text += '[created: ' + user['registration'].split('T')[0] + '] '
        else title += '[created: ' + user['registration'] + '] '
      }
      if(user['blockedby']) {  
        if(show && show.blocked) text += '[blocked] '
        else text += '[currently blocked] '
      }
     }
     }
  }
   
   
  span.setAttribute('class','detected-userdetails');
    span.setAttribute('class','detected-userdetails');
  span.appendChild(document.createTextNode(text));
    span.appendChild(document.createTextNode(text));
  someHeading.appendChild(span);
    someHeading.appendChild(span);
  someHeading.setAttribute('title',title);
    someHeading.setAttribute('title',title);
  someHeading.className += ' detected-userdetails-heading';
    someHeading.className += ' detected-userdetails-heading';
  });
}
}

Revision as of 00:51, June 21, 2020

/* 
Options:
* Now supports an option system. 
* By setting a datalet true it shows in the header instead of the title.
* Note, all are assumed false if omitted. All but 'groups' are assumed false if undefined.
var showUserGroupSettings = {
  'IP': true,
  'unregistered': true,
  'registered': true,
  'groups': true,
  'groupless': true,
  'editcount': true,
  'regdate': true,
  'blocked': true
};
*/

/* default behavior */
var showUserGroupSettings = {
  'IP': false,
  'unregistered': true,
  'registered': false,
  'groups': false,
  'groupless': false,
  'editcount': true,
  'regdate': false,
  'blocked': true
};

if((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) &&
  mw.config.get('wgTitle').indexOf('/') == -1 &&
  mw.config.get('wgAction') != 'edit' &&
  mw.config.get('wgAction') != 'submit') {
  $(showUserGroups);
}

function showUserGroups() {
  var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&maxage=3600&smaxage=3600&usprop=blockinfo|groups|editcount|registration&list=users&ususers=' + encodeURIComponent(mw.config.get('wgTitle'));
  mw.loader.getScript(url).then(function(obj) {
    var show = window.showUserGroupSettings || false;
    if(!obj['query'] || !obj['query']['users']) return
    var user = obj['query']['users'];
    if(user.length == 0) return
    user = user[0];
    var someHeading = document.getElementsByTagName('h1')[0] || document.getElementsByTagName('h2')[0]
    if(!someHeading) return
 
    var span = document.createElement('span');
    var title = 'User:' + user['name'] + ' ';
    var text = ' ';
 
    if(user['invalid'] == '') {
      if(show && show.IP) text += '[IP] '
      else title += '[invalid or IP username] '
    } else if(user['missing'] == '') {
      if(show && show.unregistered) text += '[doesn\'t exist] '
      else title += '[not a registered name] '
    } else {
      if(show && show.registered) text += '[exists] '
      else title += '[username registered] '
      if(user['groups']) {
        if(show && show.groups || !show) text += '[user,' + user['groups'] + '] '
        else title += '[' + user['groups'] + '] '
      } else {
        if(show && show.groupless) text += '[user] '
        else title += '[user] '
      }
      if(user['editcount']) {
        if(show && show.editcount) text += '[' + user['editcount'] + ' edits] '
        else title += '[' + user['editcount'] + ' edits] '
      }
      if(user['registration']) {
        if(show && show.regdate) text += '[created: ' + user['registration'].split('T')[0] + '] '
        else title += '[created: ' + user['registration'] + '] '
      }
      if(user['blockedby']) { 
        if(show && show.blocked) text += '[blocked] '
        else text += '[currently blocked] '
      }
    }
 
    span.setAttribute('class','detected-userdetails');
    span.appendChild(document.createTextNode(text));
    someHeading.appendChild(span);
    someHeading.setAttribute('title',title);
    someHeading.className += ' detected-userdetails-heading';
  });
}