Shido / Targowisko

// ==UserScript==
// @name Targowisko
// @namespace /amorion_targ/
// @include *amorion.pl/start.php*
// @include *147.135.199.206/start.php*
// @version 3.0
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @license MIT
// ==/UserScript==

$("noscript").after("<div id=\"targowisko_div\"><b>Targowisko</b><br/><buton id=\"tagowisko_check\" class=\"tg_btn\">Sprawdź Ceny</button></div>");

$("#targowisko_div").css('position', 'fixed');
$("#targowisko_div").css('bottom', '270px');
$("#targowisko_div").css('left', '10px');
$("#targowisko_div").css('background', '#1B1B1B');
$("#targowisko_div").css('opacity', '0.75');
$("#targowisko_div").css('border', '3px outset white');
$("#targowisko_div").css('padding', '10px');
$("#targowisko_div").css('width', '120px');
$("#targowisko_div").css('text-align', 'center');

$(".tg_btn").css('padding-left', '10px');
$(".tg_btn").css('padding-right', '10px');
$(".tg_btn").css('cursor', 'pointer');
$(".tg_btn").css('color', '#BBBBBB');
$(".tg_btn").css('font-weight', 'bold');
$(".tg_btn").css('background-color', '#000000');
$(".tg_btn").css('border', '1px solid #B0B0B0');

var tg_step = 0;

var tg_prince = [];
    tg_prince['miedz'] = [];
    tg_prince['zelazo'] = [];
    tg_prince['wegiel'] = [];
    tg_prince['meteor'] = [];
    tg_prince['adamantium'] = [];
    tg_prince['krysztal'] = [];
    tg_prince['D_wiaz'] = [];
    tg_prince['sosna'] = [];
    tg_prince['mithrill'] = [];
    tg_prince['illani'] = [];
    tg_prince['illanias'] = [];
    tg_prince['nutari'] = [];
    tg_prince['dynallec'] = [];

var tg_wykup = ["Żelazo", "Meteor", "Illanias", "Nutari", "Dynallec"];

function f_tg_debug(type, funct, string)
{
    if(true)
    {
        if(type == 1)
        {
            console.debug('----------------' + funct + '----------------');
        }
        else
        {
            console.debug('[' +type + '] : ' + funct);
        }
    }
}

function f_tar_price()
{
    if(tg_step == 1)
    {
        Link('dynamic', 'magazyn.php');
    }
    else if(tg_step == 2)
    {
        tg_prince['miedz']['nazwa']             = "Miedz";
        tg_prince['miedz']['skup']                 = $(".lcol2pl:contains('miedzi') td:nth-child(2)").html();
        tg_prince['miedz']['sprzedarz']         = $(".lcol2pl:contains('miedzi') td:nth-child(3)").html();
        tg_prince['miedz']['ilosc']             = $(".lcol2pl:contains('miedzi') td:nth-child(4)").html();

        tg_prince['zelazo']['nazwa']             = "Żelazo";
        tg_prince['zelazo']['skup']             = $(".lcol1pl:contains('żelaza') td:nth-child(2)").html();
        tg_prince['zelazo']['sprzedarz']         = $(".lcol1pl:contains('żelaza') td:nth-child(3)").html();
        tg_prince['zelazo']['ilosc']             = $(".lcol1pl:contains('żelaza') td:nth-child(4)").html();

        tg_prince['wegiel']['nazwa']             = "Wegiel";
        tg_prince['wegiel']['skup']             = $(".lcol1pl:contains('węgla') td:nth-child(2)").html();
        tg_prince['wegiel']['sprzedarz']         = $(".lcol1pl:contains('węgla') td:nth-child(3)").html();
        tg_prince['wegiel']['ilosc']             = $(".lcol1pl:contains('węgla') td:nth-child(4)").html();

        tg_prince['meteor']['nazwa']             = "Meteor";
        tg_prince['meteor']['skup']             = $(".lcol1pl:contains('meteorytu') td:nth-child(2)").html();
        tg_prince['meteor']['sprzedarz']         = $(".lcol1pl:contains('meteorytu') td:nth-child(3)").html();
        tg_prince['meteor']['ilosc']             = $(".lcol1pl:contains('meteorytu') td:nth-child(4)").html();

        tg_prince['adamantium']['nazwa']         = "Adamantium";
        tg_prince['adamantium']['skup']         = $(".lcol2pl:contains('adamantium') td:nth-child(2)").html();
        tg_prince['adamantium']['sprzedarz']     = $(".lcol2pl:contains('adamantium') td:nth-child(3)").html();
        tg_prince['adamantium']['ilosc']         = $(".lcol2pl:contains('adamantium') td:nth-child(4)").html();

        tg_prince['krysztal']['nazwa']             = "Krysztal";
        tg_prince['krysztal']['skup']             = $(".lcol2pl:contains('Kryształy') td:nth-child(2)").html();
        tg_prince['krysztal']['sprzedarz']         = $(".lcol2pl:contains('Kryształy') td:nth-child(3)").html();
        tg_prince['krysztal']['ilosc']             = $(".lcol2pl:contains('Kryształy') td:nth-child(4)").html();

        tg_prince['D_wiaz']['nazwa']             = "Wiąz";
        tg_prince['D_wiaz']['skup']             = $(".lcol2pl:contains('wiązu') td:nth-child(2)").html();
        tg_prince['D_wiaz']['sprzedarz']         = $(".lcol2pl:contains('wiązu') td:nth-child(3)").html();
        tg_prince['D_wiaz']['ilosc']             = $(".lcol2pl:contains('wiązu') td:nth-child(4)").html();

        tg_prince['mithrill']['nazwa']             = "Mithril";
        tg_prince['mithrill']['skup']             = $(".lcol1pl:contains('Mithril') td:nth-child(2)").html();
        tg_prince['mithrill']['sprzedarz']         = $(".lcol1pl:contains('Mithril') td:nth-child(3)").html();
        tg_prince['mithrill']['ilosc']             = $(".lcol1pl:contains('Mithril') td:nth-child(4)").html();

        tg_prince['sosna']['nazwa']             = "Sosna";
        tg_prince['sosna']['skup']             = $(".lcol1pl:contains('sosnowe') td:nth-child(2)").html();
        tg_prince['sosna']['sprzedarz']         = $(".lcol1pl:contains('sosnowe') td:nth-child(3)").html();
        tg_prince['sosna']['ilosc']             = $(".lcol1pl:contains('sosnowe') td:nth-child(4)").html();

        tg_prince['illani']['nazwa']             = "Illani";
        tg_prince['illani']['skup']             = $(".lcol2pl:contains('Illani') td:nth-child(2)").html();
        tg_prince['illani']['sprzedarz']         = $(".lcol2pl:contains('Illani') td:nth-child(3)").html();
        tg_prince['illani']['ilosc']             = $(".lcol2pl:contains('Illani') td:nth-child(4)").html();

        tg_prince['illanias']['nazwa']             = "Illanias";
        tg_prince['illanias']['skup']            = $(".lcol1pl:contains('Illanias') td:nth-child(2)").html();
        tg_prince['illanias']['sprzedarz']        = $(".lcol1pl:contains('Illanias') td:nth-child(3)").html();
        tg_prince['illanias']['ilosc']             = $(".lcol1pl:contains('Illanias') td:nth-child(4)").html();

        tg_prince['nutari']['nazwa']             = "Nutari";
        tg_prince['nutari']['skup']             = $(".lcol2pl:contains('Nutari') td:nth-child(2)").html();
        tg_prince['nutari']['sprzedarz']        = $(".lcol2pl:contains('Nutari') td:nth-child(3)").html();
        tg_prince['nutari']['ilosc']             = $(".lcol2pl:contains('Nutari') td:nth-child(4)").html();

        tg_prince['dynallec']['nazwa']             = "Dynallec";
        tg_prince['dynallec']['skup']             = $(".lcol1pl:contains('Dynallca') td:nth-child(2)").html();
        tg_prince['dynallec']['sprzedarz']        = $(".lcol1pl:contains('Dynallca') td:nth-child(3)").html();
        tg_prince['dynallec']['ilosc']             = $(".lcol1pl:contains('Dynallca') td:nth-child(4)").html();

        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Ruda miedzi&order=ASC&own=');
    }
    else if(tg_step == 3)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['miedz']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['miedz']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['miedz']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['miedz']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Ruda żelaza&order=ASC&own=');
    }
    else if(tg_step == 4)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['zelazo']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['zelazo']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['zelazo']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['zelazo']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Bryły węgla&order=ASC&own=');
    }
    else if(tg_step == 5)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['wegiel']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['wegiel']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['wegiel']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['wegiel']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Kawałki meteorytu&order=ASC&own=');
    }
    else if(tg_step == 6)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['meteor']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['meteor']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['meteor']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['meteor']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Bryły adamantium&order=ASC&own=');
    }
    else if(tg_step == 7)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['adamantium']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['adamantium']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['adamantium']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['adamantium']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Kryształy&order=ASC&own=');
    }
    else if(tg_step == 8)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['krysztal']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['krysztal']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['krysztal']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['krysztal']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Drewno z wiązu&order=ASC&own=');
    }
    else if(tg_step == 9)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['D_wiaz']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['D_wiaz']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['D_wiaz']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['D_wiaz']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Mithril&order=ASC&own=');
    }
    else if(tg_step == 10)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['mithrill']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['mithrill']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['mithrill']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['mithrill']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'pmarket.php?view=market&lista=cost&limit=0&szukany=Drewno sosnowe&order=ASC&own=');
    }
    else if(tg_step == 11)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['sosna']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['sosna']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['sosna']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['sosna']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'hmarket.php?view=market&lista=cost&limit=0&szukany=Illani&order=ASC&own=');
    }
    else if(tg_step == 12)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['illani']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['illani']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['illani']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['illani']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'hmarket.php?view=market&lista=cost&limit=0&szukany=Illanias&order=ASC&own=');
    }
    else if(tg_step == 13)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['illanias']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['illanias']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['illanias']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['illanias']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'hmarket.php?view=market&lista=cost&limit=0&szukany=Nutari&order=ASC&own=');
    }
    else if(tg_step == 14)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['nutari']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['nutari']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['nutari']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['nutari']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'hmarket.php?view=market&lista=cost&limit=0&szukany=Dynallca&order=ASC&own=')
    }
    else if(tg_step == 15)
    {
        $("tbody").html($("tbody").html().replace("lcol3pl", "lcol2pl"));

        tg_prince['dynallec']['ryn-ilosc'] = $(".lcol2pl:first td:nth-child(2)").html();
        tg_prince['dynallec']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html();
        tg_prince['dynallec']['ryn-kto'] = $(".lcol2pl:first td:nth-child(4) a").html();
        if($(".lcol2pl:first td:nth-child(4) a").html() == "Bercbelly")
        {
            tg_prince['dynallec']['ryn-cena'] = $(".lcol2pl:first td:nth-child(3) span").html() + "#";
        }
        Link('dynamic', 'city.php');
    }
    else if(tg_step == 16)
    {
        $("#tablicagraczy").after("<div id=\"tg_ceny\"></div>");
        var tg_cen     = "<input type=\"text\" value=\""
                    + "" + tg_prince['miedz']['sprzedarz']             + "&#9;" + tg_prince['miedz']['ilosc']         + "&#9;" + tg_prince['miedz']['ryn-cena']         + "&#9;" + tg_prince['miedz']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['zelazo']['sprzedarz']     + "&#9;" + tg_prince['zelazo']['ilosc']     + "&#9;" + tg_prince['zelazo']['ryn-cena']         + "&#9;" + tg_prince['zelazo']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['wegiel']['sprzedarz']     + "&#9;" + tg_prince['wegiel']['ilosc']     + "&#9;" + tg_prince['wegiel']['ryn-cena']         + "&#9;" + tg_prince['wegiel']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['meteor']['sprzedarz']     + "&#9;" + tg_prince['meteor']['ilosc']     + "&#9;" + tg_prince['meteor']['ryn-cena']         + "&#9;" + tg_prince['meteor']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['adamantium']['sprzedarz'] + "&#9;" + tg_prince['adamantium']['ilosc'] + "&#9;" + tg_prince['adamantium']['ryn-cena']     + "&#9;" + tg_prince['adamantium']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['krysztal']['sprzedarz']     + "&#9;" + tg_prince['krysztal']['ilosc']     + "&#9;" + tg_prince['krysztal']['ryn-cena']     + "&#9;" + tg_prince['krysztal']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['D_wiaz']['sprzedarz']     + "&#9;" + tg_prince['D_wiaz']['ilosc']     + "&#9;" + tg_prince['D_wiaz']['ryn-cena']         + "&#9;" + tg_prince['D_wiaz']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['sosna']['sprzedarz']     + "&#9;" + tg_prince['sosna']['ilosc']     + "&#9;" + tg_prince['sosna']['ryn-cena']         + "&#9;" + tg_prince['sosna']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['mithrill']['sprzedarz']     + "&#9;" + tg_prince['mithrill']['ilosc']     + "&#9;" + tg_prince['mithrill']['ryn-cena']    + "&#9;" + tg_prince['mithrill']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['illani']['sprzedarz']     + "&#9;" + tg_prince['illani']['ilosc']     + "&#9;" + tg_prince['illani']['ryn-cena']         + "&#9;" + tg_prince['illani']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['illanias']['sprzedarz']     + "&#9;" + tg_prince['illanias']['ilosc']     + "&#9;" + tg_prince['illanias']['ryn-cena']     + "&#9;" + tg_prince['illanias']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['nutari']['sprzedarz']     + "&#9;" + tg_prince['nutari']['ilosc']     + "&#9;" + tg_prince['nutari']['ryn-cena']         + "&#9;" + tg_prince['nutari']['ryn-ilosc'] + ""
                    + "&#9;" + tg_prince['dynallec']['sprzedarz']     + "&#9;" + tg_prince['dynallec']['ilosc']     + "&#9;" + tg_prince['dynallec']['ryn-cena']     + "&#9;" + tg_prince['dynallec']['ryn-ilosc'] + ""
                    + "\"/>"

        $("#tg_ceny").html(tg_cen);

        $("#tg_ceny table td").css("width", "5px");
    }
    else if(tg_step == 17)
    {
        var tg_prince1 = Object.values(tg_prince);
        for (var i = 0; i < tg_prince1.length; i++)
        {
            tg_prince1[i]['ryn-cena'] = tg_prince1[i]['ryn-cena'].replace("#", "");

            if(parseInt(tg_prince1[i]['ryn-cena']) < parseInt(tg_prince1[i]['skup']))
            {
                alert(tg_prince1[i]['nazwa'] + " ma cene mniejsza niz skup!");
            }
            if(parseInt(tg_prince1[i]['ilosc']) > 0 && tg_wykup.indexOf(tg_prince1[i]['nazwa']) >= 0)
            {
                alert(tg_prince1[i]['nazwa'] + " do wykupienia!");
            }
            if(parseInt(tg_prince1[i]['ilosc']) == 0 && parseInt(tg_prince1[i]['ryn-cena']) < parseInt(tg_prince1[i]['sprzedarz']))
            {
                alert(tg_prince1[i]['nazwa'] + " cena mniejsza niz w magazynie!");
            }
        }

    }
    else
    {
        tg_step = 0;
    }

    if(tg_step != 0)
    {
        tg_step++;
        setTimeout(function() { f_tar_price(); }, Math.floor((Math.random() * 1500) + 800));
    }
}

$("#tagowisko_check").click(function()
                        {
                            tg_step = 1;
                             f_tar_price();
                         });