-
Notifications
You must be signed in to change notification settings - Fork 2
/
ASF-STM.user.js
2010 lines (1911 loc) · 99.3 KB
/
ASF-STM.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name ASF STM
// @namespace https://greasyfork.org/users/2205
// @description ASF bot list trade matcher
// @description:vi Trình khớp lệnh giao dịch danh sách bot ASF
// @license Apache-2.0
// @author Rudokhvist
// @match *://steamcommunity.com/id/*/badges
// @match *://steamcommunity.com/id/*/badges/
// @match *://steamcommunity.com/profiles/*/badges
// @match *://steamcommunity.com/profiles/*/badges/
// @match *://steamcommunity.com/tradeoffer/new/*source=asfstm*
// @version 4.2
// @connect asf.justarchi.net
// @grant GM.xmlHttpRequest
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @downloadURL https://update.greasyfork.org/scripts/404754/ASF%20STM.user.js
// @updateURL https://update.greasyfork.org/scripts/404754/ASF%20STM.meta.js
// ==/UserScript==
(function () {
"use strict";
let myProfileLink = "";
let errors = 0;
let bots = null;
let myBadges = [];
let botBadges = [];
let maxPages;
let stop = false;
let botCacheTime = 5 * 60000;
let globalSettings = null;
let blacklist = [];
let defaultSettings = {
anyBots: true,
fairBots: true,
sortByName: true,
sortBotsBy: ["MatchEverythingFirst", "TotalGamesCountDesc", "TotalItemsCountDesc", "TotalInventoryCountAsc", "None"],
botMinItems: 0,
botMaxItems: 0,
weblimiter: 300,
errorLimiter: 30000,
debug: false,
maxErrors: 3,
filterBackgroundColor: "rgba(23,26,33,0.8)",
// for trade offer
tradeMessage: "ASF STM Matcher",
autoSend: false,
doAfterTrade: "NOTHING",
order: "AS_IS",
};
let cardNames = new Set();
let tradeParams = {
matches: {},
filter: [],
};
//styles
const css = `
#asf_stm_filters_body {
max-height: calc(100vh - 95px);
overflow-y: auto;
}
.asf_stm_tabs{
width: 600px;
display: block;
margin: 40px auto;
position: relative;
}
.asf_stm_tabs .asf_stm_tab{
float: left;
display: block;
}
.asf_stm_tabs .asf_stm_tab>input[type="radio"] {
position: absolute;
top: -9999px;
left: -9999px;
}
.asf_stm_tabs .asf_stm_tab>label {
display: block;
padding: 6px 21px;
cursor: pointer;
position: relative;
color: #FFF;
background: #4A83FD;
}
.asf_stm_tabs .asf_stm_content {
display: none;
overflow: hidden;
width: 630px;
height: 380px;
padding: 5px;
position: absolute;
top: 27px;
left: 0;
background: #303030;
color: #DFDFDF;
}
.asf_stm_tabs>.asf_stm_tab>[id^="asf_stm_tab"]:checked + label {
top: 0;
background: #303030;
color: #F5F5F5;
}
.asf_stm_tabs>.asf_stm_tab>[id^="asf_stm_tab"]:checked ~ [id^="asf_stm_tab-content"] {
display: block;
}
textarea {
resize: none;
}
`;
function debugTime(name) {
if (globalSettings.debug) {
console.time(name);
}
}
function debugTimeEnd(name) {
if (globalSettings.debug) {
console.timeEnd(name);
}
}
function debugPrint(msg) {
if (globalSettings.debug) {
console.log(new Date().toLocaleTimeString("en-GB", { hour12: false, hour: "2-digit", minute: "2-digit", second: "2-digit", fractionalSecondDigits: 3 }) + " : " + msg);
}
}
function deepClone(object) {
return JSON.parse(JSON.stringify(object));
}
function getPartner(str) {
if (typeof BigInt !== "undefined") {
return (BigInt(str) % BigInt(4294967296)).toString(); // eslint-disable-line
} else {
let result = 0;
for (let i = 0; i < str.length; i++) {
result = (result * 10 + Number(str[i])) % 4294967296;
}
return result.toString();
}
}
function arrayToText(array) {
return array.join(",\n");
}
function textToArray(text) {
let res = [];
text.split(",").forEach(function (elem) {
if (/^\d+$/.test(elem.trim())) {
res.push(elem.trim());
}
});
return res;
}
function hexToRgba(hex) {
return "rgba(" + [Number("0x" + hex.substring(1, 3)), Number("0x" + hex.substring(3, 5)), Number("0x" + hex.substring(5, 7))].join(",") + ",1)";
}
function rgbaToHex(rgba) {
let re = /rgba\(([.\d]+),([.\d]+),([.\d]+),([.\d]+)\)/g;
let result = re.exec(rgba);
if (result === null || result.length !== 5) {
debugPrint("failed to parse color!");
return ["#171a21", 0.8];
}
return ["#" + Number(result[1]).toString(16) + Number(result[2]).toString(16) + Number(result[3]).toString(16), Number(result[4])];
}
function mixAlpha(rgba, alpha) {
let re = /(rgba\([.\d]+,[.\d]+,[.\d]+,)([.\d]+)\)/g;
let result = re.exec(rgba);
if (result) {
return result[1] + alpha + ")";
}
debugPrint("failed to mix alpha!");
return rgba;
}
function ShowConfigDialog() {
let filterBG = rgbaToHex(globalSettings.filterBackgroundColor);
let configDialogTemplate = `
<div style="height:420px; margin-top:-20px; font-size:12px;margin-left: -20px;width: 620px;" >
<ul style="margin: 0;padding: 0;" class="asf_stm_tabs">
<li class="asf_stm_tab">
<input name="asf_stm_tabs" checked="checked"
id="asf_stm_tab1" type="radio"><label
for="asf_stm_tab1">Matcher</label>
<div id="asf_stm_tab-content1" class="asf_stm_content">
<fieldset style="padding-top: 0px;"><legend>BOTS TO MATCH</legend>
<div style="margin-bottom: 6px;"> Match with "Any"
bots: <input style="background-color: #171d25; color: white;"
id="anyBots" ${globalSettings.anyBots ? 'checked="checked"' : ""} type="checkbox"> Match
with "Fair"
bots: <input style="background-color: #171d25; color: white;"
id="fairBots" ${globalSettings.fairBots ? 'checked="checked"' : ""} type="checkbox"><br>
</div>
<div style="margin-bottom: 6px;"> Minimum
items: <input min=0 style="background-color: #171d25; color: white;"
id="botMinItems" value=${globalSettings.botMinItems} type="number"> Maximum
items: <input min=0 style="background-color: #171d25; color: white;"
id="botMaxItems" value=${globalSettings.botMaxItems} type="number"><a class="tooltip hover_tooltip" data-tooltip-text="Don't match with bots
that has less or more than required limit of items in steam inventory. 0 means no limit on number of items">
<img src="https://store.cloudflare.steamstatic.com/public/shared/images/ico/icon_questionmark.png"></a>
<br>
</div>
<div style="margin-bottom: 6px;">
<span style="width: 80px; display: inline-block;">Sort bots by:</span>
<select style="background-color: #171d25; color: white;"
id="sortBotsBy0">
<option value="MatchEverythingFirst" ${globalSettings.sortBotsBy[0] === "MatchEverythingFirst" ? 'selected="selected"' : ""}>"Any"
bots first</option>
<option value="MatchEverythingLast" ${globalSettings.sortBotsBy[0] === "MatchEverythingLast" ? 'selected="selected"' : ""}>"Any" bots last</option>
<option value="TotalGamesCountDesc" ${globalSettings.sortBotsBy[0] === "TotalGamesCountDesc" ? 'selected="selected"' : ""}>Total games count, descending</option>
<option value="TotalGamesCountAsc" ${globalSettings.sortBotsBy[0] === "TotalGamesCountAsc" ? 'selected="selected"' : ""}>Total games count, ascending</option>
<option value="TotalItemsCountDesc" ${globalSettings.sortBotsBy[0] === "TotalItemsCountDesc" ? 'selected="selected"' : ""}>Total matchable items count,
descending</option>
<option value="TotalItemsCountAsc" ${globalSettings.sortBotsBy[0] === "TotalItemsCountAsc" ? 'selected="selected"' : ""}>Total matchable items count,
ascending</option>
<option value="TotalInventoryCountDesc" ${globalSettings.sortBotsBy[0] === "TotalInventoryCountDesc" ? 'selected="selected"' : ""}>Total inventory count, descending</option>
<option value="TotalInventoryCountAsc" ${globalSettings.sortBotsBy[0] === "TotalInventoryCountAsc" ? 'selected="selected"' : ""}>Total inventory count, ascending</option>
<option value="None" ${globalSettings.sortBotsBy[0] === "None" ? 'selected="selected"' : ""}>None</option>
</select>
</div>
<div style="margin-bottom: 6px;"><span
style="width: 80px; display: inline-block;"> …then by:</span>
<select style="background-color: #171d25; color: white;" id="sortBotsBy1">
<option value="MatchEverythingFirst" ${globalSettings.sortBotsBy[1] === "MatchEverythingFirst" ? 'selected="selected"' : ""}>"Any"
bots first</option>
<option value="MatchEverythingLast" ${globalSettings.sortBotsBy[1] === "MatchEverythingLast" ? 'selected="selected"' : ""}>"Any" bots last</option>
<option value="TotalGamesCountDesc" ${globalSettings.sortBotsBy[1] === "TotalGamesCountDesc" ? 'selected="selected"' : ""}>Total games count, descending</option>
<option value="TotalGamesCountAsc" ${globalSettings.sortBotsBy[1] === "TotalGamesCountAsc" ? 'selected="selected"' : ""}>Total games count, ascending</option>
<option value="TotalItemsCountDesc" ${globalSettings.sortBotsBy[1] === "TotalItemsCountDesc" ? 'selected="selected"' : ""}>Total matchable items count,
descending</option>
<option value="TotalItemsCountAsc" ${globalSettings.sortBotsBy[1] === "TotalItemsCountAsc" ? 'selected="selected"' : ""}>Total matchable items count,
ascending</option>
<option value="TotalInventoryCountDesc" ${globalSettings.sortBotsBy[1] === "TotalInventoryCountDesc" ? 'selected="selected"' : ""}>Total inventory count, descending</option>
<option value="TotalInventoryCountAsc" ${globalSettings.sortBotsBy[1] === "TotalInventoryCountAsc" ? 'selected="selected"' : ""}>Total inventory count, ascending</option>
<option value="None" ${globalSettings.sortBotsBy[1] === "None" ? 'selected="selected"' : ""}>None</option>
</select>
</div>
<div style="margin-bottom: 6px;"><span
style="width: 80px; display: inline-block;">…then by:</span>
<select style="background-color: #171d25; color: white;"
id="sortBotsBy2">
<option value="MatchEverythingFirst" ${globalSettings.sortBotsBy[2] === "MatchEverythingFirst" ? 'selected="selected"' : ""}>"Any"
bots first</option>
<option value="MatchEverythingLast" ${globalSettings.sortBotsBy[2] === "MatchEverythingLast" ? 'selected="selected"' : ""}>"Any" bots last</option>
<option value="TotalGamesCountDesc" ${globalSettings.sortBotsBy[2] === "TotalGamesCountDesc" ? 'selected="selected"' : ""}>Total games count, descending</option>
<option value="TotalGamesCountAsc" ${globalSettings.sortBotsBy[2] === "TotalGamesCountAsc" ? 'selected="selected"' : ""}>Total games count, ascending</option>
<option value="TotalItemsCountDesc" ${globalSettings.sortBotsBy[2] === "TotalItemsCountDesc" ? 'selected="selected"' : ""}>Total matchable items count,
descending</option>
<option value="TotalItemsCountAsc" ${globalSettings.sortBotsBy[2] === "TotalItemsCountAsc" ? 'selected="selected"' : ""}>Total matchable items count,
ascending</option>
<option value="TotalInventoryCountDesc" ${globalSettings.sortBotsBy[2] === "TotalInventoryCountDesc" ? 'selected="selected"' : ""}>Total inventory count, descending</option>
<option value="TotalInventoryCountAsc" ${globalSettings.sortBotsBy[2] === "TotalInventoryCountAsc" ? 'selected="selected"' : ""}>Total inventory count, ascending</option>
<option value="None" ${globalSettings.sortBotsBy[2] === "None" ? 'selected="selected"' : ""}>None</option>
</select>
</div>
<div style="margin-bottom: 6px;"><span
style="width: 80px; display: inline-block;">…then by:</span>
<select style="background-color: #171d25; color: white;"
id="sortBotsBy3">
<option value="MatchEverythingFirst" ${globalSettings.sortBotsBy[3] === "MatchEverythingFirst" ? 'selected="selected"' : ""}>"Any"
bots first</option>
<option value="MatchEverythingLast" ${globalSettings.sortBotsBy[3] === "MatchEverythingLast" ? 'selected="selected"' : ""}>"Any" bots last</option>
<option value="TotalGamesCountDesc" ${globalSettings.sortBotsBy[3] === "TotalGamesCountDesc" ? 'selected="selected"' : ""}>Total games count, descending</option>
<option value="TotalGamesCountAsc" ${globalSettings.sortBotsBy[3] === "TotalGamesCountAsc" ? 'selected="selected"' : ""}>Total games count, ascending</option>
<option value="TotalItemsCountDesc" ${globalSettings.sortBotsBy[3] === "TotalItemsCountDesc" ? 'selected="selected"' : ""}>Total matchable items count,
descending</option>
<option value="TotalItemsCountAsc" ${globalSettings.sortBotsBy[3] === "TotalItemsCountAsc" ? 'selected="selected"' : ""}>Total matchable items count,
ascending</option>
<option value="TotalInventoryCountDesc" ${globalSettings.sortBotsBy[3] === "TotalInventoryCountDesc" ? 'selected="selected"' : ""}>Total inventory count, descending</option>
<option value="TotalInventoryCountAsc" ${globalSettings.sortBotsBy[3] === "TotalInventoryCountAsc" ? 'selected="selected"' : ""}>Total inventory count, ascending</option>
<option value="None" ${globalSettings.sortBotsBy[3] === "None" ? 'selected="selected"' : ""}>None</option>
</select>
</div>
</fieldset>
<fieldset style="padding-top: 0px;"><legend>INTERFACE</legend>
<div style="margin-bottom: 6px;"> Game filter pop-up
background color: <input
style="background-color: #171d25; color: white; height: 20px; padding: 2px;"
id="filterBackgroundColor" value="${filterBG[0]}" type="color"> opacity: <input
style="height: 4px;"
id="filterBackgroundAlpha" min=0 max=1
step=0.01 value=${filterBG[1]} type="range"><br>
</div>
<div style="margin-bottom: 6px;"> Sort results by game
name: <input
style="border: medium none transparent; background-color: #171d25; color: white;"
id="sortByName" ${globalSettings.sortByName ? 'checked="checked"' : ""} type="checkbox">
</div>
</fieldset>
<fieldset style="padding-top: 0px;"><legend>SETTINGS</legend>
<fieldset style="padding-top: 0px; float: right; width:200px;"><legend>DEVELOPER</legend>
<div style="margin-bottom: 6px;">Debug:
<input style="background-color: #171d25; color: white;"
id="debug" type="checkbox" ${globalSettings.debug ? 'checked="checked"' : ""} >
<a class="tooltip hover_tooltip" data-tooltip-text="Enable additional output to console">
<img src="https://store.cloudflare.steamstatic.com/public/shared/images/ico/icon_questionmark.png"></a>
</div>
</fieldset>
<div style="margin-bottom: 6px;"> Web limiter delay,
ms: <input class="price_option_input"
style="border: medium none transparent; background-color: #171d25; color: white;"
id="weblimiter" value= ${globalSettings.weblimiter} min=0 type="number"></div>
<div style="margin-bottom: 6px;"> Delay on error,
ms: <input class="price_option_input"
style="background-color: #171d25; color: white;"
id="errorLimiter" value=${globalSettings.errorLimiter} min=0 type="number"></div>
<div style="margin-bottom: 6px;"> Max errors: <input
class="price_option_input"
style="background-color: #171d25; color: white;"
id="maxErrors" value=${globalSettings.maxErrors} min=0 type="number"></div>
</div>
</fieldset>
</li>
<li class="asf_stm_tab">
<input name="asf_stm_tabs" id="asf_stm_tab2"
type="radio"><label for="asf_stm_tab2">Trade
helper</label>
<div id="asf_stm_tab-content2" class="asf_stm_content">
<br>
<fieldset><legend>TRADE OFFER MESSAGE</legend>
<textarea style="background-color: #171d25; color: white;" id="tradeMessage" name="tradeMessage" rows="4"
cols="60">${globalSettings.tradeMessage}</textarea>
<a class="tooltip hover_tooltip" data-tooltip-text="Custom text that will be included automatically with your
trade offers created through STM while using this userscript. To remove this functionality, simply delete the text.">
<img src="https://store.cloudflare.steamstatic.com/public/shared/images/ico/icon_questionmark.png"></a>
</fieldset>
<br>
<fieldset><legend>ACTION AFTER TRADE
</legend>
<label for="after-trade">After
trade...</label>
<select style="background-color: #171d25; color: white;" name="after-trade" id="doAfterTrade">
<option value="NOTHING" ${globalSettings.doAfterTrade === "NOTHING" ? 'selected="selected"' : ""}>Do
Nothing</option>
<option value="CLOSE_WINDOW" ${globalSettings.doAfterTrade === "CLOSE_WINDOW" ? 'selected="selected"' : ""}>Close window</option>
<option value="CLICK_OK" ${globalSettings.doAfterTrade === "CLICK_OK" ? 'selected="selected"' : ""}>Click OK</option>
</select>
<a class="tooltip hover_tooltip" data-tooltip-html="
<p>Determines what happens when you complete a trade offer.</p>
<ul>
<li><strong>Do nothing</strong>: Will do
nothing more than the normal behavior.</li>
<li><strong>Close window</strong>: Will close
the window after the trade offer is sent.</li>
<li><strong>Click OK</strong>: Will redirect
you to the trade offers recap page.</li>
</ul>">
<img src="https://store.cloudflare.steamstatic.com/public/shared/images/ico/icon_questionmark.png"></a>
</fieldset>
<br>
<fieldset><legend>CARDS OFFER
</legend>
<label for="cards-order">Cards
order</label>
<select style="background-color: #171d25; color: white;" class="form-control" name="cards-order"
id="order">
<option value="SORT" ${globalSettings.order === "SORT" ? 'selected="selected"' : ""}>Sorted</option>
<option value="RANDOM" ${globalSettings.order === "RANDOM" ? 'selected="selected"' : ""}>Random</option>
<option value="AS_IS" ${globalSettings.order === "AS_IS" ? 'selected="selected"' : ""}>As is</option>
</select>
<a class="tooltip hover_tooltip" data-tooltip-html="
<p>Determines which card is added to trade.</p>
<ul>
<li><strong>Sorted</strong>: Will sort cards by
their IDs before adding to trade. If you make several trade offers with
the same card and one of them is accepted, the rest will have message
"cards unavilable to trade".</li>
<li><strong>Random</strong>: Will add cards to
trade randomly. If you make several trade offers and one of them is
accepted, only some of them will be unavilable for trade.</li>
<li><strong>As is</strong>: Script doesn't
change anything in order. Results vary depending on browser, steam
servers, weather...</li>
</ul>">
<img src="https://store.cloudflare.steamstatic.com/public/shared/images/ico/icon_questionmark.png"></a>
</fieldset>
<br>
<fieldset><legend>AUTO-SEND TRADE OFFER
</legend>
<label for="auto-send"><input style="background-color: #171d25; color: white;" name="auto-send"
id="autoSend" value="1" type="checkbox" ${globalSettings.autoSend ? 'checked="checked"' : ""}>
Enable</label>
<a class="tooltip hover_tooltip" data-tooltip-text="Makes it possible for the script to automatically send
trade offers without any action on your side. This is not recommended
as you should always check your trade offers, but, well, this is a
possible thing. Please note that incomplete trade offers (missing
cards, ...) won't be sent automatically even when this parameter is set
to true.">
<img src="https://store.cloudflare.steamstatic.com/public/shared/images/ico/icon_questionmark.png"></a>
</fieldset>
</div>
</li>
<li class="asf_stm_tab">
<input name="asf_stm_tabs" id="asf_stm_tab3"
type="radio"><label for="asf_stm_tab3">Blacklist</label>
<div id="asf_stm_tab-content3" class="asf_stm_content">
<div class="title_text profile_xp_block_remaining"><h1>Comma-separated list of ignored steamIDs</h1><div><div>
<textarea style="background-color: #171d25; color: white;" id="blacklist" name="Blacklist" rows="17"
cols="63">${arrayToText(blacklist)}</textarea></div>
</li>
</ul>
</div>
`;
let templateElement = document.createElement("template");
templateElement.innerHTML = configDialogTemplate.trim();
let configDialog = templateElement.content.firstChild;
unsafeWindow.ShowConfirmDialog("ASF STM Configuration", configDialog, "Save", "Cancel", "Reset").done(function (button) {
if (button === "OK") {
globalSettings.anyBots = configDialog.querySelector("#anyBots").checked;
globalSettings.fairBots = configDialog.querySelector("#fairBots").checked;
globalSettings.sortByName = configDialog.querySelector("#sortByName").checked;
let newsortBotsBy = [];
configDialog.querySelectorAll("[id^=sortBotsBy").forEach(function (elem) {
newsortBotsBy.push(elem.selectedOptions[0].value);
});
globalSettings.sortBotsBy = newsortBotsBy;
let newbotMinItems = Number(configDialog.querySelector("#botMinItems").value);
globalSettings.botMinItems = isNaN(newbotMinItems) ? globalSettings.botMinItems : newbotMinItems;
let newbotMaxItems = Number(configDialog.querySelector("#botMaxItems").value);
globalSettings.botMaxItems = isNaN(newbotMaxItems) ? globalSettings.botMaxItems : newbotMaxItems;
let newweblimiter = Number(configDialog.querySelector("#weblimiter").value);
globalSettings.weblimiter = isNaN(newweblimiter) ? globalSettings.weblimiter : newweblimiter;
let newerrorLimiter = Number(configDialog.querySelector("#errorLimiter").value);
globalSettings.errorLimiter = isNaN(newerrorLimiter) ? globalSettings.errorLimiter : newerrorLimiter;
globalSettings.debug = configDialog.querySelector("#debug").checked;
let newmaxErrors = Number(configDialog.querySelector("#maxErrors").value);
globalSettings.maxErrors = isNaN(newmaxErrors) ? globalSettings.maxErrors : newmaxErrors;
globalSettings.filterBackgroundColor = mixAlpha(hexToRgba(configDialog.querySelector("#filterBackgroundColor").value), configDialog.querySelector("#filterBackgroundAlpha").value);
globalSettings.tradeMessage = configDialog.querySelector("#tradeMessage").value;
globalSettings.autoSend = configDialog.querySelector("#autoSend").checked;
globalSettings.doAfterTrade = configDialog.querySelector("#doAfterTrade").selectedOptions[0].value;
globalSettings.order = configDialog.querySelector("#order").selectedOptions[0].value;
blacklist = textToArray(configDialog.querySelector("#blacklist").value);
SaveConfig();
unsafeWindow.ShowConfirmDialog("CONFIRMATION", "Some changes may not work prior to page reload. Do you want to reload the page?").done(function () {
document.location.reload();
});
} else {
unsafeWindow.ShowConfirmDialog("CONFIRMATION", "Are you sure you want to restore default settings?").done(function () {
ResetConfig();
SaveConfig();
unsafeWindow.ShowConfirmDialog("CONFIRMATION", "Some changes may not work prior to page reload. Do you want to reload the page?").done(function () {
document.location.reload();
});
});
}
});
}
function ResetConfig() {
//we won't clear blacklist here!
globalSettings = deepClone(defaultSettings);
}
function SaveConfig() {
localStorage.setItem("Ryzhehvost.ASF.STM.Settings", JSON.stringify(globalSettings));
localStorage.setItem("Ryzhehvost.ASF.STM.Blacklist", JSON.stringify(blacklist));
}
function LoadConfig() {
globalSettings = JSON.parse(localStorage.getItem("Ryzhehvost.ASF.STM.Settings"));
blacklist = JSON.parse(localStorage.getItem("Ryzhehvost.ASF.STM.Blacklist"));
if (globalSettings === null) {
ResetConfig();
}
if (blacklist === null) {
blacklist = [];
}
//vaildate config
Object.keys(defaultSettings).forEach(function (key) {
if (!globalSettings.hasOwnProperty(key)) {
globalSettings[key] = defaultSettings[defaultSettings];
}
});
}
function SaveParams() {
if (tradeParams.cardNames === undefined) {
tradeParams.cardNames = Array.from(cardNames);
}
debugPrint(JSON.stringify(tradeParams.filter));
localStorage.setItem("Ryzhehvost.ASF.STM.Params", JSON.stringify(tradeParams));
}
function LoadParams() {
return JSON.parse(localStorage.getItem("Ryzhehvost.ASF.STM.Params"));
}
function enableButton() {
let buttonDiv = document.getElementById("asf_stm_button_div");
buttonDiv.setAttribute("class", "profile_small_header_additional");
buttonDiv.setAttribute("title", "Scan ASF STM");
let button = document.getElementById("asf_stm_button");
button.addEventListener("click", buttonPressedEvent, false);
}
function disableButton() {
let buttonDiv = document.getElementById("asf_stm_button_div");
buttonDiv.setAttribute("class", "profile_small_header_additional btn_disabled");
buttonDiv.setAttribute("title", "Scan is in process");
let button = document.getElementById("asf_stm_button");
button.removeEventListener("click", buttonPressedEvent, false);
}
function updateMessage(text) {
let message = document.getElementById("asf_stm_message");
message.textContent = text;
}
function hideMessage() {
let messageBox = document.getElementById("asf_stm_messagebox");
messageBox.setAttribute("style", "display: none;");
}
function hideThrobber() {
let throbber = document.getElementById("throbber");
throbber.setAttribute("style", "display: none;");
}
function updateProgress(index, total) {
const bar = document.getElementById("asf_stm_progress");
let progress = 0;
if (total > 0) {
progress = 100 * ((index + 1) / total);
}
bar.style.width = `${progress}%`;
bar.style.transitionDuration = "0.5s";
if (progress === 100) {
bar.style.transitionDuration = "0s";
}
}
function blacklistEventHandler(event) {
let steamID = event.currentTarget.id.split("_")[1];
if (blacklist.includes(steamID)) {
return;
}
unsafeWindow.ShowConfirmDialog("CONFIRMATION", `Are you sure you want to blacklist bot ${steamID} ?`).done(function () {
blacklist.push(steamID);
SaveConfig();
});
}
function filterAllEventHandler(event) {
let appIds = event.target.name.split(",");
appIds = appIds.map((id) => "astm_" + id);
for (let appId of appIds) {
let target = document.querySelector("#" + appId);
if (target && target.checked) {
target.click();
}
}
}
function populateCards(item) {
let htmlCards = "";
for (let j = 0; j < item.cards.length; j++) {
let itemIcon = item.cards[j].iconUrl;
let itemName = item.cards[j].item;
for (let k = 0; k < item.cards[j].count; k++) {
let cardTemplate = `
<div class="showcase_slot">
<img class="image-container" src="${itemIcon}/98x115">
<div class="commentthread_subscribe_hint" style="width: 98px;">${itemName}</div>
</div>
`;
htmlCards += cardTemplate;
}
}
return htmlCards;
}
function checkRow(row) {
debugPrint("checkRow");
let matches = row.getElementsByClassName("badge_row");
let visible = false;
for (let i = 0; i < matches.length; i++) {
if (matches[i].parentElement.style.display !== "none") {
visible = true;
break;
}
}
if (visible) {
row.style.display = "block";
} else {
row.style.display = "none";
}
}
function addMatchRow(index) {
debugPrint("addMatchRow " + index);
let itemsToSend = bots.Result[index].itemsToSend;
let itemsToReceive = bots.Result[index].itemsToReceive;
// sort by game name
function compareNames(a, b) {
const nameA = a.title;
const nameB = b.title;
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
}
if (globalSettings.sortByName) {
itemsToSend.sort(compareNames);
itemsToReceive.sort(compareNames);
}
let tradeUrl = "https://steamcommunity.com/tradeoffer/new/?partner=" + getPartner(bots.Result[index].SteamID) + "&token=" + bots.Result[index].TradeToken + "&source=asfstm";
debugPrint(tradeUrl);
let matches = "";
let any = "";
let appIdList = [];
if (bots.Result[index].MatchEverything) {
any = ` <sup><span class="avatar_block_status_in-game" style="font-size: 8px; cursor:help" title="This bots trades for any cards within same set"> ANY </span></sup>`;
}
for (let i = 0; i < itemsToSend.length; i++) {
let appId = itemsToSend[i].appId;
appIdList.push(appId);
let itemToReceive = itemsToReceive.find((a) => a.appId == appId);
let gameName = itemsToSend[i].title;
let display = "inline-block";
//remove placeholder
let filterWidget = document.getElementById("asf_stm_filters_body");
let placeholder = document.getElementById("asf_stm_placeholder");
if (placeholder !== null) {
placeholder.parentNode.removeChild(placeholder);
}
//add filter
let checkBox = document.getElementById("astm_" + appId);
if (checkBox === null) {
let newFilter = `<span style="margin-right: 15px; white-space: nowrap; display: inline-block;"><input type="checkbox" id="astm_${appId}" checked="" /><label for="astm_${appId}">${gameName}</label></span>`;
let spanTemplate = document.createElement("template");
spanTemplate.innerHTML = newFilter.trim();
filterWidget.appendChild(spanTemplate.content.firstChild);
tradeParams.filter.push(Number(appId));
SaveParams();
} else {
if (checkBox.checked === false) {
display = "none";
}
}
let sendResult = populateCards(itemsToSend[i]);
let receiveResult = populateCards(itemToReceive);
let tradeUrlApp = tradeUrl + "&match=" + appId;
let matchTemplate = `
<div class="asf_stm_appid_${appId}" style="display:${display}">
<div class="badge_row is_link goo_untradable_note showcase_slot">
<div class="notLoggedInText">
<div title="View badge progress for this game">
<a target="_blank" rel="noopener noreferrer" href="https://steamcommunity.com/${myProfileLink}/gamecards/${appId}/">
<img style="background-color: var(--gpStoreDarkerGrey);" height=69 alt="${gameName}" src="https://steamcdn-a.akamaihd.net/steam/apps/${appId}/capsule_184x69.jpg"
onerror="this.onerror=null;this.src='https://store.akamai.steamstatic.com/public/images/gift/steam_logo_digitalgiftcard.png'">
<div>${gameName}</div>
</a>
</div>
<div class="btn_darkblue_white_innerfade btn_medium">
<span>
<a href="${tradeUrlApp}" target="_blank" rel="noopener noreferrer">Offer a trade</a>
</span>
</div>
</div>
<div class="showcase_slot">
<div class="showcase_slot profile_header">
<div class="badge_info_unlocked profile_xp_block_mid avatar_block_status_in-game badge_info_title badge_row_overlay" style="height: 15px;">You</div>
${sendResult}
</div>
<span class="showcase_slot badge_info_title booster_creator_actions">
<h1>➡</h1>
</span>
</div>
<div class="showcase_slot profile_header">
<div class="badge_info_unlocked profile_xp_block_mid avatar_block_status_online badge_info_title badge_row_overlay ellipsis" style="height: 15px;">
${bots.Result[index].Nickname}
</div>
${receiveResult}
</div>
</div>
</div>
`;
if (checkBox === null || checkBox.checked) {
matches += matchTemplate;
}
}
let tradeUrlFull = tradeUrl + "&match=all";
let rowTemplate = `
<div id="asfstmbot_${index}" class="badge_row">
<div class="badge_row_inner">
<div class="badge_title_row guide_showcase_contributors">
<div class="badge_title_stats">
<div class="btn_darkblue_white_innerfade btn_medium">
<span>
<a class="filter_all" name="${appIdList.join()}" target="_blank" rel="noopener noreferrer" >Filter All</a>
</span>
</div>
<div class="btn_darkblue_white_innerfade btn_medium">
<span>
<a class="full_trade_url" href="${tradeUrlFull}" target="_blank" rel="noopener noreferrer" >Offer a trade for all</a>
</span>
</div>
</div>
<div style="float: left;" class="">
<div class="user_avatar playerAvatar online">
<a target="_blank" rel="noopener noreferrer" href="https://steamcommunity.com/profiles/${bots.Result[index].SteamID}">
<img src="https://avatars.cloudflare.steamstatic.com/${bots.Result[index].AvatarHash === null ? "fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb" : bots.Result[index].AvatarHash}.jpg" />
</a>
</div>
</div>
<div class="badge_title">
<a target="_blank" rel="noopener noreferrer" href="https://steamcommunity.com/profiles/${bots.Result[index].SteamID}">${bots.Result[index].Nickname}</a>${any}
 <span style="color: #8F98A0;">(${bots.Result[index].TotalInventoryCount} items)</span>
 <a id="blacklist_${bots.Result[index].SteamID}" data-tooltip-text="Blacklist this bot" class="tooltip hover_tooltip"><img
src="https://community.cloudflare.steamstatic.com/public/images/skin_1/iconForumBan.png?v=1"></a>
</div>
</div>
<div class="badge_title_rule"></div>
${matches}
</div>
</div>
`;
let template = document.createElement("template");
template.innerHTML = rowTemplate.trim();
let mainContentDiv = document.getElementsByClassName("maincontent")[0];
let newChild = template.content.firstChild;
newChild.querySelector(`#blacklist_${bots.Result[index].SteamID}`).addEventListener("click", blacklistEventHandler, true);
newChild.querySelector(".filter_all").parentNode.addEventListener("click", filterAllEventHandler);
mainContentDiv.appendChild(newChild);
checkRow(newChild);
}
function calcState(badge) {
//state 0 - less than max sets; state 1 - we have max sets, even out the rest, state 2 - all even
debugPrint("maxSets=" + badge.maxSets + " LastSet=" + badge.lastSet + " Max cards=" + badge.cards[badge.maxCards - 1].count + " Min cards=" + badge.cards[0].count);
if (badge.cards[badge.maxCards - 1].count === badge.maxSets) {
if (badge.cards[0].count === badge.lastSet) {
return 2; //nothing to do
} else {
return 1; //max sets are here, but we can distribute cards further
}
} else {
return 0; //less than max sets
}
}
function storeMatches(steamID, itemsToSend, itemsToReceive) {
let partner = getPartner(steamID);
tradeParams.matches[partner] = {};
for (let i = 0; i < itemsToSend.length; i++) {
if (tradeParams.matches[partner][itemsToSend[i].appId] === undefined) {
tradeParams.matches[partner][itemsToSend[i].appId] = { send: [], receive: [] };
}
for (let c = 0; c < itemsToSend[i].cards.length; c++) {
for (let a = 0; a < itemsToSend[i].cards[c].count; a++) {
let cardID = tradeParams.cardNames.indexOf(itemsToSend[i].cards[c].hash);
tradeParams.matches[partner][itemsToSend[i].appId].send.push(cardID);
}
}
}
for (let i = 0; i < itemsToReceive.length; i++) {
if (tradeParams.matches[partner][itemsToReceive[i].appId] === undefined) {
throw new Error("Sent and received appIDs don't match!");
}
for (let c = 0; c < itemsToReceive[i].cards.length; c++) {
for (let a = 0; a < itemsToReceive[i].cards[c].count; a++) {
let cardID = tradeParams.cardNames.indexOf(itemsToReceive[i].cards[c].hash);
tradeParams.matches[partner][itemsToReceive[i].appId].receive.push(cardID);
}
}
if (tradeParams.matches[partner][itemsToReceive[i].appId].send.length !== tradeParams.matches[partner][itemsToReceive[i].appId].receive.length) {
throw new Error("Sent and received card count don't match for " + tradeParams.matches[partner][itemsToReceive[i].appId] + " !");
}
}
SaveParams();
}
function compareCards(index, callback) {
let itemsToSend = [];
let itemsToReceive = [];
debugPrint("bot's cards");
debugPrint(JSON.stringify(botBadges));
debugPrint("our cards");
debugPrint(JSON.stringify(myBadges));
for (let i = 0; i < botBadges.length; i++) {
let myBadge = deepClone(myBadges[i]);
let theirBadge = deepClone(botBadges[i]);
let myState = calcState(myBadge);
debugPrint("state=" + myState);
debugPrint("myapp=" + myBadge.appId + " botapp=" + theirBadge.appId);
while (myState < 2) {
let foundMatch = false;
for (let j = 0; j < theirBadge.maxCards; j++) {
//index of card they give
if (theirBadge.cards[j].count > 0) {
//try to match
let myInd = myBadge.cards.findIndex((a) => a.number === theirBadge.cards[j].number); //index of slot where we receive card
if ((myState === 0 && myBadge.cards[myInd].count < myBadge.maxSets) || (myState === 1 && myBadge.cards[myInd].count < myBadge.lastSet)) {
//we need this ^Kfor the Emperor
debugPrint("we need this: " + theirBadge.cards[j].item + " (" + theirBadge.cards[j].count + ")");
//find a card to match.
for (let k = 0; k < myInd; k++) {
//index of card we give
debugPrint("i=" + i + " j=" + j + " k=" + k + " myState=" + myState);
debugPrint("we have this: " + myBadge.cards[k].item + " (" + myBadge.cards[k].count + ")");
if ((myState === 0 && myBadge.cards[k].count > myBadge.maxSets) || (myState === 1 && myBadge.cards[k].count > myBadge.lastSet)) {
//that's fine for us
debugPrint("it's a good trade for us");
let theirInd = theirBadge.cards.findIndex((a) => a.number === myBadge.cards[k].number); //index of slot where they will receive card
if (!bots.Result[index].MatchEverything) {
//make sure it's neutral+ for them
if (theirBadge.cards[theirInd].count >= theirBadge.cards[j].count) {
debugPrint("Not fair for them");
debugPrint("they have this: " + theirBadge.cards[theirInd].item + " (" + theirBadge.cards[theirInd].count + ")");
continue; //it's not neutral+, check other options
}
}
debugPrint("it's a match!");
let itemToSend = {
item: myBadge.cards[k].item,
count: 1,
iconUrl: myBadge.cards[k].iconUrl,
hash: myBadge.cards[k].hash,
};
let itemToReceive = {
item: theirBadge.cards[j].item,
count: 1,
iconUrl: theirBadge.cards[j].iconUrl,
hash: theirBadge.cards[j].hash,
};
//fill items to send
let sendmatch = itemsToSend.find((item) => item.appId == myBadge.appId);
if (sendmatch === undefined) {
let newMatch = {
appId: myBadge.appId,
title: myBadge.title,
cards: [itemToSend],
};
itemsToSend.push(newMatch);
} else {
let existingCard = sendmatch.cards.find((a) => a.hash === itemToSend.hash);
if (existingCard === undefined) {
sendmatch.cards.push(itemToSend);
} else {
existingCard.count += 1;
}
}
//add this item to their inventory
theirBadge.cards[theirInd].count += 1;
//remove this item from our inventory
myBadge.cards[k].count -= 1;
//fill items to receive
let receiveMatch = itemsToReceive.find((item) => item.appId == myBadge.appId);
if (receiveMatch === undefined) {
let newMatch = {
appId: myBadge.appId,
title: myBadge.title,
cards: [itemToReceive],
};
itemsToReceive.push(newMatch);
} else {
let existingCard = receiveMatch.cards.find((a) => a.hash === itemToReceive.hash);
if (existingCard === undefined) {
receiveMatch.cards.push(itemToReceive);
} else {
existingCard.count += 1;
}
}
//add this item to our inventory
myBadge.cards[myInd].count += 1;
//remove this item from their inventory
theirBadge.cards[j].count -= 1;
foundMatch = true;
break; //found a match!
}
}
if (foundMatch) {
//if we found something - we need to sort cards again and start over.
myBadge.cards.sort((a, b) => b.count - a.count);
myState = calcState(myBadge);
debugPrint("new myState=" + myState);
}
}
}
}
if (!foundMatch) {
break; //found no matches - move to next badge
}
theirBadge.cards.sort((a, b) => b.count - a.count);
}
}
debugPrint("items to send");
debugPrint(JSON.stringify(itemsToSend));
debugPrint("items to receive");
debugPrint(JSON.stringify(itemsToReceive));
bots.Result[index].itemsToSend = itemsToSend;
bots.Result[index].itemsToReceive = itemsToReceive;
if (itemsToSend.length > 0) {
storeMatches(bots.Result[index].SteamID, itemsToSend, itemsToReceive);
addMatchRow(index);
callback();
} else {
debugPrint("no matches");
callback();
}
}
function GetOwnCards(index) {
debugPrint("GetOwnCards " + index);
if (index === 0) {
for (let i = 0; i < myBadges.length; i++) {
myBadges[i].cards.length = 0;
}
}
if (index < myBadges.length) {
let profileLink;
profileLink = myProfileLink;
updateMessage("Getting our data for badge " + (index + 1) + " of " + myBadges.length);
updateProgress(index, myBadges.length);
let url = "https://steamcommunity.com/" + profileLink + "/ajaxgetbadgeinfo/" + myBadges[index].appId;
let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "json";
// eslint-disable-next-line
xhr.onload = function () {
if (stop) {
updateMessage("Interrupted by user");
hideThrobber();
enableButton();
let stopButton = document.getElementById("asf_stm_stop");
stopButton.parentNode.removeChild(stopButton);
return;
}
let status = xhr.status;
if (status === 200) {
try {
debugPrint("processing badge " + myBadges[index].appId);
if (xhr.response != undefined && xhr.response.eresult == 1) {
if (xhr.response.badgedata.rgCards.length >= 5) {
errors = 0;
myBadges[index].maxCards = xhr.response.badgedata.rgCards.length;
for (let i = 0; i < myBadges[index].maxCards; i++) {
let newcard = {
item: xhr.response.badgedata.rgCards[i].title,
hash: xhr.response.badgedata.rgCards[i].markethash,
count: xhr.response.badgedata.rgCards[i].owned,
iconUrl: xhr.response.badgedata.rgCards[i].imgurl,
number: i,
};
debugPrint(JSON.stringify(newcard));
myBadges[index].cards.push(newcard);
cardNames.add(xhr.response.badgedata.rgCards[i].markethash);
}
index++;
setTimeout(
(function (index) {
return function () {
GetOwnCards(index);
};
})(index),
globalSettings.weblimiter,
);
return;
} else {
debugPrint("less than 5 cards in a badge - something is wrong");
debugPrint(JSON.stringify(xhr.response));
errors++;
}
} else {
updateMessage("Error getting own badge data, badge: " + myBadges[index].appId);
if (xhr.response != undefined) {
debugPrint("eresult = " + xhr.response.eresult);
}
hideThrobber();
enableButton();