ClockworkSquirrel / ROBLOX - Populate User Search

// ==UserScript==
// @name         ROBLOX - Populate User Search
// @description  Displays 20 popular users in the search page if results turn up nothing.
// @author       ClockworkSquirrel
// @version      1.0.0
//
// @match        https://*.roblox.com/search/users*
// @require      https://code.jquery.com/jquery-3.1.1.min.js
// @icon         http://svgshare.com/i/HP.svg
//
// @run-at       document-end
// @grant        unsafeWindow
// ==/UserScript==

var settings = {
	quantity: 40,
	animateLoad: false
};

var resource = {
	gameList: "/games/moreresultscached?SortFilter=1&MaxRows="+settings.quantity,
	avatar: "http://assetgame.roblox.com/Thumbs/Avatar.ashx?username=",
	loader: "https://i.imgur.com/YxHLbcs.gif"
};

(function(){
	'use strict';

	function create(Element){return $(document.createElement(Element));}

	function populateUserList(){
		if ($("div#peoplesearch-results").length > 0){
			var navBarSearch = $("input#navbar-search-input").focus();
			var searchForm = $("div#PeopleSearchContainer div:eq(0)");
			navBarSearch.val(searchForm.find("input").val());
			
			searchForm.find("span").remove();
			searchForm.find("input").focus(function(){navBarSearch.focus();}).attr("class", "form-control input-field-disabled").css("width", ($("div#Results").width()-28)+"px");
			return;
		}

		var resultsDiv = $("div#Results").html("");
		var peopleResults = create("div").attr("id", "peoplesearch-results")
		.addClass("peoplesearch-result-container").appendTo(resultsDiv).slideUp();

		var loaderImg = create("img").attr("src", resource.loader).attr("height", "40px")
		.appendTo(create("center").appendTo(resultsDiv));

		$.get(resource.gameList, function(data){
			$("div#PeopleSearchContainer div:eq(0)").slideUp().promise().done(function(){
				$(this).html("").append(create("h2").html("<b>Sorry!</b> No results found!")).slideDown().promise().done(function(){
					$(data).find("span.game-card-footer a[href]").each(function(thisIndex){
						var thisUser = $(this).text();

						var itemContainer = create("div").addClass("divider-top").addClass("result-item-container").attr("data-userpageurl", $(this).attr("href"));
						var avImgContainer = create("div").addClass("avatar-image-container").addClass("notranslate").appendTo(itemContainer);
						var avImgLink = create("span").addClass("avatar-image-link").appendTo(avImgContainer);
						create("img").attr("alt", thisUser).addClass("avatar-image").attr("src", resource.avatar+thisUser).appendTo(avImgLink);

						var textContainer = create("div").addClass("text-container").addClass("text").appendTo(itemContainer);
						var textSubcontainer = create("div").addClass("notranslate").appendTo(textContainer);
						textSubcontainer.append(create("a").attr("href", $(this).attr("href")).text(thisUser));
						textContainer.append(create("div").addClass("notranslate").addClass("linkify"));

						var viewButton = create("div").addClass("view-button").appendTo(itemContainer);
						viewButton.append(create("span").text("Trending: #"+(thisIndex+1)));

						itemContainer.append(create("div").addClass("clear")).appendTo(peopleResults);
					}).promise().done(function(){
						if (settings.animateLoad) peopleResults.slideDown(2000); else peopleResults.show();
						loaderImg.parent().remove();
					});
				});
			});
		});
	}

	$(document).ready(populateUserList);
})();