-
Notifications
You must be signed in to change notification settings - Fork 11
/
auto_steam_queue.user.js
202 lines (164 loc) · 7.77 KB
/
auto_steam_queue.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// ==UserScript==
// @name Auto Steam Discovery Queue
// @namespace https://steamcommunity.com/id/zetx/
// @description Go to next game queued as soon as page is done loading.
// @include http*://store.steampowered.com/*app/*
// @include http*://store.steampowered.com/*explore*
// @include http*://store.steampowered.com/*agecheck/app/*
// @version 4.05
// @run-at document-end
// @grant none
// ==/UserScript==
// See README.md for shout-outs <3
function auto_steam_queue() {
var comeBackTomorrow = 'Come back tomorrow to earn more cards by browsing your Discovery Queue!';
var notInRegion = 'This item is currently unavailable in your region';
//var path = window.location.pathname.split('/')[1];
var path = window.location.pathname.match(/\/([\w]+?)(?:\/|$)/).pop();
// Create a 'control' UI for updates and running arbitrary queues
var createUI = function() {
var autoQueueContainerDiv = document.createElement('div');
var autoQueueStatusDiv = document.createElement('div');
var autoQueueControlsDiv = document.createElement('div');
autoQueueContainerDiv.setAttribute('id', 'auto_queue');
autoQueueContainerDiv.setAttribute('class', 'discovery_queue_customize_ctn');
autoQueueContainerDiv.setAttribute('style', 'margin-top: 12px; margin-bottom: 12px !important;');
autoQueueStatusDiv.setAttribute('id', 'auto_queue_status');
autoQueueStatusDiv.setAttribute('style', 'display: inline');
autoQueueControlsDiv.setAttribute('id', 'auto_queue_controls');
autoQueueControlsDiv.setAttribute('style', 'float: right');
autoQueueContainerDiv.appendChild(autoQueueStatusDiv);
autoQueueContainerDiv.appendChild(autoQueueControlsDiv);
document.getElementsByClassName('discovery_queue_apps')[0].getElementsByTagName('h2')[0].insertAdjacentHTML('afterend', autoQueueContainerDiv.outerHTML);
};
// Add the controls for running arbitrary queues
var populateControls = function() {
var controlsContainer = document.getElementById('auto_queue_controls');
var form = document.createElement('form');
var input = document.createElement('input');
var span = document.createElement('span');
var button = document.createElement('button');
form.setAttribute('id', 'auto_queue_form');
form.setAttribute('style', 'display: inline');
input.setAttribute('type', 'number');
input.setAttribute('min', '1');
input.setAttribute('step', '1');
input.setAttribute('id', 'queue_num');
input.setAttribute('placeholder', '# of queues to run');
span.textContent = 'Run';
button.setAttribute('type', 'submit');
button.setAttribute('class', 'btnv6_blue_hoverfade btn_tiny');
button.appendChild(span);
form.appendChild(input);
form.appendChild(button);
controlsContainer.innerHTML = form.outerHTML;
document.getElementById('auto_queue_form').addEventListener('submit', completeNumQueues, false);
};
// On submit, do numQueues worth of queues
var completeNumQueues = function(event) {
event.preventDefault();
var numQueues = document.getElementById('queue_num').value;
generateAndCompleteQueue(0, numQueues);
};
// Sets status updates for the control UI
var setStatus = function(newStatus) {
if (document.getElementById('auto_queue_status') === null) {
return;
}
document.getElementById('auto_queue_status').textContent = 'Queue Status: ' + newStatus;
};
// Tells Steam to generate a new queue then runs through the appids to clear 'em off the queue
var generateAndCompleteQueue = function(currentQueueNum, maxQueueNum) {
setStatus('Queue #' + (++currentQueueNum));
$J.post('https://store.steampowered.com/explore/generatenewdiscoveryqueue', {
sessionid: g_sessionID,
queuetype: 0
}).done(function(data) {
var appsCleared = [];
data.queue.forEach(function(appId) {
appsCleared.push(
$J.post('https://store.steampowered.com/app/60', {
appid_to_clear_from_queue: appId,
sessionid: g_sessionID
})
);
});
Promise.all(appsCleared).then(function() {
if (currentQueueNum < maxQueueNum) {
generateAndCompleteQueue(currentQueueNum, maxQueueNum);
} else {
setStatus('Finished ' + currentQueueNum + ' queue(s).');
UpdateNotificationCounts();
}
}, function(reason) {
console.log('Bad: ' + reason);
});
});
};
// Actions for /explore*
var explorePageActions = function() {
if (document.getElementsByClassName('discovery_queue_apps').length) {
createUI();
populateControls();
}
if ($J('.discovery_queue_winter_sale_cards_header').length) {
if (!$J('.discovery_queue_winter_sale_cards_header:contains(' + comeBackTomorrow + ')').length) {
setStatus('Starting queues...');
generateAndCompleteQueue(0, 3);
}
}
setStatus('Waiting...');
};
// Auto-submitted old-style age checks
var ageCheckPageActions = function() {
// https://store.steampowered.com/agecheck/app/*
$("span:contains('Enter')");
$J('#ageYear').val(1915).trigger('change');
DoAgeGateSubmit();
};
// Actions for /app* including new-style age checks
var appPageActions = function() {
if (window.location.pathname.split('/')[3] === 'agecheck') {
document.getElementsByClassName('btn_grey_white_innerfade btn_medium')[0].click();
} else if ($J('.error:contains(' + notInRegion + ')').length) {
var unavailable_app = window.location.pathname.split('/')[2];
$J.post('/app/7', {
sessionid: g_sessionID,
appid_to_clear_from_queue: unavailable_app
}).done(function(data) {
window.location = 'https://store.steampowered.com/explore/next';
$J('.error').html($J('.error').html() + '<br />(Removing from queue)');
}).fail(function() {
$J('.error').html($J('.error').html() + '<br />(Could not remove from queue. Reload or try <a href="https://www.reddit.com/r/Steam/comments/3r2k4y/how_do_i_complete_discovery_queue_if_every_queue/cwkrrzf">removing manually.</a>)');
});
}
/*
else if ( $J('#next_in_queue_form').length ) {
$J('.queue_sub_text').text('Loading next in queue');
$J('#next_in_queue_form').submit();
}
*/
};
if (path === 'explore') {
explorePageActions();
} else if (path === 'app') {
appPageActions();
} else if (path === 'agecheck') {
ageCheckPageActions();
}
}
addJS_Node(null, null, auto_steam_queue);
//-- This is a standard-ish utility function:
function addJS_Node(text, s_URL, funcToRun, runOnLoad) {
var D = document;
var scriptNode = D.createElement ('script');
if (runOnLoad) {
scriptNode.addEventListener ("load", runOnLoad, false);
}
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}