TF2Outpost AutoBump

Bumps trade on TF2 Outpost

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name           TF2Outpost AutoBump
// @version        1.0
// @description    Bumps trade on TF2 Outpost
// @include        http://www.tf2outpost.com/trades
// @run-at         document-end
// @grant          none
// @namespace https://greasyfork.org/users/5246
// ==/UserScript==

(function() {
    var RELOAD_MINUTES = 31; // reload every 31 minutes
    var divid = "tf2oab";
    var reload_time, counter;

    function notify(notify) {
        var div = document.getElementById(divid);
        if (!div) {
            var trades = document.getElementById("trades");
            var div = document.createElement("div");
            div.id = divid;
            trades.insertBefore(div, trades.childNodes[0]);
        }
        div.innerHTML = notify;
    }
    
    /*
    Called by the JS Interval counter to reload the page after reload_time
    */
    function showstatus() {
        reload_time -= 1;
        if (reload_time <= 0)
        {
            clearInterval(counter);
            location.reload();
            return;
        }
        var min = Math.floor(reload_time/60);
        var sec = reload_time - min*60;
        notify("TF2 Outpost AutoBump: Reloading page in " +min+ " minutes and "+sec+" seconds...");
    }
    
    function color_anchor(anchor, apply) {
        anchor.parentNode.parentNode.parentNode.parentNode.style.border = apply?"1px solid red":"none";
    }
    
    function bump_trades() {
        var xpr = document.evaluate(".//li/a[@class='trade_bump']/div[@class='icon_bump']", document, null, XPathResult.ANY_TYPE, null);
        var anchor;
        while (anchor = xpr.iterateNext()) {
            anchor = anchor.parentNode;
            if (anchor.getAttribute('data-tradeid'))
                break;
        }
        if (anchor && anchor.getAttribute('data-tradeid')) {
            anchor.scrollIntoView();
            color_anchor(anchor, true);
            setTimeout(function(){
                    color_anchor(anchor, false);
                    anchor.click();
                    setTimeout(bump_trades, 500);
                }, 500);
        } else {
            reload_time = RELOAD_MINUTES*60;
            window.scrollTo(0,0);
            counter = setInterval(showstatus, 1000);
        }
    }
    
    bump_trades();
}).call(this);