Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[JavaScript] Returns an array of all of the names of a Trello boards members.
/**
* Retrieves a list of all of the members on a Trello board and stores and
* returns their names in an array. It will not include any duplicates.
*
* Trello names are usually represented as "Elliot Alderson (mrrobot)" but the
* returned array will only return an array with their actual name (that is,
* Ellio Alderson).
*
* This does not require jQuery or any third-party library to run. If you want
* to run this from the console of Chrome, then paste this entire function into
* your console, then execute the following line of code:
*
* - var names = get_trello_names();
*
* This will give you an array of all of the names that exist on your board.
*
* @return array names An array of all of the names of a Trello boards members.
*/
var get_trello_names = function() {
var members = [],
names = [],
name = '',
i, l;
// Get the members as an HTMLCollection and convert it to an array.
members = document.getElementsByClassName( 'member-avatar' );
members = [].slice.call( members );
/* Iterate through all of the members and all the name (without parentheses)
* to the array of members (adding unique names only).
*/
for ( i = 0, l = members.length; i < l; i++ ) {
name = members[ i ];
name = name.getAttribute( 'title' ).toString();
name = name.replace( /\(([^)]+)\)/, '' ).trim();
if ( -1 === names.indexOf( name ) ) {
names.push( name );
}
}
return names;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment