Steam Queue Auto Discover

Automatic queue discoverer for 3 Steam Sale cards getting

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @author              Deniss Dubinin
// @name                Steam Queue Auto Discover
// @description         Automatic queue discoverer for 3 Steam Sale cards getting
// @version             1.0.0
// @namespace           https://raw.githubusercontent.com/denissdubinin/Steam-Queue-Auto-Discover
// @supportURL          https://github.com/denissdubinin/Steam-Queue-Auto-Discover/issues
// @icon                https://store.steampowered.com/favicon.ico
// @match               https://store.steampowered.com/explore
// ==/UserScript==

(function(window) {
    'use strict';

    const SESSION_ID = g_sessionID;
    const GENERATE_QUEUE_URL = 'https://store.steampowered.com/explore/generatenewdiscoveryqueue';
    const QUEUE_ITEM_URL = 'https://store.steampowered.com/app/';
    const NEXT_QUEUE_URL = 'https://store.steampowered.com/explore/next/0/';

    let queueItems = [],
        mainQueueIterator = 0,
        error = false,
        popup;

    class sendRequest {
        send(url, params, successCallback) {
            var urlParams;

            urlParams = Object.keys(params).map(
                function(param) {
                    return encodeURIComponent(param) + '=' + encodeURIComponent(params[param])
                }
            ).join('&');

            var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');

            xhr.open('POST', url);

            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4) {
                    switch (xhr.status) {
                        case 200:
                            error = false;

                            if (successCallback !== undefined &&
                                successCallback !== null
                            ) {
                                successCallback(xhr.response);
                            }
                            break;
                        default:
                            error = true;
                            generateNewQueue();
                            break;
                    }
                }
            }

            xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
            xhr.send(urlParams);

            return xhr;
        }
    }

    let sendRequestClass = new sendRequest();

    function generateNewQueue() {
        if (popup !== undefined) {
            popup.Dismiss();
        }

        if (mainQueueIterator < 3) {
            let popupContext = '';

            if (error) {
                popupContext = `Error happened. Discovering queue #${mainQueueIterator + 1}`;
            } else {
                popupContext = `Discovering queue #${mainQueueIterator + 1}`;
            }

            popup = ShowBlockingWaitDialog(
                'Queue autodiscover',
                popupContext
            );

            sendRequestClass.send(
                GENERATE_QUEUE_URL, {
                    sessionid: SESSION_ID,
                    queuetype: 0,
                    snr: '1_5_9__discovery-queue-0'
                },
                generateQueueCallback
            );

            mainQueueIterator++;
        } else {
            let button = '<a class="btn_green_white_innerfade btn_medium"' +
                'href="#" onClick="window.location = \'https://store.steampowered.com/\'">' +
                '<span>Reload The Page</span></a>' +
                '<style>.waiting_dialog_throbber {display: none;}</style>',
                popup = ShowBlockingWaitDialog(
                    'Queue autodiscover',
                    'Autodiscover finished.&emsp;' + button
                );
        }
    }

    function generateQueueCallback(response) {
        if (response === undefined ||
            JSON.parse(response).queue === undefined
        ) {
            return;
        }

        var i,
            length,
            callback = null,
            queueItems = JSON.parse(response).queue;

        for (i = 0, length = queueItems.length; i < length; ++i) {
            if (queueItems[i] === queueItems[length - 1]) {
                callback = function() {
                    sendRequestClass.send(
                        NEXT_QUEUE_URL, {
                            appid_to_clear_from_queue: queueItems[i],
                            sessionid: SESSION_ID,
                            snr: '1_5_9__discovery-queue-0'
                        },
                        generateNewQueue
                    );
                }
            }

            sendRequestClass.send(
                QUEUE_ITEM_URL + queueItems[i], {
                    appid_to_clear_from_queue: queueItems[i],
                    sessionid: SESSION_ID,
                },
                callback
            );

            callback = null;
        };
    }

    generateNewQueue();
})(window);