-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.user.js
More file actions
3402 lines (3032 loc) · 152 KB
/
script.user.js
File metadata and controls
3402 lines (3032 loc) · 152 KB
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 SilverScripts
// @namespace http://tampermonkey.net/
// @version 7.6.6
// @description Find out prices of items in your inventory by hovering over them while at the Marketplace, in the Inner City, or whilst browsing your Inventory in the Outpost, automatically use services, edit and equip Quickswaps/Loadouts, and more!
// @author SilverBeam
// @match *fairview.deadfrontier.com/onlinezombiemmo/index.php*
// @match *fairview.deadfrontier.com/onlinezombiemmo/DF3D/DF3D_InventoryPage.php?page=31*
// @match *fairview.deadfrontier.com/onlinezombiemmo/
// @grant GM.getValue
// @grant GM.setValue
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest
// @grant GM_openInTab
// @grant GM.openInTab
// @require https://greasyfork.org/scripts/445697/code/index.js?version=1055427
// @license GPL-3.0-or-later
// ==/UserScript==
(function() {
'use strict';
//////////////////////////////
// Variables Declaration //
/////////////////////////////
var userVars = unsafeWindow.userVars;
var globalData = unsafeWindow.globalData;
var infoBox = unsafeWindow.infoBox;
var itemsDataBank = {};
var servicesDataBank = {};
var inventoryArray = [];
var loadouts = [];
var pickingLoadoutCategory = "";
var pickingLoadoutSlotIndex = -1;
var activeLoadoutEdit = -1;
var lastSlotHovered = -1;
var tooltipDisplaying = false;
var userData = {};
var savedMarketData = {"requestsIssued":0,"previousDataTimestamp":0,"previousItemTimestamp":{},"previousServicesTimestamp":0,"itemsDataBank":{},"servicesDataBank":{}};
var characterCookieData = {};
var lastActiveUserID = null;
var REQUEST_LIMIT = 17;
var userSettings = {"hoverPrices":true,"autoService":true,"autoMarketWithdraw":true,"alwaysDisplayQuickSwitcher":false};//Default Settings
var updateCheck = {"skipVer":"0.0.0","lastCheck":"1980-01-01"};
var uploadedVersion; //This is saved here to avoid calling 2 times the GM library
var pendingRequests = {
"requestsNeeded": 0,
"requestsCompleted": 0,
"requesting": false,
"requestsCooldownPeriod": 500, //Minimum time before another refresh is issued again after an inventory change
"requestsCoolingDown": false
};
var locations = {
"inventories": [
"fairview.deadfrontier.com/onlinezombiemmo/index.php?page=25",
"fairview.deadfrontier.com/onlinezombiemmo/index.php?page=35",
"fairview.deadfrontier.com/onlinezombiemmo/index.php?page=24",
"fairview.deadfrontier.com/onlinezombiemmo/index.php?page=50",
"fairview.deadfrontier.com/onlinezombiemmo/DF3D/DF3D_InventoryPage.php?page=31",
],
"marketplace" : ["fairview.deadfrontier.com/onlinezombiemmo/index.php?page=35"],
"yard" : ["fairview.deadfrontier.com/onlinezombiemmo/index.php?page=24"],
"storage" : ["fairview.deadfrontier.com/onlinezombiemmo/index.php?page=50"],
"ICInventory" : ["fairview.deadfrontier.com/onlinezombiemmo/DF3D/DF3D_InventoryPage.php?page=31"],
"forum" : ["fairview.deadfrontier.com/onlinezombiemmo/index.php?board=","fairview.deadfrontier.com/onlinezombiemmo/index.php?action=forum","fairview.deadfrontier.com/onlinezombiemmo/index.php?topic="]
};
var helpWindow = unsafeWindow.prompt;
var helpWindowStructure = {
"home": {
"data":
[
["span","Welcome to SilverScripts Help and Settings!",[]],
["p"," ",[]],
["button","AutoService Help",[],openHelpWindowPage,["autoService"]],
["button","AutoService not working?",[],openHelpWindowPage,["serviceReadme"]],
["button","MarketWithdraw Help",[],openHelpWindowPage,["marketWithdraw"]],
["button","Settings",[],openHelpWindowPage,["settings"]],
["button","Close",[],closeHelpWindowPage,[]]
],
"style":
[
["height","145px"]
]
},
"serviceReadme": {
"data":
[
["span","Warning!Prices are updated only when something in the inventory changes. If you are unable to purchase a service, move an item in the inventory around to refresh services data!",[]],
["p","",[]],
["div","",[],[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["home"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","160px"]
]
},
"autoService": {
"data":
[
["span","If you hold the <span style='color: #ff0000;'>[ALT]</span> key while hovering on a serviceable item, a prompt will appear. By ALT+Clicking, the relevant service for that item will be automatically bought from the market.",[]],
["p","",[]],
["div","",[],[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["home"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","170px"]
]
},
"marketWithdraw": {
"data":
[
["span","If you don't have enough cash to buy an item, the <span style='color: #ff0000;'>buy</span> button is replaced by a <span style='color: #ff0000;'>withdraw</span> button. By pressing it, the necessary cash will be withdrawn from your bank. The button is disabled if the bank doesn't have enough cash. This function can be disabled in the settings.",[]],
["p","",[]],
["div","",[],[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["home"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","205px"]
]
},
"settings": {
"data":
[
["button","Disable HoverPrices",[],flipSetting,["hoverPrices",0]],
["button","Disable AutoService",[],flipSetting,["autoService",1]],
["button","Disable AutoMarketWithdraw",[],flipSetting,["autoMarketWithdraw",2]],
["button","Enable AlwaysDisplayQuickSwitcher",[],flipSetting,["alwaysDisplayQuickSwitcher",3]],
["p","",[]],
["div","",[],[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["home"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","110px"],
["width", "300px"]
]
},
"loadoutsMenu": {
"data":
[
["button","Equip Quickswap",{"style":[["position","absolute"],["left","30px"]]},loadoutOpenEquipMenu,[]],
["button","Edit Quickswap",{"style":[["position","absolute"],["left","30px"]]},loadoutOpenEditMenu,[]],
["button","Reset Quickswap",{"style":[["position","absolute"],["left","30px"]]},loadoutOpenResetMenu,[]],
["p","",[]],
["button","Close",{"style":[["position","absolute"],["left","30px"]]},closeHelpWindowPage,[]]
],
"style":
[
["height","130px"],
["width","300px"]
]
},
"loadoutsListEquip": {
"data":
[
["div","",[],[
["button","Equip Quickswap:",{"style":[["position","absolute"],["left","30px"]]},equipLoadout,[0]],
["span","1",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Equip Quickswap:",{"style":[["position","absolute"],["left","30px"]]},equipLoadout,[1]],
["span","2",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Equip Quickswap:",{"style":[["position","absolute"],["left","30px"]]},equipLoadout,[2]],
["span","3",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Equip Quickswap:",{"style":[["position","absolute"],["left","30px"]]},equipLoadout,[3]],
["span","4",{"style":[["position","absolute"],["right","30px"]]}]
]],
["p","",[]],
["div","",[],[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["loadoutsMenu"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","130px"],
["width","300px"]
]
},
"loadoutsListEdit": {
"data":
[
["div","",[],[
["button","Edit Quickswap:",{"style":[["position","absolute"],["left","30px"]]},editLoadout,[0]],
["span","1",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Edit Quickswap:",{"style":[["position","absolute"],["left","30px"]]},editLoadout,[1]],
["span","2",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Edit Quickswap:",{"style":[["position","absolute"],["left","30px"]]},editLoadout,[2]],
["span","3",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Edit Quickswap:",{"style":[["position","absolute"],["left","30px"]]},editLoadout,[3]],
["span","4",{"style":[["position","absolute"],["right","30px"]]}]
]],
["p","",[]],
["div","",[],[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["loadoutsMenu"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","130px"],
["width","300px"]
]
},
"loadoutEdit": {
"data":
[
["p","",[]],
["div","",[],[
["button","Quickswap Name:",{"style":[["position","absolute"],["left","70px"]]},renameLoadout,[]],
["span","name",{"style":[["position","absolute"],["right","70px"]]}]
]],
["p","",[]],
["span","Armor",{"style":[["position","absolute"],["left","160px"]]}],
["div","",[],[
["div","",{"style":[["position","absolute"],["left","160px"]],"className":"slot validSlot silverScriptsSlot armour","id":"armour_0"},[]],
]],
["p","",[]],
["p","",[]],
["span","Weapons",{"style":[["position","absolute"],["left","155px"]]}],
["div","",[],[
["div","",{"style":[["position","absolute"],["left","100px"]],"className":"slot validSlot silverScriptsSlot weapon","id":"weapon_0"},[]],
["div","",{"style":[["position","absolute"],["left","160px"]],"className":"slot validSlot silverScriptsSlot weapon","id":"weapon_1"},[]],
["div","",{"style":[["position","absolute"],["left","220px"]],"className":"slot validSlot silverScriptsSlot weapon","id":"weapon_2"},[]],
]],
["p","",[]],
["p","",[]],
["span","Implants",{"style":[["position","absolute"],["left","148px"]]}],
["div","",{"style":[["position","absolute"],["width","100%"],["height","176px"]]},[
["div","",{"style":[["position","absolute"],["left","100px"],["width","100%"],["height","44px"]]},[
["div","",{"style":[["position","absolute"],["left","0px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_0"},[]],
["div","",{"style":[["position","absolute"],["left","44px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_1"},[]],
["div","",{"style":[["position","absolute"],["left","88px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_2"},[]],
["div","",{"style":[["position","absolute"],["left","132px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_3"},[]],
]],
["div","",{"style":[["position","absolute"],["left","100px"],["top","44px"],["width","100%"],["height","44px"]]},[
["div","",{"style":[["position","absolute"],["left","0px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_4"},[]],
["div","",{"style":[["position","absolute"],["left","44px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_5"},[]],
["div","",{"style":[["position","absolute"],["left","88px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_6"},[]],
["div","",{"style":[["position","absolute"],["left","132px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_7"},[]],
]],
["div","",{"style":[["position","absolute"],["left","100px"],["top","88px"],["width","100%"],["height","44px"]]},[
["div","",{"style":[["position","absolute"],["left","0px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_8"},[]],
["div","",{"style":[["position","absolute"],["left","44px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_9"},[]],
["div","",{"style":[["position","absolute"],["left","88px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_10"},[]],
["div","",{"style":[["position","absolute"],["left","132px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_11"},[]],
]],
["div","",{"style":[["position","absolute"],["left","100px"],["top","132px"],["width","100%"],["height","44px"]]},[
["div","",{"style":[["position","absolute"],["left","0px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_12"},[]],
["div","",{"style":[["position","absolute"],["left","44px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_13"},[]],
["div","",{"style":[["position","absolute"],["left","88px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_14"},[]],
["div","",{"style":[["position","absolute"],["left","132px"]],"className":"slot validSlot silverScriptsSlot implant","id":"implant_15"},[]],
]],
]],
["div","",{"style":[["position","absolute"],["bottom","20px"],["width","100%"]]},[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},loadoutOpenEditMenu,[]],
["button","Equip",{"style":[["position","absolute"],["right","30px"]]},equipCurrentLoadout,[]],
]]
],
"style":
[
["height","450px"],
["width","375px"],
["top","0px"],
["left","125px"]
]
},
"loadoutsListReset": {
"data":
[
["div","",[],[
["button","Reset Quickswap:",{"style":[["position","absolute"],["left","30px"]]},resetLoadoutButton,[0]],
["span","1",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Reset Quickswap:",{"style":[["position","absolute"],["left","30px"]]},resetLoadoutButton,[1]],
["span","2",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Reset Quickswap:",{"style":[["position","absolute"],["left","30px"]]},resetLoadoutButton,[2]],
["span","3",{"style":[["position","absolute"],["right","30px"]]}]
]],
["div","",[],[
["button","Reset Quickswap:",{"style":[["position","absolute"],["left","30px"]]},resetLoadoutButton,[3]],
["span","4",{"style":[["position","absolute"],["right","30px"]]}]
]],
["p","",[]],
["div","",[],[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["loadoutsMenu"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","130px"],
["width","300px"]
]
},
"updateAvailable": {
"data":
[
["span","A new update for <span style='color: #ff0000;'>SilverScripts</span> is available. Please update the script through <span style='color: #ff0000;'>TamperMonkey's</span> interface.",{"style":[["position","absolute"],["left","20px"],["right","20px"],["top","10px"]]}],
["p","",[]],
["button","Go to install page",{"style":[["position","absolute"],["left","30px"],["bottom","90px"]]},openScriptGMPage,[]],
["button","Show changelog",{"style":[["position","absolute"],["left","30px"],["bottom","70px"]]},openHelpWindowPage,["changelog"]],
["button","Remind me later",{"style":[["position","absolute"],["left","30px"],["bottom","50px"]]},closeHelpWindowPage,[]],
["button","Stop reminding me",{"style":[["position","absolute"],["left","30px"],["bottom","30px"]]},stopUpdateReminderForCurVer,[]],
],
"style":
[
["height","230px"],
["width","300px"]
]
},
"changelog": {
"data":
[
["span","Changelog text here",{}],
["div","",{},[
["button","Back",{"style":[["position","absolute"],["left","30px"]]},openHelpWindowPage,["updateAvailable"]],
["button","Close",{"style":[["position","absolute"],["right","30px"]]},closeHelpWindowPage,[]]
]]
],
"style":
[
["height","160px"]
]
},
}
//////////////////////////
// Utility Functions //
/////////////////////////
function getItemsDataBank(){
return itemsDataBank;
}
unsafeWindow.getSilverItemsDataBank = getItemsDataBank;
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function lowerFirstLetter(string) {
return string.charAt(0).toLowerCase() + string.slice(1);
}
function flipSetting(settingName,settingIndex){
var oldValue = userSettings[settingName];
if(oldValue == true){
userSettings[settingName] = false;
helpWindowStructure["settings"]["data"][settingIndex][1] = "Enable "+capitalizeFirstLetter(settingName);
}else{
userSettings[settingName] = true;
helpWindowStructure["settings"]["data"][settingIndex][1] = "Disable "+capitalizeFirstLetter(settingName);
}
GM.setValue("userSettings",JSON.stringify(userSettings));
//Trick to refresh the menu
openHelpWindowPage("settings");
}
function refreshMarketSearch(){
var itemDisplay = document.getElementById("itemDisplay");
itemDisplay.scrollTop = 0;
itemDisplay.scrollLeft = 0;
unsafeWindow.search();
}
function serializeObject(obj) {
var pairs = [];
for (var prop in obj) {
if (!obj.hasOwnProperty(prop)) {
continue;
}
pairs.push(prop + '=' + obj[prop]);
}
return pairs.join('&');
}
function makeRequest(requestUrl,requestParams,callbackFunc,callBackParams){
requestParams["pagetime"] = userVars["pagetime"];
requestParams["templateID"] = "0";
requestParams["sc"] = userVars["sc"];
requestParams["gv"] = 42;
requestParams["userID"] = userVars["userID"];
requestParams["password"] = userVars["password"];
return new Promise((resolve) => {
var xhttp = new XMLHttpRequest();
var payload = null;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//Invoke the callback with the request response text and some parameters, if any were supplied
//then resolve the Promise with the callback's reponse
let callbackResponse = null;
if(callbackFunc != null){
callbackResponse = callbackFunc(this.responseText,callBackParams);
}
if(callbackResponse == null){
callbackResponse = true;
}
resolve(callbackResponse);
}
};
payload = serializeObject(requestParams);
xhttp.open("POST", requestUrl, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("x-requested-with", "SilverScriptRequest");
payload = "hash=" + unsafeWindow.hash(payload) + "&" + payload;
xhttp.send(payload);
});
}
function cloneObject(object){
return JSON.parse(JSON.stringify(object));
}
function getImplantRestrictions(itemFlashType){
//Fetch info on the target implant
var restrictions = {
"forbiddenImplants":[],
"isUnique": false
};
if(globalData[itemFlashType]["implant_block"]){
restrictions["forbiddenImplants"] = globalData[itemFlashType]["implant_block"].split(',');
}
if(globalData[itemFlashType]["implant_unique"] && globalData[itemFlashType]["implant_unique"]=="1"){
restrictions["isUnique"] = true;
}
return restrictions;
}
function secondsToHms(d) {
d = parseInt(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
var hDisplay = h < 10 ? "0"+h : h;
var mDisplay = m < 10 ? "0"+m : m;
var sDisplay = s < 10 ? "0"+s : s;
return hDisplay + ":" + mDisplay + ":" + sDisplay;
}
function isAtLocation(location){
//Make an exception check for the homepage as its address is contained in each one
if(location == "home"){
if(window.location.href.split("fairview.deadfrontier.com/onlinezombiemmo/index.php")[1] == "" ||
window.location.href.split("fairview.deadfrontier.com/onlinezombiemmo/")[1] == "" ){
return true;
}else{
return false;
}
}
//Check if location name exists first
if(locations[location] != undefined){
for(var i=0;i<locations[location].length;i++){
if(window.location.href.indexOf(locations[location][i]) != -1){
return true;
}
}
}
return false;
}
async function checkForScriptUpdate(){
if(isAtLocation("ICInventory") || isAtLocation("forum")){
return;
}
updateCheck = JSON.parse(await GM.getValue("updateCheck",JSON.stringify(updateCheck)));
var lastCheckDate = new Date(updateCheck["lastCheck"]);
var daysElapsedSinceLastCheck = Math.ceil((Date.now() - lastCheckDate) / (1000 * 60 * 60 * 24));
if(daysElapsedSinceLastCheck <= 1){
return;
}
//TODO: Update to 2.x.x version of the lib
var GF = new GreasyFork;
var code = await GF.get().script().code(383308);
uploadedVersion = GF.parseScriptCodeMeta(code).filter(e => e.meta === '@version')[0].value;
var localVersion = GM.info.script.version;
//Check if local version is lesser than uploaded version
var needsUpdate = uploadedVersion.localeCompare(localVersion, undefined, { numeric: true, sensitivity: 'base' }) == 1;
//Check if the user has asked to skip or remind later, and that a day has elapsed
var isVersionAfterSkip = uploadedVersion.localeCompare(updateCheck["skipVer"], undefined, { numeric: true, sensitivity: 'base' }) == 1;
if(needsUpdate && isVersionAfterSkip){
//Save the new version changelog into its menu page
var history = await GF.get().script().history(383308);
helpWindowStructure["changelog"]["data"][0][1] = history[0]["changelog"]["html"].trim();
//Adjust menu height depending on changelog length. Simulate its height when open.
helpWindow.style.position = "absolute";
helpWindow.style.left = "208px";
helpWindow.style.top = "195px";
helpWindow.style.width = "270px";
helpWindow.style.height = "100px";
helpWindow.style.opacity = "0";
helpWindow.parentNode.style.display = "block";
helpWindow.innerHTML = "<span id='testSpan'>"+helpWindowStructure["changelog"]["data"][0][1]+"</span>";
var helpWindowHeight = document.getElementById("testSpan").offsetHeight;
helpWindowStructure["changelog"]["style"][0][1] = (65 + helpWindowHeight) + "px";
helpWindow.style.opacity = "1";
closeHelpWindowPage();
openHelpWindowPage("updateAvailable");
}
//Save current date, we already checked for the day
updateCheck["lastCheck"] = Date.now();
GM.setValue("updateCheck",JSON.stringify(updateCheck));
}
function openScriptGMPage(){
var GF = new GreasyFork;
GF.action('install', {
id: 383308,
});
}
function stopUpdateReminderForCurVer(){
//Save the uploaded version as the version to ignore when performing an update check
updateCheck["skipVer"] = uploadedVersion;
GM.setValue("updateCheck",JSON.stringify(updateCheck));
closeHelpWindowPage();
}
function updateInventoryData(inventoryData){
unsafeWindow.updateIntoArr(unsafeWindow.flshToArr(inventoryData, "DFSTATS_"), unsafeWindow.userVars);
unsafeWindow.populateInventory();
unsafeWindow.populateCharacterInventory();
unsafeWindow.updateAllFields();
initInventoryArray();
}
function getLevelAppropriateMedicalTypeList(){
var playerLevel = userVars["DFSTATS_df_level"];
//Chain IFs instead of using Switch bacause that is the ugly but recommended way
if(playerLevel < 11){return ["steristrips","plasters"]}
if(playerLevel >= 11 && playerLevel < 21){return ["antisepticspray","antibiotics"]}
if(playerLevel >= 21 && playerLevel < 31){return ["bandages"]}
if(playerLevel >= 31 && playerLevel < 41){return ["morphine"]}
if(playerLevel >= 41 && playerLevel < 71){return ["nerotonin"]}
if(playerLevel >= 71){return ["nerotonin8b","steroids"]}
return [];
}
function getBestLevelAppropriateMedicalTypeAndAdministerNeed(){
var damagePercentage = (userVars["DFSTATS_df_hpmax"]/userVars["DFSTATS_df_hpcurrent"]) * 100;
var medList = getLevelAppropriateMedicalTypeList();
var chosenMed = "";
var needAdminister = true;
var medType, medItem;
//Use the fact that the array is already sorted
for(medType of medList){
medItem = globalData[medType];
medItem["healthrestore"] = parseInt(medItem["healthrestore"]);
medItem["adminhealthrestore"] = medItem["healthrestore"] * 3;
//Swap to cheaper med if it still lets the player reach max health
if(chosenMed != ""){
if(medItem["adminhealthrestore"] >= damagePercentage){
chosenMed = medType;
}else{
break;
}
}else{
chosenMed = medType;
}
}
//Check the array again to see if we can skip administer. This is ugly but should work.
for(medType of medList){
medItem = cloneObject(globalData[medType]);
//Swap to cheaper med if it still lets the player reach max health
if(medItem["healthrestore"] >= damagePercentage){
chosenMed = medType;
needAdminister = false;
}else{
break;
}
}
return [chosenMed,needAdminister];
}
unsafeWindow.getBestLevelAppropriateMedicalTypeAndAdministerNeed = getBestLevelAppropriateMedicalTypeAndAdministerNeed;
function getLevelAppropriateFoodTypeList(){
var playerLevel = userVars["DFSTATS_df_level"];
//Chain IFs instead of using Switch bacause that is the ugly but recommended way
//All list are already sorted in descending foodrestore values
if(playerLevel < 11){return ["millet_cooked","beer"]}
if(playerLevel >= 11 && playerLevel < 21){return ["hotdogs_cooked","bakedbeans_cooked"]}
if(playerLevel >= 21 && playerLevel < 31){return ["potatoes_cooked","tuna_cooked"]}
if(playerLevel >= 31 && playerLevel < 41){return ["eggs_cooked","salmon_cooked","oats_cooked"]}
if(playerLevel >= 41 && playerLevel < 71){return ["caviar_cooked","mixednuts_cooked","redwine"]}
if(playerLevel >= 71){return ["driedtruffles_cooked","whiskey"]}
return [];
}
function getBestLevelAppropriateFoodType(){
var hunger = 100 - userVars['DFSTATS_df_hungerhp'];
var foodList = getLevelAppropriateFoodTypeList();
var chosenFood = "";
//Use the fact that the array is already sorted
for(var foodType of foodList){
//Fix cooked items restore levels
var [id, extraInfo] = foodType.split("_");
var foodItem = globalData[id];
if(extraInfo != undefined){
foodItem["actual_foodrestore"] = parseInt(foodItem["foodrestore"]) * 3;
}else{
foodItem["actual_foodrestore"] = parseInt(foodItem["foodrestore"]);
}
//Swap to cheaper food if it still lets the player reach max nourishment
if(chosenFood != ""){
if(foodItem["actual_foodrestore"] >= hunger){
chosenFood = foodType;
}else{
break;
}
}else{
chosenFood = foodType;
}
}
return chosenFood;
}
function findLastEmptyGenericSlot(slotType)
{
for(var i = userVars["DFSTATS_df_" + slotType + "slots"]; i >= 1; i--)
{
if(userVars["DFSTATS_df_" + slotType + i + "_type"] === "")
{
return i;
}
}
return false;
}
function addPendingRequest(){
pendingRequests.requestsNeeded += 1;
pendingRequests.requesting = true;
}
function completePendingRequest(){
pendingRequests.requestsCompleted += 1;
if(pendingRequests.requestsCompleted >= pendingRequests.requestsNeeded){
resetPendingRequests();
}
}
function resetPendingRequests(){
pendingRequests.requestsNeeded = 0;
pendingRequests.requestsCompleted = 0;
pendingRequests.requesting = false;
}
function havePendingRequestsCompleted(){
return !pendingRequests.requesting;
}
//////////////////////
// Init Functions //
/////////////////////
function initUserData(){
if(isAtLocation("forum") || unsafeWindow.userVars == undefined){
return;
}
if(isAtLocation("ICInventory")){
userData["tradezone"] = '4';
}else{
userData["tradezone"] = userVars["DFSTATS_df_tradezone"];
}
lastActiveUserID = unsafeWindow.userVars['userID'];
GM.setValue("lastActiveUserID",lastActiveUserID);
}
function addItemToDatabank(flashType,quantity){
//Init a new inventory item
var item = {};
item.id = flashType;
item.extraInfo = "";
item.type = "";
item.flashType = flashType;
item.trades = [];
//Check if slot isn't empty
if(item.id != "" && item.id != undefined){
//Detect extra data such as cooked/dye color
if(item.id.indexOf("_") != -1){
item.extraInfo = capitalizeFirstLetter(item.id.split("_")[1]);
item.id = item.id.split("_")[0];
}
var itemGlobData = globalData[item.id];
//Set shared data across all item types
item.name = itemGlobData.name;
item.quantity = quantity;
item.quantity = item.quantity < 1? 1:item.quantity;
item.type = capitalizeFirstLetter(itemGlobData.itemcat);
item.notTransferable = itemGlobData.no_transfer == 1;
if(item.type == "Armour"){
//Quantity is current armor HP
item.maxHP = parseInt(itemGlobData.hp); //Max armor hp
item.level = itemGlobData.shop_level;
item.profession = "Engineer";
item.serviceAction = "buyrepair";
item.serviceSound = "repair";
item.serviceTooltip = "Repair";
item.scrapValue = unsafeWindow.scrapValue(item.flashType,1);
}
if(item.type == "Weapon"){
item.scrapValue = unsafeWindow.scrapValue(item.flashType,1);
}
if(item.type == "Item"){
//Add level to the item if it has one
if(itemGlobData.level != undefined){
item.level = itemGlobData.level;
}
//Add scrap value if this is a cosmetic
if(itemGlobData.clothingtype != undefined){
item.scrapValue = unsafeWindow.scrapValue(item.flashType,1);
}
//Find if the item has a profession associated and/or is cookable and add it
//to the databank for a market request
if(itemGlobData.needcook == "1" && item.extraInfo != "Cooked"){
item.type = "Cookable";
item.profession = "Chef";
item.serviceAction = "buycook";
item.serviceSound = "cook";
item.serviceTooltip = "Cook";
//Add Cooked item info to the Databank
//If this is the first time this item has been found in the inventory,
//register its Cooked info into the itemsDataBank
if(itemsDataBank[item.id+"_cooked"] == null){
var cookedItem = {};
cookedItem.id = item.id+"_cooked";
cookedItem.extraInfo = "Cooked";
cookedItem.name = "Cooked "+item.name;
cookedItem.quantity = 1;
cookedItem.type = "Item";
itemsDataBank[cookedItem.id] = cookedItem;
}
}else if(itemGlobData.needdoctor == "1"){
item.type = "Medical";
item.profession = "Doctor";
item.serviceAction = "buyadminister";
item.serviceSound = "heal";
item.serviceTooltip = "Administer";
}
}
//Fix for cooked items detection
if(item.extraInfo == "Cooked"){
item.id = item.id + "_cooked";
item.name = "Cooked " + item.name;
}
//Add profession level required to service the item.
//If item isn't serviceable this is ignored.
if(item.level != undefined){
item.professionLevel = item.level - 5;
}
//If this is the first time this item has been found in the inventory,
//register its info into the itemsDataBank
if(itemsDataBank[item.id] == null){
itemsDataBank[item.id] = item;
}
}else{
item.name = "";
item.quantity = 0;
}
return item
}
function initInventoryArray(){
if(!isAtLocation("inventories")){
return;
}
//Reset inventory array
inventoryArray = [];
//Refresh databank and inventory contents
for(var i=1;i<=parseInt(userVars.DFSTATS_df_invslots);i++){
var item = addItemToDatabank(userVars["DFSTATS_df_inv" + i + "_type"],
parseInt(userVars["DFSTATS_df_inv" + i + "_quantity"]));
inventoryArray.push(item);
}
}
async function loadStoredSettings(){
//We stringify the default object as fallback
userSettings = JSON.parse(await GM.getValue("userSettings",JSON.stringify(userSettings)));
console.log(userSettings)
if(userSettings.hoverPrices == false){
helpWindowStructure["settings"]["data"][0][1] = "Enable HoverPrices";
}
if(userSettings.autoService == false){
helpWindowStructure["settings"]["data"][1][1] = "Enable AutoService";
}
if(userSettings.autoMarketWithdraw == false){
helpWindowStructure["settings"]["data"][2][1] = "Enable AutoMarketWithdraw";
}
if(userSettings.alwaysDisplayQuickSwitcher == true){
helpWindowStructure["settings"]["data"][3][1] = "Disable AlwaysDisplayQuickSwitcher";
}
}
async function initLoadouts(){
for(var i=0;i<4;i++){
resetLoadout(i);
}
//Load stored loadouts
loadouts = JSON.parse(await GM.getValue("loadouts",JSON.stringify(loadouts)));
loadoutRefreshUsedSlotOverlay();
}
async function loadSavedMarketData(){
savedMarketData = JSON.parse(await GM.getValue("savedMarketData",JSON.stringify(savedMarketData)));
if(savedMarketData["previousItemTimestamp"] == undefined){
savedMarketData["previousItemTimestamp"] = {};
}
itemsDataBank = savedMarketData["itemsDataBank"];
servicesDataBank = savedMarketData["servicesDataBank"];
}
async function loadStoredCharacterCookieData(){
//Load stored cookie data
characterCookieData = JSON.parse(await GM.getValue("characterCookieData",JSON.stringify(characterCookieData)));
//Fix character cookie if loading from previous versions
for(let userID in characterCookieData){
if(characterCookieData[userID]['userID'] == undefined){
characterCookieData[userID]['userID'] = userID;
}
}
//Stop here if outside the home page due to the fact that userVars may not be available
if(!isAtLocation("home")){
return;
}
//Update current character cookie
let characterName = "";
if(characterCookieData[unsafeWindow.userVars['userID']] != undefined){
characterName = characterCookieData[unsafeWindow.userVars['userID']].characterName;
}else{
characterName = document.getElementById("sidebar").children[2].firstChild.textContent;
}
characterCookieData[unsafeWindow.userVars['userID']] = {"characterName":characterName,"cookie":document.cookie,
"userID":unsafeWindow.userVars['userID']};
//Save updated cookie data
GM.setValue("characterCookieData",JSON.stringify(characterCookieData));
}
function removeCharacterFromCharacterCookieData(userID){
if(characterCookieData[userID] != undefined){
delete characterCookieData[userID];
//Save updated cookie data
GM.setValue("characterCookieData",JSON.stringify(characterCookieData));
}
}
function changeCharacterCookieDataName(userID){
if(characterCookieData[userID] != undefined){
let newCharName = window.prompt("Input the new name for the saved character");
characterCookieData[userID]["characterName"] = newCharName.slice(0,16);
//Save updated cookie data
GM.setValue("characterCookieData",JSON.stringify(characterCookieData));
}
}
async function loadLastActiveUserID(){
lastActiveUserID = await GM.getValue("lastActiveUserID",null);
}
//////////////////////////////
// Item Price Functions //
/////////////////////////////
function resetDataBankItemsMarketInfo(){
if(isAtLocation("forum")){
return;
}
for(var itemName in itemsDataBank){
itemsDataBank[itemName].rawServerResponse = "";
}
}
function addAllAmmoToDatabank(){
if(!isAtLocation("inventories")){
return;
}
//This array was extracted from the game data using the following one-liner:
//Object.keys(Object.fromEntries(Object.entries(globalData).filter(([key, value]) => value.itemcat === 'ammo')));
var ammoTypes = ['32ammo', '35ammo', '357ammo', '38ammo', '40ammo', '45ammo', '50ammo', '55ammo', '20gaugeammo',
'16gaugeammo', '12gaugeammo', '10gaugeammo', 'grenadeammo', 'heavygrenadeammo', '55rifleammo',
'75rifleammo', '9rifleammo', '127rifleammo', '14rifleammo', '20rifleammo', 'fuelammo'];
for(let ammoId of ammoTypes){
addItemToDatabank(ammoId,1);
}
}
function addLevelAppropriateMedicalToDatabank(){
if(!isAtLocation("marketplace")){
return;
}
//Add medical to databank
var [medicalId,needsAdminister] = getBestLevelAppropriateMedicalTypeAndAdministerNeed();
addItemToDatabank(medicalId,1);
//Fetch the medical's price if the player is damaged
if(parseInt(userVars["DFSTATS_df_hpcurrent"]) < parseInt(userVars["DFSTATS_df_hpmax"])){
requestItem(itemsDataBank[medicalId]);
}
}
function addLevelAppropriateFoodToDatabank(){
if(!isAtLocation("marketplace")){
return;
}
//Add food to databank
var foodId = getBestLevelAppropriateFoodType();
addItemToDatabank(foodId,1);
//Fetch the food's price if the player is hungry
if(parseInt(userVars['DFSTATS_df_hungerhp']) < 100){
requestItem(itemsDataBank[foodId]);
}