advancedev / Roblox Clothing

// ==UserScript==
// @name         Roblox Clothing
// @namespace    http://your.homepage/
// @version      2.0.0
// @description  This will show you what every one is whereing.
// @author       Advancedev
// @include	        *://*.roblox.com/*ser.aspx?*=*
// @match        http://www.roblox.com/User.aspx?ID=15035874&ForcePublicView=true
// @require         http://code.jquery.com/jquery-1.11.1.min.js
// @require         http://code.jquery.com/jquery-2.1.3.min.js
// @noframes
// @grant           unsafeWindow
// @run-at          document-body
// @copyright       2015
// ==/UserScript==

var ScriptVersion = "2.0.0";
var ScriptText = "Bug fixes, and support for IE.";

function Create(ElementType){return document.createElement(ElementType)};
function OpenURL(LinkURL){location.href = LinkURL};

$(document).ready(function(){
	if (location.href.toLowerCase().indexOf("/user.aspx?id=") <= 0){return false};
    var ContentBar = $("div.divider-right"), UserID = location.href.toLowerCase().match(/user.aspx\?id=(\d+)/i)[1];
    
    if (ContentBar !== null){
         function DisplayItem(AssetID){
            var P_Overlay = Create("div"), P_Main = Create("div");
            $(P_Overlay).attr("class", "simplemodal-overlay").attr("style", "height:100%;width:100%;position:fixed;left:0;top:0;z-index:1001;background:rgba(0,0,0,.8);");
            $(P_Main).attr("class", "simplemodal-container");
            $(P_Main).attr("style", "position:absolute;z-index:1002;height:72px;width:200px;left:50%;top:50%;margin:-36px 0 0 -100px;color:#fff;text-align:center;");
            $(P_Main).append('<p class="processing-indicator"><img src="http://ow.ly/zkKoY" alt="Loading..."></p>');
            $(P_Main).append('<p class="processing-text">Loading details...</p>');
            $(P_Overlay).append(P_Main);
            $("body").append(P_Overlay);
            
            $.get("http://www.roblox.com/Item.aspx?id="+AssetID, function(G_Data){
                var PageMain = $(G_Data).find("#ItemContainer");
                var ItemTitle = $(PageMain).find('h1[data-se="item-name"]:eq(0)').text();
                var ItemDesc = $(PageMain).find('pre[class="Description Full text"]:eq(0)').text();
                
                if (ItemTitle !== null && ItemDesc !== null){
                	var MarketData = Create("div");
                    $(MarketData).attr("style", "width:100%;height:75px;overflow:auto;").append(ItemDesc);
                    
                    if (window.ActiveXObject || "ActiveXObject" in window){
                    	OpenURL("/Item.aspx?id="+AssetID);
                    }else{
	                    Roblox.GenericConfirmation.open({
	                        titleText: ItemTitle, bodyContent: MarketData, xToCancel: true,
	                        imageUrl: "/Thumbs/Asset.ashx?width=420&height=420&AssetID="+AssetID,
	                        dismissable: true, onAccept: function(){OpenURL("/Item.aspx?id="+AssetID)},
	                        allowHtmlContentInBody: true, acceptColor: Roblox.GenericConfirmation.green,
	                        acceptText: "View", declineText: "Cancel"
	                    });
                    };
                }else{OpenURL("/Item.aspx?id="+AssetID);};
            })
            .fail(function(){OpenURL("/Item.aspx?id="+AssetID)})
            .always(function(){P_Overlay.remove()});
        };
        
        var NewDiv = Create("div");
        $(NewDiv).attr("class", "divider-bottom");
        
        var NewBtn = Create("a");
        $(NewBtn).attr("class", "btn-medium btn-negative").attr("style", "margin:10px 5px 10px 0;").html("Fetching...");
        
        $(NewDiv).append(NewBtn).append('<p style="display:inline;">Created by <a href="/User.aspx?id=15035874">Advancedev</a>.</p>');
        $(NewDiv).insertBefore(ContentBar.find('h2[class="title"]:eq(1)'));
        $(NewDiv).append('<p style="margin:0 0 5px 1px;font-size:11px;"><b>Version '+ScriptVersion+'</b> '+ScriptText+'</p>');
        
        $.get("http://www.roblox.com/Asset/AvatarAccoutrements.ashx?userId="+UserID)
        .done(function(G_Data){
            var DataItems = G_Data.toString().split(";");
            var D_Items = []; $.each(DataItems, function(D_Key, D_Val){if (D_Val.toLowerCase().indexOf("bodycolors.ashx") == -1){D_Items.push(D_Val.match(/id=(\d+)/i)[1])}});
			DataItems.length = 0; $.each(D_Items, function(D_Key, D_Val){DataItems.push(D_Val)});
            
            if (DataItems.length > 0){
                var NewUL = Create("ul");
                $(NewUL).attr("style", "list-style-type:none;margin:0;padding:0;").hide();
                $(NewDiv).append(NewUL);
                
                $.each(DataItems, function(D_Key, D_Val){
                    var NewItemA = Create("a");
                    $(NewItemA).attr("style", "cursor:pointer;").append('<img style="width:110px;height:110px;" src="/Thumbs/Asset.ashx?width=420&height=420&AssetID='+D_Val+'"/>');
                    $(NewItemA).attr("href", "http://www.roblox.com/Item.aspx?id="+D_Val).click(function(){DisplayItem(D_Val); return false;});
                    $(NewUL).append('<li style="display:inline-block !important;margin:0;padding:0;">').append(NewItemA).append('</li>');
                });
                
                $(NewBtn).attr("class", "btn-medium btn-neutral").html("Clothing").click(function(){$(NewUL).slideToggle()});
            }else{
                $(NewBtn).html("Wardrobe").click(function(){
                    Roblox.GenericModal.open("Wardrobe", null, "This user isn't wearing anything. The button will light-up blue if a user has clothing on.");
                });
            };
        })
        .fail(function(){
            $(NewBtn).html("Failed").click(function(){
            	Roblox.GenericModal.open("Clothing", null, "An error occurred. Couldn't get this user's currently worn assets.");
            });
        });
    };
});