Vulcun Loot Autoclicker + Streams scan

Autoscans streams for drops and enters the loot. Please set your browser to allow Vulcun popup when it asks you.

Fra 02.12.2015. Se den seneste versjonen.

// ==UserScript==
// @name         Vulcun Loot Autoclicker + Streams scan
// @namespace    http://tampermonkey.net/
// @version      1.16
// @description  Autoscans streams for drops and enters the loot. Please set your browser to allow Vulcun popup when it asks you.
// @author       Mihai Morcov
// @match        https://vulcun.com/user/lobby*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
/**
 * Hello dear Vulcunians,
 * The waiting is finally over. A very smart autolooter is here and ready to grow.
 * If this script helps you and you get rich please consider donating me for a coffee.
 * Helps with the coding sessions. (Paypal: [email protected])
 *
 * What you should do:
 * Open https://vulcun.com/user/lobby#page-live in a new tab
 * The script will scan for red drops
 * First time a 'red' drop is found, it will try to open it in a new tab
 * (YOU NEED TO CLICK ON ALLOW POPUPS FROM VULCUN IN YOUR BROWSER, only first time)
 *
 *
 * How it works:
 * 1. Scans the stream list every few minutes.
 * 2. If a 'red' drop is found opens it in a new tab
 * 3. It will click the Enter loot button
 * 4. It will close the loot tab after few minutes
 * 5. The initial tab will continue to scan for drops every minute,
 * and will also refresh the stream list every 10 minutes
 *
 * Good luck!
 *
 * PS: Use the Feedback forum if you have problems.
 */

/** Default time steps and delays:
 do not change these!
 var HIDE_TWITCH_PLAYER = true;
 var STREAM_SCAN_STEP = 10 * 1000;
 var STREAM_LOADING_TIME = 5 * 1000;
 var REFRESH_STREAMS_INTERVAL = 10 * 60 * 1000;
 var CLOSE_TAB_TIME = 2 * 60 * 1000;
 */

'use strict';
var GREEN = '/img/lootdrop/long_pulse.gif';
var YELLOW = '/img/lootdrop/med_pulse.gif';
var RED = '/img/lootdrop/short_pulse.gif';
var NONE = '';

// Options, play with these, or don't:
// *instructions-unclear meme here*
var HIDE_TWITCH_PLAYER = true;
var STREAM_SCAN_STEP = 10 * 1000; // scan next stream after 10 seconds
var STREAM_LOADING_TIME = 5 * 1000; // wait 5 seconds before checking the stream status
var REFRESH_STREAMS_INTERVAL = 10 * 60 * 1000; // refresh the streams list after 10 minutes
var CLOSE_TAB_TIME = 2 * 60 * 1000; // keep a loot tab opened for 2 minutes. !Do not set less than 2 minutes.

var MSG_TWITCH_PLAYER_HIDDEN = "Twitch player is hidden by the Vulcun Loot Autoclicker script, to improve the performance.";
var MSG_SCANNER_TAB = "This is a <b>SCANNER</b> tab. Should only have 1 at a time open.";
var MSG_LOOT_TAB = "This is a <b>LOOT</b> tab. Will autoclick then close itself after few minutes.";
var MSG_LOOT_FAILED_TAB = "Loot drop failed. The stream is offline. Closing this tab in 15 seconds...";


function setCookie(key, value) {
    var expires = new Date();
    //expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
    expires.setTime(expires.getTime() + (STREAM_SCAN_STEP * 2));
    console.debug('Set cookie(' + key + ',' + value + ')');
    document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}

function getCookie(key) {
    var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
    var result = keyValue ? keyValue[2] : null;
    console.debug('Get cookie(' + key + ')=' + result);
    return result;
}

function scan() {

    var streams = $('#vu-game-listing-ongoing .vu-channel-tab');
    var noOfStreams = streams.length;
    console.info(new Date() + " Begin cycling through "+noOfStreams+" streams...");
    for (var i = 0; i < noOfStreams; i++) {
        var stream = streams[i];
        setTimeout(check, STREAM_SCAN_STEP * (i + 1), stream);
    }

    return noOfStreams;
}
var CONSOLE_ID = "autolooter-console";
var CON = '#' + CONSOLE_ID;

function hidePlayer() {
    var playerDiv = $('#channel-player-container');
    playerDiv.attr('class' , '');
    playerDiv.attr('style' , 'color: red;');
    playerDiv.html("<div id='"+CONSOLE_ID+"' </div>");
    var con = $(CON);
    con.append('<span style="color: red"><b>'+MSG_TWITCH_PLAYER_HIDDEN+'</b></span>');
}

function check(stream) {
    $(stream).click();
    var idd = $(stream).attr('data-league');

    if(HIDE_TWITCH_PLAYER == true) {
        hidePlayer();
        $(CON).append('<br/><span style="color: blue;">'+MSG_SCANNER_TAB+'</span>');
    }

    setTimeout(function(uniqueId) {

        var channelName = $("div[data-league='" + uniqueId + "'] .indexVideoPanelTitle").text();
        var eta = $("#lootdrop-eta").attr('src');
        var lootChestStyle = $("#lootdrop-eta").css('display');
        if(lootChestStyle == 'none') {
            eta = NONE;
        }
        var color = '';
        if(eta == RED)    color = 'RED   ';
        if(eta == YELLOW) color = 'YELLOW';
        if(eta == GREEN)  color = 'GREEN ';
        if(eta == NONE)   color = 'NONE  ';

        console.info(uniqueId + " - " + color + " - " + channelName);
        if(eta == RED) {
            console.log("Red detected on " + channelName);
            setCookie('redId', uniqueId);
            var win = window.open('https://vulcun.com/user/lobby#page-live', '_blank');
        } else {
            if(color == '') {
                // Vulcun bug, they display the timer instead :D We got this.
                var timer = $("#lootdrop-eta").text().substring(12);
                console.log("ETA image bugged. Use timer instead: " + timer);
                if(timer != '') {
                    var minutes = timer.split(':')[0];
                    if (minutes <= 1) {
                        console.log("Timer under 2 minutes detected on " + channelName);
                        setCookie('redId', uniqueId);
                        var win = window.open('https://vulcun.com/user/lobby#page-live', '_blank');
                    }
                } else {
                    setTimeout(refresh, 5000);
                }
            }
        }
    }, STREAM_LOADING_TIME, idd);
}

function enterContest() {
    $('#enter-lootdrop').each(function() {

        var parentDiv = $(this).parent();

        console.log(parentDiv);
        var parentCss = parentDiv.css('display');
        console.log(parentCss);
        var closeTimeout = 120000;
        if(parentCss == 'block') {
            this.click();
            console.log("Button clicked");
            //console.log("Loot dialog is open... Will close it in "+closeTimeout / 1000 +" seconds");
            //setTimeout(closeModal, closeTimeout);

            //console.log('Stop enterLoot scanning.');
            // clearInterval(enterLoot);
        }

    });
}

function closeModal() {
    $('.close').each(function() {
        this.click();
        console.log("Modal closed");
    });
}

function refresh() {
    var redId = getCookie('redId');

    if(redId == null) {
        location.reload();
    } else {
        console.debug('Postponed refresh. Id was: ' + redId);
        setTimeout(refresh, STREAM_SCAN_STEP * 2 + 1000);
    }
}

function closeTab() {
    window.top.close();
}

var enterLoot;

//$("div[data-league='1306']").click();

setTimeout(function() {
    var redId = getCookie('redId');

    if(HIDE_TWITCH_PLAYER == true) {
        hidePlayer();
    }

    if (redId == null) {
        setTimeout(refresh, REFRESH_STREAMS_INTERVAL);

        var noOfStreams = scan();
        if(noOfStreams > 0) {
            $(CON).append('<br/><span style="color: blue;">' + MSG_SCANNER_TAB + '</span>');
            document.title = "Scanning...";
            setInterval(scan, noOfStreams * STREAM_SCAN_STEP + STREAM_LOADING_TIME + 1000);
        } else {
            setTimeout(refresh, 60000);
        }
    } else {
        var channelName = $("div[data-league='" + redId + "'] .indexVideoPanelTitle").text();
        console.log('Not scanning streams. Prepare for drop on ' + channelName);
        $("div[data-league='"+redId+"']").click();

        enterLoot = setInterval(enterContest, 10000);
        if(channelName != '') {
            setTimeout(closeTab, CLOSE_TAB_TIME + 15000);
            $(CON).append('</br><span style="color: green;">'+MSG_LOOT_TAB+'</span>');
            document.title = "Looting '"+ channelName + "'";
        } else {
            setTimeout(closeTab, 15000);
            $(CON).append('</br><span style="color: maroon;">'+MSG_LOOT_FAILED_TAB+'</span>');
            document.title = "Loot drop failed.";
        }
    }
}, 2000);