tauame / Torn Totalizador plushie/flower

// ==UserScript==
// @name         Torn Totalizador plushie/flower
// @namespace    setTotal.torn.tauame
// @version      0.1
// @description  Exibe valor total dos Plushies e Flowers no Item market do Torn
// @author       tauame
// @match        https://www.torn.com/imarket.php*
// @grant        none
// @license GPL-3.0-or-later
// @updateURL https://openuserjs.org/meta/tauame/Torn_Totalizador_plushieflower.meta.js
// @downloadURL https://openuserjs.org/install/tauame/Torn_Totalizador_plushieflower.user.js
// ==/UserScript==


function showSetValue(){
    var plushieContainer = $("#plushies");
    var flowerContainer = $("#flowers");

    if(!plushieContainer.length || !flowerContainer.length){
        //page not loaded yet
        return;
    }

    var container;
    var category;
    if(plushieContainer.attr("aria-hidden")=="false") {
        container = plushieContainer;
        category = "plushies";
    }
    if(flowerContainer.attr("aria-hidden")=="false") {
        container = flowerContainer;
        category = "flowers";
    }

    if(category == "plushies" && !$('li[data-item="258"]').length)return;
    if(category == "flowers" && !$('li[data-item="282"]').length)return;

    if(!$("#"+category+"-totalvalue-custom").length){
        container.prepend("<p id=\""+category+"-totalvalue-custom\"></p>");
    }

    if(container.attr("aria-hidden")=="true")return;

    var totalValueElement = $("#"+category+"-totalvalue-custom");
    var totalValue = 0;

    var plushieList = [215,187,186,261,618,258,266,268,269,273,384,281,274];
    var flowerList = [260,263,617,264,271,272,267,277,282,276,385];

    var itemList;
    if(category == "plushies"){
        itemList = plushieList;
    }else if(category == "flowers"){
        itemList = flowerList;
    }

    for(var i = 0; i<itemList.length; i++){
        var item = $("li[data-item="+itemList[i]+"]").find(".minprice");
        var itemValueText = item
                    .clone()    //clone the element
                    .children() //select all the children
                    .remove()   //remove all the children
                    .end()  //again go back to selected element
                    .text();
        totalValue += parseInt(itemValueText.replace("$","").replace(",",""));
    }

    if(totalValueElement.text().search(""+totalValue)==-1){
        totalValueElement.text("Valor total do set: $"+totalValue);
    }

}



(function() {
    'use strict';



     var obsConfig = {
            childList: true,
            attributes: true,
            characterData: true,
            subtree: true,
            attributeOldValue: true,
            characterDataOldValue: true
        };
    var itemObserver = new MutationObserver(function(mutations) {
        showSetValue();
    });
    itemObserver.observe (document.body, obsConfig);
})();