Vulcun Loot Autoclicker + Streams scan

Autoscans streams for drops and enters the loot in background.

2015-12-10 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Vulcun Loot Autoclicker + Streams scan
// @namespace    http://tampermonkey.net/
// @version      2.01
// @description  Autoscans streams for drops and enters the loot in background.
// @author       Mihai Morcov
// @match        https://vulcun.com/user/lobby*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
/**
 * v2 is here!
 *
 * 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 streams and enter the contest when the countdown is at 00:00.
 * You only need one tab open.
 * Also it displays actual timers, not 'pulse' image as Vulcun does :)
 *
 * How it works:
 * The script does not open tabs anymore (from v2). Entering a contest is done in background.
 * 1. Initializes the stream list
 * 2. Sets the loot drop countdown for each stream
 * 3. Will enter the contest when a stream countdown is ready. (in background)
 * 4. Will rescan the contest for it's new loot drop countdown after 60 seconds.
 *
 * 5. Will also refresh the stream list every 10 minutes
 *
 * Good luck!
 *
 * PS: Use the Feedback forum if you have problems.
 */

'use strict';

var REFRESH_STREAMS_INTERVAL = 10 * 60 * 1000; // refresh the streams list after 10 minutes

var MSG_TWITCH_PLAYER_HIDDEN = "Twitch player is hidden by the Vulcun Loot Autoclicker script, to improve the performance.";

var firebase;
var eta=0;
var streams;
var contests = {};

function scan() {
    document.title = "Vulcun Loot Autoclicker v2 : Scanning...";
    streams = $('#vu-game-listing-ongoing .vu-channel-tab');
    var noOfStreams = streams.length;
    if(noOfStreams <= 0) {
        location.reload();
    }
    console.info(new Date() + " Begin cycling through "+noOfStreams+" streams...");

    $(CON).append(
        '<div class="panel panel-default" style="border: 1px solid; color: #333">'+
        '<div class="panel-heading">'+
        '<span >Vulcun Loot Autoclicker v2 - No more multiple tabs. This will do all the work.</span>'+
        '<span class="badge" style="float:right; background-color: #124585; border: 1px solid; ">Paypal: [email protected]</span>'+
        '<span class="badge" style="float:right; background-color: white; color: #124585; border: 1px solid;">◔ ◡ ◔</span>'+
        '<span class="badge" style="float:right; background-color: white; color: #124585; border: 1px solid;">Getting items ?</span>'+
        '</div>'+
        '<div class="panel-body">'+
        '<ul class="list-group" id="loot-streams"><li style="border-bottom: 0px; margin-bottom: 5px; color: black;" class="list-group-item">Streams list, with timers! how cool is that :) </li></ul>'+
        '</div></div>');

    for (var i = 0; i < noOfStreams; i++) {
        setTimeout(function (i) {
            //console.log('i='+i);
            var stream = streams[i];
            var uniqueId = $(stream).attr('data-league');
            var channelName = $("div[data-league='" + uniqueId + "'] .indexVideoPanelTitle").text();
            firebase = new Firebase("https://lootdrop.firebaseio.com/lootdrop_v2/");
            firebase.child('eta/' + uniqueId).once('value', function (snap) {
                eta = snap.val();
                if(eta != null && eta*1000 > new Date().getTime()) {
                    //   console.log(uniqueId + ", " +eta);
                    contests[uniqueId + ''] = eta;
                    console.log('uid=' + uniqueId + ', eta=' + eta);
                    var remaining = eta * 1000 - new Date().getTime() + 15000;
                    setTimeout(enterContest, remaining, uniqueId);
                } else {
                    log('Received eta value for ' + uniqueId + ' was null or negative. Skipping...');
                }
            });

            addStreamRow(i+1, uniqueId, channelName);
        }, i*100, i);
    }

    setInterval(function() {
        for (var key in contests) {
            //console.log("key="+key);
            if(key != undefined) {
                var remaining  = contests[key]*1000 - new Date().getTime();
                if(remaining >= 0) {
                    updateStreamRow(key, remaining);
                }
            }
        }
    }, 1000);

    setTimeout(function() {
        console.debug('Checking if streams are stuck in Starting...')
        var ok=false;
        for (var key in contests) {
            //console.log("key="+key);
            if (key != undefined) {
                ok = true;
            }
        }
        if(!ok) {
            console.debug("OK=false, refreshing.");
            location.reload();
        } else {
            console.debug("Streams are fine. Continue...");
        }
    }, 10000);
}

function addStreamRow(index, uniqueId, channelName) {
    $('#loot-streams').append('<li style="border-bottom: 0px; margin-bottom: 10px;" class="list-group-item"><span style="margin-right: 10px; font-size: small;" class="label label-default" id="loot'+uniqueId+'">Starting...</span>' + index + '. ' + channelName+'</li>');
}

function updateStreamRow(key, remaining) {
    var timer = $('#loot' + key);
    var timerColor = '';
    if(remaining < 120000) {
        timerColor = 'red';
    } else if (remaining < 480000) {
        timerColor = '#e5b933';
    } else {
        timerColor = '#92b449';
    }

    timer.css('background-color', timerColor);
    timer.html("Loot drop in: " + convertTime(remaining));
}

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><br/>');
}

function log(message) {
    console.log(new Date() + " : " + message);
}

function enterContest(id) {

    $.ajax({
        type: "POST",
        url: "https://vulcun.com/api/enterlootdrop",
        data: {'league_id': id},
        success: function (resp) {
        }
    });

    log(" ADDED Contest Entry for " + id + ". Check inventory in few minutes to see if you win!");
    $('#loot' + id).html("Entry submitted! Rescanning the timer...");

    setTimeout(function(uniqueId) {
        log('Rescan ' + uniqueId);
        var channelName = $("div[data-league='" + uniqueId + "'] .indexVideoPanelTitle").text();
        firebase = new Firebase("https://lootdrop.firebaseio.com/lootdrop_v2/");
        firebase.child('eta/' + uniqueId).once('value', function (snap) {
            eta = snap.val();
            contests[uniqueId + ''] = eta;

            var remaining = eta * 1000 - new Date().getTime() + 2000;
if(remaining >= 0) {
            console.log('A new contest entry will be added for '+ uniqueId + ' in eta=' + remaining);
            setTimeout(enterContest, remaining, uniqueId);
 } else
            {
                console.log(uniqueId + " is offline");
                var timer = $('#loot' + uniqueId);
                timer.html("OFFLINE");
            }
        });
    }, 60000, id);
}

setTimeout(function() {
    if(location.href == 'https://vulcun.com/user/lobby') {
        location.assign('https://vulcun.com/user/lobby#page-live');
    }

    if(location.href != 'https://vulcun.com/user/lobby#page-live') {
        return;
    }

    setTimeout(function() {
        location.reload();
    }, REFRESH_STREAMS_INTERVAL);

    hidePlayer();

    scan();
}, 2000);

function convertTime(time) {
    var millis= time % 1000;
    time = parseInt(time/1000);
    var seconds = time % 60;
    time = parseInt(time/60);
    var minutes = time % 60;
    time = parseInt(time/60);
    var hours = time % 24;

    var sec, min, hrs;
    if (seconds < 10)  sec = "0" + seconds;
    else            sec = "" + seconds;
    if (minutes < 10)  min = "0" + minutes;
    else            min = "" + minutes;
    if (hours < 10)    hrs = "0" + hours;
    else            hrs = "" + hours;

    if (hours == 0)  return min + ":" + sec;
    else    return hrs + ":" + min + ":" + sec;
}