diff --git a/README.md b/README.md index 76c6e02..a2b23bd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ -# Steam-Queue-Auto-Discover -Automatic queue discoverer for Steam Sales +# Steam Queue Auto Discover +This small script saves you some minutes every day if you are collecting Steam Sale cards. + +![Screenshot of the "Discovery queues" section](screenshots/queue.png) + +## How to? +There are two ways to use this script: + +### Directly from browser console: +1. Open [Steam Queue Explore Page](https://store.steampowered.com/explore/) +2. Do `right click` on opened page and open web-inspector + + +3. Open `Console` +4. Insert [script](https://raw.githubusercontent.com/denissdubinin/Steam-Queue-Auto-Discover/master/queue.js) in console and press `Enter` + + +### Using browser extension: +*Using this way script will be triggered each time you will open [Steam Queue Explore](https://store.steampowered.com/explore) page.* +1. Install browser extension: + [Chrome](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo), + [Firefox](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/), + [Opera](https://addons.opera.com/en/extensions/details/tampermonkey-beta/), + [Safari](https://tampermonkey.net/?browser=safari) +2. Open [Script page](https://raw.githubusercontent.com/denissdubinin/Steam-Queue-Auto-Discover/master/queue.user.js) +4. Click `Install` +3. Open [Steam Queue Explore Page](https://store.steampowered.com/explore) + +## Is there any risks? +No, this script emulates web requests, Steam will see these requests as real queue visits. + +## Note +Please note, that you can get only 3 cards per day and only during Steam Sale. + +## Issue reporting +Faced with any issue? [Report the issue](https://github.com/denissdubinin/Steam-Queue-Auto-Discover/issues) or [fix it by yourself](https://github.com/denissdubinin/Steam-Queue-Auto-Discover/pulls). You are welcome 😊 diff --git a/queue.user.js b/queue.user.js new file mode 100644 index 0000000..b09a629 --- /dev/null +++ b/queue.user.js @@ -0,0 +1,150 @@ +// ==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 +// @updateURL https://raw.githubusercontent.com/denissdubinin/Steam-Queue-Auto-Discover/master/queue.user.js +// @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 = '' + + 'Reload The Page' + + '', + popup = ShowBlockingWaitDialog( + 'Queue autodiscover', + 'Autodiscover finished. ' + 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); diff --git a/screenshots/inspector.png b/screenshots/inspector.png new file mode 100644 index 0000000..ca1fdad Binary files /dev/null and b/screenshots/inspector.png differ diff --git a/screenshots/queue.png b/screenshots/queue.png new file mode 100644 index 0000000..7c728fb Binary files /dev/null and b/screenshots/queue.png differ