-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueue.user.js
150 lines (126 loc) · 4.98 KB
/
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
// ==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 = '<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. ' + 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);