// ==UserScript==
// @name         Auto Sell Items using Enhanced Steam Google Chrome plugin
// @namespace    http://github.com/taeram/user-scripts/
// @version      1.1.1
// @description  Auto sell items in your Steam Inventory using the "Quick Sell" feature of the Enhanced Steam google chrome plugin: https://chrome.google.com/webstore/detail/enhanced-steam/okadibdjfemgnhjiembecghcbfknbfhg
// @author       You
// @match        https://steamcommunity.com/id/*/inventory/
// @grant        none
// ==/UserScript==

var reloadPageInterval = 300; // seconds

var jQueryFound = (typeof(jQuery) !== 'undefined');
if (!jQueryFound) {
    script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
    document.getElementsByTagName("body")[0].appendChild(script);
}

function autoSellAnItem() {
    var items = jQuery('.itemHolder .item.context6');
    for (var i=0; i < items.length; i++) {
        var isGems = jQuery(items[i]).find('.item_currency_amount').length > 0;
        var isSold = jQuery(items[i]).hasClass('btn_disabled');
        if (!isGems && !isSold) {
            jQuery(items[i]).find('.inventory_item_link').click();
            setTimeout(function () {
                var itemName = jQuery('.item_desc_description .hover_item_name').text();
                console.log("Attempting to sell " + itemName);
                var marketActions = jQuery('.item_market_actions');
                for (var j=0; j < marketActions.length; j++) {
                    if (jQuery(marketActions[j]).is(':visible')) {
                        var marketActionButtons = jQuery(marketActions[j]).find('.btn_small');
                        for (var k = 0; k < marketActionButtons.length; k++) {
                            if (jQuery(marketActionButtons[k]).attr('id').match(/es_quicksell/)) {
                                var quickSellPrice = jQuery(marketActionButtons[k]).attr('price');
                                console.log("Quick Selling " + itemName + " for $" + quickSellPrice);
                                jQuery(marketActionButtons[k]).find('span').click();
                                return;
                            } else if (jQuery(marketActionButtons[k]).attr('id').match(/es_instantsell/)) {
                                var instantSellPrice = jQuery(marketActionButtons[k]).attr('price');
                                console.log("Instant Selling " + itemName + " for $" + instantSellPrice);
                                jQuery(marketActionButtons[k]).find('span').click();
                                return;
                            }
                        }
                    }
                }
            }, 2000);
            return;
        }
    }
    
    // Reload the page and wait for more items to appear
    console.log("Didn't find anything to sell, waiting to reload the page in " + reloadPageInterval + " seconds");
    setTimeout(function () {
        window.location.reload();
    }, reloadPageInterval * 1000);
}

// Add an "Auto Sell" button
var autoSellButton = jQuery('<button class="btn_green_white_innerfade btn_medium" style="margin-right: 12px"><span>Auto-Sell Inventory</span></button>').prependTo('.inventory_rightnav');
jQuery(autoSellButton).on('click', function () {
    // Turn off auto sell if the button is clicked again
    if (localStorage.getItem('auto_sell_enabled') == "true") {
        localStorage.setItem('auto_sell_enabled', false);
        return;
    }
    
    // Enable auto selling so it persists between page loads
    localStorage.setItem('auto_sell_enabled', true);
    
    autoSellAnItem();
});

// Automatically try and sell something if the button is enabled
if (localStorage.getItem('auto_sell_enabled') == "true") {
    // Wait for the page to load
    setTimeout(autoSellAnItem, 5000);
}

@@ -161,19 +161,19 @@
       1.
-1.1
+2.0
 %0A// @des
@@ -1320,16 +1320,24 @@
 cription
+:visible
  .hover_
@@ -1348,16 +1348,144 @@
 _name').
+first().text();%0A                var itemType = jQuery('.item_desc_description:visible .item_desc_game_info %3E div:last').first().
 text();%0A
@@ -1544,16 +1544,40 @@
 itemName
+ + %22 (%22 + itemType + %22)%22
 );%0A     
@@ -2919,17 +2919,17 @@
      %7D, 
-2
+3
 000);%0A  
@@ -3851,16 +3851,56 @@
 Item();%0A
+    setInterval(autoSellAnItem, 10000);%0A
 %7D);%0A%0A// 
@@ -4068,30 +4068,105 @@
 Timeout(
-autoSellAnItem
+function () %7B%0A        autoSellAnItem();%0A        setInterval(autoSellAnItem, 10000);%0A    %7D
 , 5000);
@@ -4162,14 +4162,19 @@
   %7D, 5000);%0A
+    %0A
 %7D%0A

Fix selling multiple items at a time