-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfavoritesawarder.js
1604 lines (1525 loc) · 60.2 KB
/
favoritesawarder.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 Favorites Awarder
// @version 2.1
// @description Steam Favorites Awarder
// @author Nitoned
// @match https://steamcommunity.com/*
// @match https://*steampowered.com/*
// @connect steamcommunity.com
// @connect steampowered.com
// @license AGPL-3.0
// @icon https://store.akamai.steamstatic.com/public/images/applications/store/coin_single.png
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @grant GM_setClipboard
// ==/UserScript==
(() => {
'use strict';
//Bots
let GBots = {};
//Award History
let GHistory = {};
//Task
let GTask = {};
//Panel
let GPanel = {};
//Dict
let GObjs = {};
var pointType = "cheap"; //most awards per points (good for leveling/if the person has an excessive amount of awardable items)
//let pointType = "expensive"; //most points per awards (good for low awardable type accounts)
//init
(() => {
loadConf();
graphGUI();
flashBotList();
flashHistoryList();
const { panelMain, panelLeft } = GPanel;
if (panelMain) {
GPanel.panelMain = false;
panelSwitch();
}
if (panelLeft) {
GPanel.panelLeft = false;
leftPanelSwitch();
}
if (!isEmptyObject(GTask)) {
GTask.work = false;
}
appllyTask();
})();
//====================================================================================
//Add Control Pannel
function graphGUI() {
function genButton(text, foo, enable = true) {
const b = document.createElement('button');
b.textContent = text;
b.className = 'aam_button';
b.disabled = !enable;
b.addEventListener('click', foo);
return b;
}
function genDiv(cls = 'aam_div') {
const d = document.createElement('div');
d.className = cls;
return d;
}
function genA(text, url) {
const a = document.createElement('a');
a.textContent = text;
a.className = 'aam_a';
a.target = '_blank';
a.href = url;
return a;
}
function genInput(value, tips, number = false) {
const i = document.createElement('input');
i.className = 'aam_input';
if (value) { i.value = value; }
if (tips) { i.placeholder = tips; }
if (number) {
i.type = 'number';
i.step = 100;
i.min = 0;
}
return i;
}
function genTextArea(value, tips) {
const i = document.createElement('textarea');
i.className = 'aam_textarea';
if (value) { i.value = value; }
if (tips) { i.placeholder = tips; }
return i;
}
function genCheckbox(name, checked = false) {
const l = document.createElement('label');
const i = document.createElement('input');
const s = genSpace(name);
i.textContent = name;
i.type = 'checkbox';
i.className = 'aam_checkbox';
i.checked = checked;
l.appendChild(i);
l.appendChild(s);
return [l, i];
}
function genSelect(choose = [], choice = null) {
const s = document.createElement('select');
s.className = 'aam_select';
choose.forEach(([text, value]) => {
s.options.add(new Option(text, value));
});
if (choice) { s.value = choice; }
return s;
}
function genList(choose = [], choice = null) {
const s = genSelect(choose, choice);
s.className = 'aam_list';
s.setAttribute('multiple', 'multiple');
return s;
}
function genP(text) {
const p = document.createElement('p');
p.textContent = text;
return p;
}
function genSpan(text = ' ') {
const s = document.createElement('span');
s.textContent = text;
return s;
}
const genSpace = genSpan;
function genBr() {
return document.createElement('br');
}
function genHr() {
return document.createElement('hr');
}
function genMidBtn(text, foo) {
const a = document.createElement('a');
const s = genSpan(text);
a.className = 'btn_profile_action btn_medium';
a.addEventListener('click', foo);
a.appendChild(s);
return [a, s];
}
const btnArea = document.querySelector('.profile_header_actions');
const [btnSwitch, bSwitch] = genMidBtn('⭐', panelSwitch);
btnArea.appendChild(genSpace());
btnArea.appendChild(btnSwitch);
btnArea.appendChild(genSpace());
//const panelArea = document.querySelector('.profile_customization_area');
const panelArea = document.querySelector('.profile_leftcol');
const panelMain = genDiv('aam_panel');
panelMain.style.display = 'none';
//const pointheader = genDiv('aam_customization_header');
//panelArea.appendChild(pointheader);
const busyPanel = genDiv('aam_busy');
const busyPanelContent = genDiv('aam_busy_content');
const busyMessage = genP('Loading...');
const busyImg = new Image();
busyImg.src = 'https://steamcommunity-a.akamaihd.net/public/images/login/throbber.gif';
busyPanelContent.appendChild(busyMessage);
busyPanelContent.appendChild(busyImg);
busyPanel.appendChild(busyPanelContent);
panelMain.appendChild(busyPanel);
const workPanel = genDiv('aam_busy aam_work');
const workLog = genTextArea('', 'Log',);
const workHide = genButton('❌ Close', () => { workScreen(false, null); }, true);
workPanel.appendChild(workLog);
workPanel.appendChild(workHide);
panelMain.appendChild(workPanel);
const leftPanel = genDiv('aam_left');
const accountPanel = genDiv('aam_account');
const accountTitle = genSpan('Accounts:');
const accountList = genList([], null);
const accountBtns = genDiv('aam_btns');
const acAdd = genButton('➕ Current', accountAdd);
const acDel = genButton('➖ Remove', accountDel);
const acUpdate = genButton('🔄 Refresh', flashAllAccounts);
accountBtns.appendChild(acAdd);
accountBtns.appendChild(acDel);
accountBtns.appendChild(acUpdate);
accountPanel.appendChild(accountTitle);
accountPanel.appendChild(genBr());
accountPanel.appendChild(accountList);
accountPanel.appendChild(accountBtns);
leftPanel.appendChild(accountPanel);
const historyPanel = genDiv('aam_history');
historyPanel.style.display = 'none';
const historyTitle = genSpan('History:');
const historyList = genList([], null);
const historyBtns = genDiv('aam_btns');
const hsProfile = genButton('🌏 Profile', showProfile);
const hsDelete = genButton('➖ Remove', deleteHistory);
const hsClear = genButton('🗑️ Clear', clearHistory);
const hsReload = genButton('🔄 Refresh', flashHistoryList);
historyBtns.appendChild(hsProfile);
historyBtns.appendChild(hsDelete);
historyBtns.appendChild(hsClear);
historyBtns.appendChild(hsReload);
historyPanel.appendChild(historyTitle);
historyPanel.appendChild(genBr());
historyPanel.appendChild(historyList);
historyPanel.appendChild(historyBtns);
leftPanel.appendChild(historyPanel);
panelMain.appendChild(leftPanel);
const awardPanel = genDiv('aam_award');
const feedbackLink = genA('Feedback', 'https://github.com/encumber/SteamPointAwarder/issues');
const awardBot = genSelect([['---Not Selected---', '']], null);
const awardSteamID = genInput('', 'Steam ID 64', false);
const awardPoints = genInput('', 'Points Recieved', true);
//const [awardCProfile, awardProfile] = genCheckbox('Profile', false);
//const [awardCRecommand, awardRecommand] = genCheckbox('Review', false);
const [awardCScreenshot, awardScreenshot] = genCheckbox('Screenshot', true);
//const [awardCGuide, awardGuide] = genCheckbox('Guide', true);
// const [awardCVideo, awardVideo] = genCheckbox('Video', true);
//const [awardCWorkshop, awardWorkshop] = genCheckbox('Workshop', true);
const [awardCImage, awardImage] = genCheckbox('Artwork', true);
const awardBtns1 = genDiv('aam_btns');
const awardBtnCurrent = genButton('🤵 Current User', getCurrentProfile);
//Currently Broken
//const awardBtnCalc = genButton('📊 Calculate', calcAwardItems);
const awardBtns2 = genDiv('aam_btns');
const awardBtnSet = genButton('Confirm', applyAwardConfig);
const awardBtnReset = genButton('Reset', restoreAwardConfig);
const hSwitch = genButton('History', leftPanelSwitch);
const awardBtns3 = genDiv('aam_btns aam_award_btns');
const awardBtnStart = genButton('✅ Start', startAward, false);
const awardBtnStop = genButton('⛔ Stop', stopAward, false);
const awardStatus = genSpan('');
//const pointTypeList = genList(["cheap", "expensive"], pointType);
if (pointType === "cheap") {
var pointTypeNum = '1200';
} else if (pointType === "expensive") {
var pointTypeNum = '6600';
}
const panelMain2 = genDiv('profile_customization_header headeroverried profile_customization');
let panel2Message = genP('Steam Favorites Awarder: ' + pointTypeNum + ' points per item');
panelMain2.style.display = 'none';
panelArea.insertBefore(panelMain2, panelArea.firstChild);
panelMain2.appendChild(panel2Message)
panelMain2.appendChild(panelMain)
panelMain2.appendChild(genSpace())
awardBtns1.appendChild(awardBtnCurrent);
awardPanel.appendChild(genBr());
awardBtns2.appendChild(awardBtnSet);
awardBtns2.appendChild(awardBtnReset);
awardBtns2.appendChild(hSwitch);
awardBtns3.appendChild(awardBtnStart);
awardBtns3.appendChild(awardBtnStop);
awardBtns3.appendChild(awardStatus);
awardPanel.appendChild(genSpan('Bot Account:'));
awardPanel.appendChild(feedbackLink);
//awardPanel.appendChild(genBr());
awardPanel.appendChild(awardBot);
awardPanel.appendChild(genSpan('Send To (SteamID):'));
//awardPanel.appendChild(genBr());
awardPanel.appendChild(awardSteamID);
awardPanel.appendChild(awardBtns1);
awardPanel.appendChild(genSpan('Points Recieved:'));
//awardPanel.appendChild(genBr());
awardPanel.appendChild(awardPoints);
awardPanel.appendChild(genSpan('Award Types:'));
awardPanel.appendChild(genBr());
//awardPanel.appendChild(awardCProfile);
//awardPanel.appendChild(awardCRecommand);
//awardPanel.appendChild(genBr());
awardPanel.appendChild(awardCScreenshot);
awardPanel.appendChild(awardCImage);
//awardPanel.appendChild(genBr());
//awardPanel.appendChild(awardCGuide);
//awardPanel.appendChild(awardCVideo);
//awardPanel.appendChild(genBr());
//awardPanel.appendChild(awardCWorkshop);
awardPanel.appendChild(genBr());
awardPanel.appendChild(awardBtns2);
awardPanel.appendChild(genBr());
awardPanel.appendChild(awardBtns3);
panelMain.appendChild(awardPanel);
const panelFix = document.querySelector(".profile_customization_area");
const panelFix2 = document.querySelector(".profile_customization");
Object.assign(GObjs, {
bSwitch, hSwitch, panelMain, panelMain2, panelFix, panelFix2,
busyPanel, busyMessage, workPanel, workLog, workHide,
accountPanel, accountList, historyPanel, historyList,
awardBot, awardSteamID, awardPoints, awardStatus,
awardScreenshot, awardImage,
awardBtnStart, awardBtnStop, awardBtnSet, awardBtnReset
});
}
//Panel display switch
function panelSwitch() {
const { bSwitch, panelMain, panelMain2, panelFix, panelFix2 } = GObjs;
if (GPanel.panelMain !== true) {
panelMain.style.display = '';
panelMain2.style.display = '';
//panelFix.style.padding = "1em 0em 0em 0em";
bSwitch.textContent = '⭐';
GPanel.panelMain = true;
GPanel.panelMain2 = true;
try {
panelFix.style.padding = "1em 0em 0em 0em";
panelFix2.style.display = '';
} catch {}
} else {
panelMain.style.display = 'none';
panelMain2.style.display = 'none';
bSwitch.textContent = '⭐';
GPanel.panelMain = false;
GPanel.PanelMain2 = false;
try {
panelFix.style.padding = "0em 0em 0em 0em";
panelFix2.style.display = 'none';
} catch {}
}
GM_setValue('panel', GPanel);
}
//Left panel toggle
function leftPanelSwitch() {
const { hSwitch, accountPanel, historyPanel } = GObjs;
if (GPanel.panelLeft !== true) {
accountPanel.style.display = 'none';
historyPanel.style.display = '';
hSwitch.textContent = 'Bots';
GPanel.panelLeft = true;
} else {
historyPanel.style.display = 'none';
accountPanel.style.display = '';
hSwitch.textContent = 'History';
GPanel.panelLeft = false;
}
GM_setValue('panel', GPanel);
}
//Add Account
function accountAdd() {
let v_nick, v_token, v_steamID;
loadScreen(true, 'Get login...');
getMySteamID()
.then(({ nick, steamID }) => {
v_nick = nick;
v_steamID = steamID;
loadScreen(true, 'Get Token...');
return getToken();
})
.then((tk) => {
v_token = tk;
loadScreen(true, 'Get Points...');
return getPoints(v_steamID, tk);
})
.then((points) => {
showAlert('Success', `Added Successfully\nAvailable Points: ${points}`, true);
GBots[v_steamID] = { nick: v_nick, token: v_token, points }
GM_setValue('bots', GBots);
flashBotList();
})
.catch((reason) => {
showAlert('Error', reason, false);
}).finally(() => {
loadScreen(false, null);
});
}
//Remove Account
function accountDel() {
const { accountList } = GObjs;
if (accountList.selectedIndex >= 0) {
showConfirm('Confirm', 'Are you sure you want to remove the selected account?', () => {
let i = 0;
for (const opt of accountList.selectedOptions) {
delete GBots[opt.value];
i++;
}
flashBotList();
GM_setValue('bots', GBots);
showAlert('Alert', `Removed ${i} accounts`, true);
}, null);
} else {
showAlert('Error', 'No accounts were selected', false);
}
}
//Refresh Accounts
async function flashAllAccounts() {
//Refresh Points
function makePromise(sid, tk) {
return new Promise((resolve, reject) => {
getPoints(sid, tk)
.then((points) => {
GBots[sid].points = points;
loadScreen(true, `Progress: ${++fin} / ${count}`);
}).catch((reason) => {
GBots[sid].points = -1;
// GBots[sid].nick = 'Failed';
loadScreen(true, `${sid} Error: ${reason}`);
}).finally(() => {
GM_setValue('bots', GBots);
resolve();
});
});
}
let count = 0, fin = 0;
for (const _ in GBots) {
count++;
}
if (count > 0) {
loadScreen(true, 'Loading Points...');
const pList = [];
for (const steamID in GBots) {
const { token } = GBots[steamID];
pList.push(makePromise(steamID, token));
}
Promise.all(pList)
.finally(() => {
loadScreen(false, null);
flashBotList();
if (fin >= count) {
showAlert('Success', 'Points refreshed', true);
} else {
showAlert('Error', 'Refresh failed, any displayed as [-1] have failed', true);
}
});
} else {
showAlert('Error', 'Accounts list is empty', false);
}
}
//Refresh Account List
function flashBotList() {
const { bot } = GTask;
const { accountList, awardBot } = GObjs;
accountList.options.length = 0;
awardBot.options.length = 0;
awardBot.options.add(new Option('---Not Selected---', ''))
let i = 1;
let flag = false;
if (!isEmptyObject(GBots)) {
for (const steamID in GBots) {
const { nick, points } = GBots[steamID];
const pointsStr = parseInt(points).toLocaleString();
accountList.options.add(new Option(`${i} | ${nick} | ${steamID} | ${pointsStr} Points`, steamID));
awardBot.options.add(new Option(`${i++} | ${nick} | ${pointsStr} Points`, steamID))
if (steamID === bot) {
flag = true;
awardBot.selectedIndex = i - 1;
}
}
} else {
accountList.options.add(new Option('-- If there are no accounts, Add current account --', ''));
}
if ((!isEmptyObject(GTask)) && (!flag)) {
GTask = {};
GM_setValue('task', GTask);
appllyTask();
showAlert('Alert', 'The robot account has been modified, and the tipping settings have been reset!', false);
}
}
//Refresh the history
function flashHistoryList() {
const { historyList } = GObjs;
historyList.options.length = 0;
let i = 1;
if (!isEmptyObject(GHistory)) {
for (const steamID in GHistory) {
const [nick, points] = GHistory[steamID];
const pointsStr = parseInt(points).toLocaleString();
historyList.options.add(new Option(`${i++} | Awarded ${nick.replace(/([﷽⎛⎞])/g, '░')}'s Favorites ${pointsStr} Points`, steamID));
}
} else {
historyList.options.add(new Option('-- There is no history, it will automatically update once awarding starts --', ''));
}
}
//historical record points
function addHistory(steamID, nick, points) {
if (GHistory[steamID] !== undefined) {
GHistory[steamID] = [nick, GHistory[steamID][1] + points];
} else {
GHistory[steamID] = [nick, points];
}
GM_setValue('history', GHistory);
}
//Get current profile
function getCurrentProfile() {
const { awardSteamID } = GObjs;
awardSteamID.value = g_rgProfileData.steamid;
}
//Calculate award items
function calcAwardItems() {
const { awardSteamID } = GObjs;
const steamID = awardSteamID.value;
if (steamID === '') {
showAlert('Error', 'No SteamID!', false);
} else {
loadScreen(true, 'Loading Profile...');
getProfile(steamID)
.then(([succ, nick]) => {
if (succ) {
loadScreen(true, 'Stats can be rewarded in the project...');
const pList = [
// getAwardCounts(steamID, 'r'),
getAwardCounts(steamID, 's'),
getAwardCounts(steamID, 'i')
//getAwardCounts(steamID, 'g'),
//getAwardCounts(steamID, 'v'),
//getAwardCounts(steamID, 'w')
];
Promise.all(pList)
.then((result) => {
const data = {};
let sum = 0;
for (const [type, succ, count] of result) {
if (succ) {
const points = count * 6600;
data[type] = `${count} Can be awarded:${points.toLocaleString()} Points`;
sum += points;
} else {
data[type] = 'Read Error';
}
}
let text = `<p>Username:${nick}</p><p>Reviews:${data.r}</p><p>Screenshots:${data.s}</p><p>Artworks:${data.i}</p><p>Total Points:${sum.toLocaleString()} Points</p><p>*not 100% accurate*</p>`
showAlert('Alert', text, true);
})
.finally(() => {
loadScreen(false, null);
});
} else {
showAlert('Error', 'Account does not exist, check if SteamID is correct [🤵Current User] to set automatically', false);
loadScreen(false, null);
}
})
.catch((reason) => {
showAlert('Error', `<p>Network error, read profile failed</p><p>${reason}</p>`, false)
loadScreen(false, null);
});
}
}
//View Profile
function showProfile() {
const { historyList } = GObjs;
const i = historyList.selectedIndex;
if (i > -1) {
const { value } = historyList.options[i];
if (value != '') {
window.open(`https://steamcommunity.com/profiles/${value}`);
}
} else {
showAlert('Alert', 'History is not checked!', false);
}
}
//clear history
function clearHistory() {
if (!isEmptyObject(GHistory)) {
showConfirm('Confirm', 'Are you sure you want to clear award history?', () => {
GHistory = {};
flashHistoryList();
GM_setValue('history', GHistory);
showAlert('Alert', 'Cleared successfully', true);
}, null);
} else {
showAlert('Alert', 'History is empty!', false);
}
}
//delete history
function deleteHistory() {
const { historyList } = GObjs;
if (historyList.selectedIndex >= 0) {
showConfirm('Confirm', 'Are you sure you want to delete the selected award history?', () => {
let i = 0;
for (const opt of historyList.selectedOptions) {
delete GHistory[opt.value];
i++;
}
flashHistoryList();
GM_setValue('history', GHistory);
showAlert('Alert', `${i} History deleted`, true);
}, null);
} else {
showAlert('Alert', 'History has not been selected!', false);
}
}
//Save award settings
function applyAwardConfig() {
const {
awardBtnStart, awardBtnStop,
awardBot, awardSteamID, awardPoints,
awardScreenshot, awardImage
} = GObjs;
awardBtnStart.disabled = awardBtnStop.disabled = true;
let bot = awardBot.value;
let points = parseInt(awardPoints.value);
let steamID = String(awardSteamID.value).trim();
let type = 0;
//if (!awardProfile.checked) { type += 1; }
//if (!awardRecommand.checked) { type += 2; }
if (!awardScreenshot.checked) { type += 4; }
//if (!awardGuide.checked) { type += 5; }
//if (!awardVideo.checked) { type += 6; }
//if (!awardWorkshop.checked) { type += 7; }
if (!awardImage.checked) { type += 8; }
if (bot == '') {
showAlert('Error', 'No bots have been selected!', false);
} else if (steamID === '') {
showAlert('Error', 'No SteamID to Award,Use [💬Current User]', false);
} else if (!steamID.match(/^\d+$/)) {
showAlert('Error', 'SteamID is invalid,Use [💬Current User]', false);
} else if (points !== points || points < 100) {
showAlert('Error', 'Points can only be a number', false);
} else if (type === 15) {
showAlert('Error', 'Type not selected', false);
} else {
points = Math.ceil(points / 100) * 100;
GTask = { bot, steamID, points, type, work: false, nick: null };
awardBtnStart.disabled = awardBtnStop.disabled = false;
GM_setValue('task', GTask);
showAlert('Alert', 'Settings Saved [✅ Start Awarding]', true);
}
}
//Reset Award Settings
function restoreAwardConfig() {
showConfirm('Confirm', 'Are you sure you want to reset settings?', () => {
GTask = {};
GM_setValue('task', GTask);
appllyTask();
showAlert('Alert', 'Settings cleared', true);
}, null);
}
//Apply Settings
function appllyTask() {
const {
awardBtnStart, awardBtnStop,
awardBot, awardSteamID, awardPoints,
awardScreenshot, awardImage
} = GObjs;
const { bot, steamID, points, type } = GTask;
awardBtnStart.disabled = awardBtnStop.disabled = isEmptyObject(GTask);
awardBot.value = bot ? bot : '';
awardSteamID.value = steamID ? steamID : '';
awardPoints.value = points ? points : '';
//awardProfile.checked = !Boolean(type & 1);
//awardRecommand.checked = !Boolean(type & 2);
//awardGuide.checked = !Boolean(type & 5);
awardScreenshot.checked = !Boolean(type & 4);
//awardWorkshop.checked = !Boolean(type & 7);
// awardVideo.checked = !Boolean(type & 6);
awardImage.checked = !Boolean(type & 8);
}
//Start Awarding
async function startAward() {
if (isEmptyObject(GTask)) {
showAlert('Error', 'Missing Data', false);
return;
}
const { steamID, work, points, bot, nick: taskNick } = GTask;
const { nick: botNick } = GBots[bot];
const pointsStr = parseInt(points).toLocaleString();
if (!work) {
spaceLine(1);
if (!taskNick) {
loadScreen(true, 'Reading Profile to Award');
getProfile(steamID)
.then(([succ, nickName]) => {
if (succ) {
GTask.work = true;
GTask.nick = nickName;
GM_setValue('task', GTask);
print(`Award Settings:\n〖Username:${nickName},Estimated recieved:${pointsStr} Points,Bot:${botNick}〗`);
print('Awarding starts after 2s, click [⛔ Stop Awarding] to terminate in advance!');
workScreen(true);
setTimeout(() => {
autoAward();
}, 2000);
} else {
print('No Profile Found', 'E');
showAlert('Error', 'Make sure SteamID is correct<br>Reccomend [🤵Current User] for better results', false);
}
})
.catch((reason) => {
showAlert('Error', `<p>Network error, read profile failed</p><p>${reason}</p>`, false)
}).finally(() => {
loadScreen(false, null);
});
} else {
GTask.work = true;
GM_setValue('task', GTask);
print(`〖Username:${taskNick},Estimated recieved:${pointsStr} Points,Bot:${botNick}〗`);
print('Awarding starts after 2s, click [⛔ Stop Awarding] to terminate in advance!');
workScreen(true);
setTimeout(() => {
autoAward();
}, 2000);
}
} else {
print('Awarding Started');
}
}
//Stop Awarding
async function stopAward() {
if (isEmptyObject(GTask)) {
showAlert('Error', 'Missing Data', false);
return;
}
const { work } = GTask;
if (work) {
spaceLine(4);
print('Manually stop Awarding by Clicking [❌ Close]');
GTask.work = false;
GM_setValue('task', GTask);
showStatus('Stopped', false);
} else {
showAlert('Error', 'Awarding hasn\'t started', false);
}
}
//Awards Dict
/*
const reactionsDict1 = {
1: 300, 2: 300, 3: 300, 4: 300, 5: 300, 6: 300, 7: 300, 8: 300, 12: 300, 18: 300, 21: 300, 23: 300
};
const reactionValues1 = [
300, 300, 300, 300, 300, 300, 300, 300, 300,
300, 300, 300
];
const reactionIDs1 = [
1, 2, 3, 4, 5, 6, 7, 8, 12,
18, 21, 23
];
const reactionsDict2 = {
1: 300, 2: 300, 3: 300, 4: 300, 5: 300, 6: 300, 7: 300, 8: 300, 9: 600,
10: 1200, 11: 2400, 12: 300, 13: 2400, 14: 600, 15: 1200, 16: 600,
17: 4800, 18: 300, 19: 600, 20: 1200, 21: 300, 22: 600, 23: 300
};
const reactionValues2 = [
300, 300, 300, 300, 300, 300, 300, 300, 600, 1200, 2400, 300,
2400, 600, 1200, 600, 4800, 300, 600, 1200, 300, 600, 300
];
const reactionIDs2 = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
];
let reactionsDict = reactionsDict1
let reactionIDs = reactionIDs1
let reactionValues = reactionValues1
*/
if (pointType === "cheap") {
var reactionsDict = {
1: 300, 2: 300, 3: 300, 4: 300, 5: 300, 6: 300, 7: 300, 8: 300, 12: 300, 18: 300, 21: 300, 23: 300
};
var reactionValues = [
300, 300, 300, 300, 300, 300, 300, 300, 300,
300, 300, 300
];
var reactionIDs = [
1, 2, 3, 4, 5, 6, 7, 8, 12,
18, 21, 23
];
} else if (pointType === "expensive") {
var reactionsDict = {
1: 300, 2: 300, 3: 300, 4: 300, 5: 300, 6: 300, 7: 300, 8: 300, 9: 600,
10: 1200, 11: 2400, 12: 300, 13: 2400, 14: 600, 15: 1200, 16: 600,
17: 4800, 18: 300, 19: 600, 20: 1200, 21: 300, 22: 600, 23: 300
};
var reactionValues = [
300, 300, 300, 300, 300, 300, 300, 300, 600, 1200, 2400, 300,
2400, 600, 1200, 600, 4800, 300, 600, 1200, 300, 600, 300
];
var reactionIDs = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
];
}
//Auto Award
async function autoAward() {
//Award Type
const reactionType = {
's': ['2', 'Screenshots'], 'i': ['2', 'Artwork']
};
const { bot, steamID, type, points: pointsGoal, nick: taskNick } = GTask;
const { nick: botNick, token } = GBots[bot];
appllyTask();
addHistory(steamID, taskNick, 0);
showStatus('Start', true);
let pointsLeft = pointsGoal;
if (token) {
const workflow = [];
if (!Boolean(type & 8)) { workflow.push('i') }; //Artwork
if (!Boolean(type & 4)) { workflow.push('s') }; //Screenshots
//if (!Boolean(type & 2)) { workflow.push('r') }; //Reviews
// if (!Boolean(type & 1)) { workflow.push('p') }; //Profile
// if (!Boolean(type & 5)) { workflow.push('g') }; //Guides
//if (!Boolean(type & 6)) { workflow.push('v') }; //Videos
//if (!Boolean(type & 5)) { workflow.push('w') }; //Workshop
while (GTask.work && workflow.length > 0) {
const award_type = workflow.pop();
const [target_type, target_name] = reactionType[award_type];
let process = genProgressBar((pointsGoal - pointsLeft) / pointsGoal * 100);
spaceLine(3);
print(`[${target_name}] Started,Remaining/Total:${pointsLeft.toLocaleString()}/${pointsGoal.toLocaleString()}`);
print(`Progress:${process}`);
spaceLine(3);
let coast = 0;
if (target_type === '3') { //Profile
let GoldReactions = null;
for (let i = 0; i < 3; i++) { //Retry 3 times
if (GoldReactions === null) { //List Empty, retry award
const [succOld, oldReactions] = await getAwardRecords(token, target_type, steamID);
if (!succOld) {
print('Failed to load awards');
continue;
}
GoldReactions = oldReactions;
const todoReactions = selectFitableReactions(pointsLeft, GoldReactions);
if (todoReactions.length === 0) {
print(`[${target_name}] No awards left,skipping`);
break;
}
coast = sumReactionsPoints(todoReactions);
print(`[${target_name}] will be awarded:${todoReactions.length} awards,Points:${coast.toLocaleString()}`)
const plist = [];
for (const id of todoReactions) {
plist.push(sendAwardReaction(token, target_type, steamID, id));
}
print('Awarding...');
const result = await Promise.all(plist);
const [succ, fail] = countSuccess(result);
print(`Sent/Failed:${succ} / ${fail}`);
}
//Count the new award list and calculate the awarded points
const [succNew, newReactions] = await getAwardRecords(token, target_type, steamID);
if (!succNew) {
print('Failed to load awards,retrying after 2s');
await aiosleep(2000);
continue;
}
const diffReactions = filterDiffReactions(newReactions, GoldReactions);
coast = sumReactionsPoints(diffReactions);
pointsLeft -= coast;
addHistory(steamID, taskNick, coast);
print(`[${target_name}] Successfully awarded:${diffReactions.length} awards,Points:${coast.toLocaleString()}`);
break;
}
GTask.points = pointsLeft;
if (pointsLeft <= 0) {
GTask.work = false;
}
GM_setValue('task', GTask);
process = genProgressBar((pointsGoal - pointsLeft) / pointsGoal * 100);
spaceLine(3);
print(`[${target_name}] Awarding stared,Remaining / Total:${pointsLeft.toLocaleString()} / ${pointsGoal.toLocaleString()}`);
print(`Progress:${process}`);
spaceLine(3);
print('Updating points balances');
await getPoints(bot, token)
.then((p) => {
GBots[bot].points = p;
GM_setValue('bots', GBots);
print(`[${botNick}] has,${p.toLocaleString()} Points left`);
if (p < 300) {
print(`[${botNick}] has no points, stopping`);
GTask.work = false;
}
}).catch((r) => {
print(`[${botNick}] Points update failed:${r}`);
});
} else { //Screenshots
let page = 1;
while (GTask.work) {
let j = 0;
print('Getting Awarded Items');
const [succ, items] = await getAwardItems(steamID, award_type, page++);
if (!succ) {
page--;
if (++j < 3) {
print(`Failed to load awardable items, retrying after 2s`);
await aiosleep(2000);
continue;
} else {
print(`Failed to load awardable items, skipping...`);
break;
}
}
if (items.length === 0) {
print(`[${target_name}] List is empty`);
break;
}
print(`[${target_name}] Successfully loaded ${items.length} items`);
for (const itemID of items) {
print(`[${target_name}] Item ID:${itemID}`);
let GoldReactions = null;
for (let i = 0; i < 3; i++) {
if (GoldReactions === null) { //The old award list is empty, re-read and award
const [succOld, oldReactions] = await getAwardRecords(token, target_type, itemID);
if (!succOld) {
print('Failed to get awardable items, try again...');
continue;
}
GoldReactions = oldReactions;
const todoReactions = selectFitableReactions(pointsLeft, GoldReactions);
if (todoReactions.length === 0) {
print(`[${target_name}] No suitablke awards,Skipping...`);
break;
}
coast = sumReactionsPoints(todoReactions);
print(`[${target_name}] Will recieve:${todoReactions.length} awards,Points:${coast.toLocaleString()}`)
const plist = [];
for (const id of todoReactions) {
plist.push(sendAwardReaction(token, target_type, itemID, id));
}
print('Sending Awards...');
const result = await Promise.all(plist);
const [succ, fail] = countSuccess(result);
print(`Sent/Fail:${succ} / ${fail}`);
}
print('*Waiting 2s to prevent ratelimit.*');
await asleep(2000);
//Count the new award list and calculate the awarded points
const [succNew, newReactions] = await getAwardRecords(token, target_type, itemID);
if (!succNew) {
print('Failed to get awardable items, try again...');
continue;
}
const diffReactions = filterDiffReactions(newReactions, GoldReactions);
coast = sumReactionsPoints(diffReactions);
pointsLeft -= coast;
addHistory(steamID, taskNick, coast);
print(`[${target_name}] Successfully Awarded:${diffReactions.length} awards,Points:${coast.toLocaleString()}`);
break;
}
GTask.points = pointsLeft;
if (pointsLeft <= 0) {
GTask.work = false;
}
GM_setValue('task', GTask);
process = genProgressBar((pointsGoal - pointsLeft) / pointsGoal * 100);
spaceLine(3);
print(`[${target_name}] Awarding,Remaining / Total:${pointsLeft.toLocaleString()} / ${pointsGoal.toLocaleString()}`);
print(`Progress:${process}`);
spaceLine(3);
print('Updating Points Balances');