Change api methods to return and for loop instead

This commit is contained in:
Jiiks 2015-12-12 18:54:44 +02:00
parent 41752faf1d
commit aec8f9b93f
1 changed files with 24 additions and 20 deletions

View File

@ -1345,30 +1345,34 @@ BdApi.getCore = function() {
//Attempts to get user id by username //Attempts to get user id by username
//Name = username //Name = username
//Callback = callback function
//Since Discord hides users if there's too many, this will often fail //Since Discord hides users if there's too many, this will often fail
BdApi.getUserIdByName = function(name, callback) { BdApi.getUserIdByName = function(name) {
$(".member-username").each(function() { var users = $(".member-username");
if($(this).text() == name) {
var avatarUrl = $(this).closest(".member").find(".avatar-small").css("background-image"); for(var i = 0 ; i < users.length ; i++) {
var uid = avatarUrl.match(/\d+/); var user = $(users[i]);
callback(uid); if(user.text() == name) {
} console.log("FOUND: " + user);
}); var avatarUrl = user.closest(".member").find(".avatar-small").css("background-image");
return avatarUrl.match(/\d+/);
}
}
return null;
}; };
//Attempts to get username by id //Attempts to get username by id
//ID = user id //ID = user id
//Callback = callback function
//Since Discord hides users if there's too many, this will often fail //Since Discord hides users if there's too many, this will often fail
BdApi.getUserNameById = function(id, callback) { var gg;
$(".avatar-small").each(function() { BdApi.getUserNameById = function(id) {
var url = $(this).css("background-image"); var users = $(".avatar-small");
var uid = url.match(/\d+/);
for(var i = 0 ; i < users.length ; i++) {
if(uid == id) { var user = $(users[i]);
var uname = $(this).parent().find(".member-username").text(); var url = user.css("background-image");
callback(uname); if(id == url.match(/\d+/)) {
} return user.parent().find(".member-username").text();
}); }
}
return null;
}; };