MediaWiki:Gadget-Gender.js: Difference between revisions
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
mNo edit summary |
(rewrite using $.getJSON) |
||
Line 5: | Line 5: | ||
$(function() { | $(function() { | ||
// init AJAX and request the user's gender from the API | // init AJAX and request the user's gender from the API | ||
$.getJSON( | |||
mw.util.wikiScript( 'api' ), | |||
{ | |||
format: 'json', | |||
action: 'query', | |||
list: 'users', | |||
ususers: escape(wgTitle.replace(/ /, "_")), | |||
usprop: 'gender' | |||
}, | |||
function( response ) { | |||
var genderText = | var genderText = response.query.users[0].gender; | ||
// U+2640 and U+2642 are female and male signs respectively. | // U+2640 and U+2642 are female and male signs respectively. | ||
var genderSymbol = ""; | var genderSymbol = ""; | ||
Line 25: | Line 24: | ||
genderSymbol = "<span class=\"male-icon\">♂</span>"; | genderSymbol = "<span class=\"male-icon\">♂</span>"; | ||
} | } | ||
// if gender was specified, append the symbol | // if gender was specified, append the symbol | ||
if (genderSymbol != "") { | if (genderSymbol != "") { | ||
Line 33: | Line 31: | ||
} | } | ||
} | } | ||
); | |||
}); | }); | ||
} | } |
Revision as of 02:54, March 17, 2017
// If on a user or user talk page, and not a subpage... if ((wgNamespaceNumber == 2 || wgNamespaceNumber == 3) && !/\//.test(wgTitle)) { // add a hook to... $(function() { // init AJAX and request the user's gender from the API $.getJSON( mw.util.wikiScript( 'api' ), { format: 'json', action: 'query', list: 'users', ususers: escape(wgTitle.replace(/ /, "_")), usprop: 'gender' }, function( response ) { var genderText = response.query.users[0].gender; // U+2640 and U+2642 are female and male signs respectively. var genderSymbol = ""; if (genderText == "female") { genderSymbol = "<span class=\"female-icon\">♀</span>"; } else if (genderText == "male") { genderSymbol = "<span class=\"male-icon\">♂</span>"; } // if gender was specified, append the symbol if (genderSymbol != "") { document.getElementById("firstHeading").innerHTML += " " + genderSymbol; } } ); }); }