This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
SG Game Tags v3.5 WIP (dont install this).user.js
1265 lines (1163 loc) · 45.4 KB
/
SG Game Tags v3.5 WIP (dont install this).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 SG Game Tags
// @namespace https://steamcommunity.com/id/Ruphine/
// @version 3.5
// @description some tags of the game in Steamgifts.
// @author Ruphine
// @match *://www.steamgifts.com/*
// @icon https://cdn.steamgifts.com/img/favicon.ico
// @connect steampowered.com
// @connect ruphine.esy.es
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.min.js
// @grant GM_deleteValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
/*jshint multistr: true */
/* Constant Variables */
const linkGameAPI = "http://store.steampowered.com/api/appdetails?appids=";//filters=categories,platforms,genres&
const linkPackAPI = "http://store.steampowered.com/api/packagedetails?packageids=";
const linkBundleAPI = "http://www.ruphine.esy.es/steamgifts/bundlelist.php?v=2"; //v1 = {"appid":"38900", "type":"app"} v2 = {"appid":"A38900"}
const linkUserAPI = "http://store.steampowered.com/dynamicstore/userdata/";
//p for properties
const pBundle = {
class : "tags_bundle",
text : "Bundled",
text2 : "Not-Bundled",
title : "Bundled since ",
min : "B",
min2 : "NB",
link : "https://www.steamgifts.com/bundle-games/search?q=",
color1 : "#E9202A",
color2 : "#FFFFFF"
};
const pCard = {
class : "tags_card",
text : "Trading Cards",
title : "This game has trading cards",
min : "T",
link : "http://www.steamcardexchange.net/index.php?inventorygame-appid-",
color1 : "#3AA435",
color2 : "#FFFFFF"
};
const pAchievement = {
class : "tags_achievement",
text : "Achievements",
title : "This game has steam achievements",
min : "A",
link : "http://steamcommunity.com/stats/", // 424280/achievements/";
color1 : "#305AC9",
color2 : "#FFFFFF"
};
const pWishlist = {
class : "tags_wishlist",
text : "Wishlist",
title : "This game is in your Steam wishlist",
min : "W",
link : "https://www.steamgifts.com/account/steam/wishlist/search?q=",
color1 : "#9335F1",
color2 : "#FFFFFF"
};
const pLinux = {
class : "tags_linux",
text : "Linux",
title : "Linux supported",
min : "L",
color1 : "#E67300",
color2 : "#FFFFFF"
};
const pMac = {
class : "tags_mac",
text : "Mac",
title : "Mac Supported",
min : "M",
color1 : "#777777",
color2 : "#FFFFFF"
};
const pEarly = {
class : "tags_early",
text : "Early Access",
title : "This game is in early access state",
min : "E",
color1 : "#9FA027",
color2 : "#FFFFFF"
};
const pHidden = {
class : "tags_hidden",
text : "Hidden",
title : "This game is in your filter list",
min : "H",
link : "https://www.steamgifts.com/account/settings/giveaways/filters/search?q=",
color1 : "#A0522D",
color2 : "#FFFFFF"
};
const pOwned = {
class : "tags_owned",
text : "Owned",
title : "You already have this game",
min : "O",
color1 : "#444444",
color2 : "#FF9900"
};
const pIgnored = {
class : "tags_ignored",
text : "Ignored",
title : "You marked this game as not interested",
min : "X",
color1 : "#E06666",
color2 : "#FFFFFF"
};
/* CSS */
const myCSS = '\
.tags { \
text-decoration: none; \
border-radius: 4px; \
padding: 2px 5px; \
font-size: 8pt; \
margin: 3px 3px 3px 0px; \
text-shadow: none; \
display: none; \
white-space: nowrap; \
} \
.tags.minimalist { \
margin-right: 0; \
margin-left: 5px; \
} \
.' + pBundle.class + ' { \
background-color: ' + GM_getValue("bundle-1", pBundle.color1) + '; \
color: ' + GM_getValue("bundle-2", pBundle.color2) + '; \
} \
.' + pCard.class + ' { \
background-color: ' + GM_getValue("card-1", pCard.color1) + '; \
color: ' + GM_getValue("card-2", pCard.color2) + '; \
} \
.' + pAchievement.class + ' { \
background-color: ' + GM_getValue("achievement-1", pAchievement.color1) + '; \
color: ' + GM_getValue("achievement-2", pAchievement.color2) + '; \
} \
.' + pWishlist.class + ' { \
background-color: ' + GM_getValue("wishlist-1", pWishlist.color1) + '; \
color: ' + GM_getValue("wishlist-2", pWishlist.color2) + '; \
} \
.' + pLinux.class + ' { \
background-color: ' + GM_getValue("linux-1", pLinux.color1) + '; \
color: ' + GM_getValue("linux-2", pLinux.color2) + '; \
} \
.' + pMac.class + ' { \
background-color: ' + GM_getValue("mac-1", pMac.color1) + '; \
color: ' + GM_getValue("mac-2", pMac.color2) + '; \
} \
.' + pEarly.class + ' { \
background-color: ' + GM_getValue("early-1", pEarly.color1) + '; \
color: ' + GM_getValue("early-2", pEarly.color2) + '; \
} \
.' + pHidden.class + ' { \
background-color: ' + GM_getValue("hidden-1", pHidden.color1) + '; \
color: ' + GM_getValue("hidden-2", pHidden.color2) + '; \
} \
.' + pOwned.class + ' { \
background-color: ' + GM_getValue("owned-1", pOwned.color1) + '; \
color: ' + GM_getValue("owned-2", pOwned.color2) + '; \
} \
.' + pIgnored.class + ' { \
background-color: ' + GM_getValue("ignored-1", pIgnored.color1) + '; \
color: ' + GM_getValue("ignored-2", pIgnored.color2) + '; \
} \
';
$("head").append('<style type="text/css">' + myCSS + '</style>');
const THIS_URL = window.location.href;
const TIMEOUT = 0;
const CACHE_TIME = 6*60*60*1000; //6 hours
var cbCards = GM_getValue("cbCards", true);
var cbAchievement = GM_getValue("cbAchievement", true);
var cbBundled = GM_getValue("cbBundled", true);
var cbWishlist = GM_getValue("cbWishlist", true);
var cbLinux = GM_getValue("cbLinux", false);
var cbMac = GM_getValue("cbMac", false);
var cbEarly = GM_getValue("cbEarly", false);
var cbHidden = GM_getValue("cbHidden", true);
var cbOwned = GM_getValue("cbOwned", true);
var cbIgnored = GM_getValue("cbIgnored", false);
var cbTagStyle = GM_getValue("cbTagStyle", 1); //1 = full, 2 = minimalist
var BundledGames = GM_getValue("BundledGames", "");
var BundledCache = GM_getValue("BundledCache", 0);
var UserdataAPI = GM_getValue("UserdataAPI", "");
var UserdataCache = GM_getValue("UserdataCache", 0);
var GameData = GM_getValue("GameData", "");
var PackageData = GM_getValue("PackageData", "");
var rgWishlist, rgOwnedApps, rgOwnedPackages, rgIgnoredApps, rgIgnoredPackages;
var arrBundled;
if(cbBundled && BundledCache < Date.now() - CACHE_TIME) // Check if need to request bundle list from ruphine API
getBundleList();
else if((cbWishlist || cbOwned || cbIgnored) && UserdataCache < Date.now() - CACHE_TIME) //6 hours. Check if need to request steam user api
getUserdata();
else
main();
function main()
{
try {
arrBundled = JSON.parse(BundledGames);
}
catch (e) {
console.log("[SG Game Tags] Invalid json format for Bundle List");
BundledGames = ""; GM_setValue("BundledGames", "");
BundledCache = 0; GM_setValue("BundledCache", 0);
}
try {
var userdata = JSON.parse(UserdataAPI);
rgWishlist = userdata.rgWishlist;
rgOwnedApps = userdata.rgOwnedApps;
rgOwnedPackages = userdata.rgOwnedPackages;
rgIgnoredApps = userdata.rgIgnoredApps;
rgIgnoredPackages = userdata.rgIgnoredPackages;
}
catch (e) {
console.log("[SG Game Tags] Invalid json format for UserdataAPI");
UserdataAPI = ""; GM_setValue("UserdataAPI", "");
UserdataCache = 0; GM_setValue("UserdataCache", 0);
}
if(GameData === "")
PrepareJSON();
else
{
GameData = JSON.parse(GameData);
PackageData = JSON.parse(PackageData);
}
var observer;
var config = {childList: true, attributes: false, characterData: false, subtree: true};
if(/www.steamgifts.com\/giveaways\/new/.test(THIS_URL)) // process giveaway creation page
InitGiveawayCreationPage();
else if(/www.steamgifts.com\/account\/*/.test(THIS_URL))
{
var sidebar_item = '<li class="sidebar__navigation__item">\
<a class="sidebar__navigation__item__link" href="/sg-game-tags">\
<div class="sidebar__navigation__item__name">SG Game Tags</div>\
<div class="sidebar__navigation__item__underline"></div>\
</a>\
</li>';
$($(".sidebar__navigation")[2]).append(sidebar_item);
}
else if(/www.steamgifts.com\/sg-game-tags/.test(THIS_URL)) // process sg game tags setting page
initSetting();
else if(/www.steamgifts.com\/($|giveaways$|giveaways\/search)/.test(THIS_URL)) // homepage and all search active giveaway
{
ProcessGiveawayListPage($(".widget-container"));
// handles element added later by endless scroll, add timeout to delay this function because it is triggered when ext SG runs
observer = new MutationObserver(function(mutations)
{
$.each(mutations, function(index, mutation){
ProcessGiveawayListPage(mutation.addedNodes);
});
});
$(".widget-container>div").each(function(index, element){
observer.observe(element, config);
});
if($(".featured__inner-wrap .global__image-outer-wrap--missing-image").length === 0 && $(".featured__inner-wrap a img").length > 0)
ProcessFeaturedGiveaway($(".featured__inner-wrap a img")[0].src);
}
// user profile & group page excluding user trade and feedback and excluding group users, stats, and wishlist
else if(/www.steamgifts.com\/(user|group)\//.test(THIS_URL) && !/user\/\w+\/(feedback|trade)/.test(THIS_URL) && !/group\/\w+\/\w+\/(users|stats|wishlist)/.test(THIS_URL)) // exclude some pages
{
ProcessGiveawayListPage($(".widget-container"));
// handles element added later by endless scroll, add timeout to delay this function because it is triggered when ext SG runs
observer = new MutationObserver(function(mutations)
{
$.each(mutations, function(index, mutation){
ProcessGiveawayListPage(mutation.addedNodes);
});
});
$(".widget-container>div").each(function(index, element){
observer.observe(element, config);
});
if($(".featured__inner-wrap .global__image-outer-wrap--missing-image").length === 0 && $(".featured__inner-wrap a img").length > 0)
ProcessFeaturedGiveaway($(".featured__inner-wrap a img")[0].src);
}
else if(/www.steamgifts.com\/giveaway\//.test(THIS_URL)) // giveaway page https://www.steamgifts.com/giveaway/FGbTw/left-4-dead-2
ProcessFeaturedGiveaway($(".featured__inner-wrap a")[0].href);
// https://www.steamgifts.com/sales*
// https://www.steamgifts.com/sales/account/steam/games
// https://www.steamgifts.com/sales/account/steam/wishlist
// https://www.steamgifts.com/giveaways/created
// https://www.steamgifts.com/giveaways/entered
// https://www.steamgifts.com/giveaways/won
// https://www.steamgifts.com/giveaways/wishlist
// https://www.steamgifts.com/account/settings/giveaways/filters
else if(/www.steamgifts.com\/(sales|account\/steam\/(games|wishlist)|giveaways\/(created|entered|won|wishlist)|account\/settings\/giveaways\/filters|group\/\w+\/\w+\/wishlist)/.test(THIS_URL))
{
ProcessGameListPage($(".widget-container"));
observer = new MutationObserver(function(mutations)
{
$.each(mutations, function(index, mutation){
ProcessGameListPage(mutation.addedNodes);
});
});
$(".widget-container>div").each(function(index, element){
observer.observe(element, config);
});
}
AddShortcutToSettingPage();
}
function ProcessFeaturedGiveaway(URL)
{
if(cbBundled || cbCards || cbAchievement || cbHidden || cbWishlist || cbLinux || cbMac || cbEarly) // check if at least one tag enabled
{
var Name = $(".featured__heading__medium").text().substring(0,45); //letter after 45th converted to ...
var $Target = $(".featured__heading");
ProcessTags($Target, URL, Name);
}
}
function ProcessGiveawayListPage(parent) // giveaways list with creator name
{
if(cbBundled || cbCards || cbAchievement || cbHidden || cbWishlist || cbLinux || cbMac || cbEarly) // check if at least one tag enabled
{
$(parent).find(".giveaway__row-inner-wrap").each(function(index, element)
{
var URL = $(element).find(".giveaway__heading>a.giveaway__icon").attr("href");
if(URL !== undefined)
{
var Name = $(element).find(".giveaway__heading__name").contents().filter(
function() //return text without [NEW] and [FREE]
{
return this.nodeType === 3; //Node.TEXT_NODE
}
).slice(-1)[0].textContent.substring(0,40); //letter after 40th converted to ...
var $Target = $(element).find(".giveaway__heading");
ProcessTags($Target, URL, Name);
}
});
}
}
function ProcessGameListPage(parent) // giveaways / games list
{
if(cbBundled || cbCards || cbAchievement || cbHidden || cbWishlist || cbLinux || cbMac || cbEarly) // check if at least one tag enabled
{
$(parent).find(".table__row-inner-wrap").each(function(index, element)
{
var URL;
if(/www.steamgifts.com\/account\/settings\/giveaways\/filters/.test(THIS_URL))
URL = $(element).find("a.table__column__secondary-link").text();
else
URL = $($(element).find(".global__image-inner-wrap")[0]).css('background-image');
if(URL !== undefined)
{
URL = URL.replace('url(', '').replace(')', '');
var Name = $(element).find(".table__column__heading").text().substring(0,30);
var $Target = $(element).find(".table__column--width-fill > :first-child");
if(/www.steamgifts.com\/sales/.test(THIS_URL))
$Target.css("display", "block"); //because sales pages don't use <p> thus tags will appears in line with title
ProcessTags($Target, URL, Name);
}
});
}
}
function ProcessTags($Target, URL, Name)
{
var ID = getAppIDfromLink(URL);
Name = encodeURIComponent(Name); //encode special characters that may break search params
var linkStore = "";
if(isApp(URL))
linkStore = "http://store.steampowered.com/app/" + ID;
else if(isPackage(URL))
linkStore = "http://store.steampowered.com/sub/" + ID;
var $tagBundle, $tagCard, $tagAchievement, $tagWishlist, $tagLinux, $tagMac, $tagEarly, $tagHidden, $tagOwned, $tagIgnored, $tagOther;
if(cbTagStyle == 1)
{
if(cbBundled == 1)
$tagBundle = createTag(pBundle.class, pBundle.title, pBundle.text, pBundle.link+Name, $Target);
else
$tagBundle = createTag(pBundle.class, "", pBundle.text2, pBundle.link+Name, $Target);
$tagCard = createTag(pCard.class, pCard.title, pCard.text, pCard.link+ID, $tagBundle);
$tagAchievement = createTag(pAchievement.class, pAchievement.title, pAchievement.text, pAchievement.link+ID+"/achievements/", $tagCard);
$tagWishlist = createTag(pWishlist.class, pWishlist.title, pWishlist.text, pWishlist.link+Name, $tagAchievement);
$tagLinux = createTag(pLinux.class, pLinux.title, pLinux.text, linkStore, $tagWishlist);
$tagMac = createTag(pMac.class, pMac.title, pMac.text, linkStore, $tagLinux);
$tagEarly = createTag(pEarly.class, pEarly.title, pEarly.text, linkStore, $tagMac);
$tagOwned = createTag(pOwned.class, pOwned.title, pOwned.text, linkStore, $tagEarly);
$tagIgnored = createTag(pIgnored.class, pIgnored.title, pIgnored.text, linkStore, $tagOwned);
}
else
{
if(cbBundled == 1)
$tagBundle = createTag(pBundle.class + " minimalist", pBundle.title, pBundle.min, pBundle.link+Name, $Target);
else
$tagBundle = createTag(pBundle.class + " minimalist", "", pBundle.min2, pBundle.link+Name, $Target);
$tagCard = createTag(pCard.class + " minimalist", pCard.title, pCard.min, pCard.link+ID, $Target);
$tagAchievement = createTag(pAchievement.class + " minimalist", pAchievement.title, pAchievement.min, pAchievement.link+ID+"/achievements/", $Target);
$tagWishlist = createTag(pWishlist.class + " minimalist", pWishlist.title, pWishlist.min, pWishlist.link+Name, $Target);
$tagLinux = createTag(pLinux.class + " minimalist", pLinux.title, pLinux.min, linkStore, $Target);
$tagMac = createTag(pMac.class + " minimalist", pMac.title, pMac.min, linkStore, $Target);
$tagEarly = createTag(pEarly.class + " minimalist", pEarly.title, pEarly.min, linkStore, $Target);
$tagOwned = createTag(pOwned.class + " minimalist", pOwned.title, pOwned.min, linkStore, $Target);
$tagIgnored = createTag(pIgnored.class + " minimalist", pIgnored.title, pIgnored.min, linkStore, $Target);
}
if(/www.steamgifts.com\/giveaway\//.test(THIS_URL)) //only trigger inside giveaway page, no need for homepage
{
if(cbTagStyle == 1)
$tagHidden = createTag(pHidden.class, pHidden.title, pHidden.text, pHidden.link+Name, $tagIgnored);
else if(cbTagStyle == 2)
$tagHidden = createTag(pHidden.class + " minimalist", pHidden.title, pHidden.min, pHidden.link+Name, $Target);
getHiddenStatus(ID, Name, $tagHidden);
}
if(isApp(URL))
getSteamCategories(ID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly);
else if(isPackage(URL))
{
$tagCard.attr("href", "");
$tagAchievement.attr("href", "");
getSteamCategoriesFromPackage(ID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly);
}
var type = isApp(URL) ? 'app' : 'sub';
if(cbBundled && BundledGames !== "")
getBundleStatus(ID, type, $tagBundle);
if(UserdataAPI !== "")
{
if(cbWishlist)
getWishlistStatus(ID, $tagWishlist);
if(cbOwned)
getOwnedStatus(ID, $tagOwned, (type == 'app'));
if(cbIgnored)
getIgnoredStatus(ID, $tagIgnored, (type == 'app'));
}
}
function createTag(_class, title, text, href, $divTarget)
{
var $tag = $('<a target="_blank" class="tags ' + _class +'" title="' + title + '" href="' + href + '">' + text + '</a>');
if(cbTagStyle == 1 || /www.steamgifts.com\/giveaways\/new/.test(THIS_URL)) // full text below game title, use after, or bundle tag in giveaway creation page
$divTarget.after($tag);
else if(cbTagStyle == 2) // minimalist beside game title use append
$divTarget.append($tag);
return $tag;
}
function getSteamCategories(appID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly, packID = "0")
{
var needRequest = false;
if(GameData[appID] === undefined)
{
var template = {"cards": false, "achievement": false, "mac": false, "linux": false, "early_access": false, "last_checked": 0, "game": appID+""};
GameData[appID] = template;
needRequest = true;
}
else
{
var data = GameData[appID];
if(cbCards && data.cards)
{
$tagCard.css("display", "inline-block");
$tagCard.css("display", "inline-block");
$tagCard.attr("href", pCard.link+GameData[appID].game);
}
if(cbAchievement && data.achievement)
{
$tagAchievement.css("display", "inline-block");
$tagAchievement.attr("href", pAchievement.link+GameData[appID].game+"/achievements/");
}
if(cbMac && data.mac)
$tagMac.css("display", "inline-block");
if(cbLinux && data.linux)
$tagLinux.css("display", "inline-block");
if(data.last_checked < (Date.now() - (24 * 60 * 60 * 1000))) // 24 hours have passed since last checked
{
if((!data.cards && cbCards) || (!data.achievement && cbAchievement) || (!data.mac && cbMac ) || (!data.linux && cbLinux) || (data.early_access && cbEarly))
needRequest = true;
}
else if(data.early_access && cbEarly)
$tagEarly.css("display", "inline-block");
}
if(needRequest)
{
var link = linkGameAPI+appID;
if(GameData[appID].last_checked !== 0 || (packID != "0" && PackageData[packID].last_checked !== 0)) //if not first time checked, filter out the request
link += "&filters=categories,platforms,genres";
// console.log("[SG Game Tags] requesting " + link);
GM_xmlhttpRequest({
method: "GET",
timeout: 10000,
url: link,
onload: function(data)
{
var obj = JSON.parse(data.responseText)[appID].data;
if(obj !== undefined) // undefined = doesn't have store page or doesn't exist
// get steam apps categories : achievement, trading cards, etc
{
if (obj.type !== undefined && obj.type != "game") //if it is DLC, obj will have different fullgame.appid
{
GameData[appID].game = obj.fullgame.appid;
//set tagcard and tagachievement href to the main game appid
$tagCard.attr("href", pCard.link+obj.fullgame.appid);
$tagAchievement.attr("href", pAchievement.link+obj.fullgame.appid+"/achievements/");
}
else if(packID != "0" && PackageData[packID].games.indexOf(appID) == -1)
PackageData[packID].games.push(appID);
var categories = obj.categories;
if(categories !== undefined)
{
var catCards = $.grep(categories, function(e){ return e.id == "29"; });
if(catCards.length > 0)
{
if(cbCards) $tagCard.css("display", "inline-block");
GameData[appID].cards = true;
if(packID != "0")
{
PackageData[packID].cards = true;
if(PackageData[packID].games.length > 1)
$tagCard.attr("href", "http://ruphine.esy.es/steamgifts/tradingcard.php?packageid="+packID);
else
$tagCard.attr("href", pCard.link+PackageData[packID].games[0]);
}
}
var catAchievement = $.grep(categories, function(e){ return e.id == "22"; });
if(catAchievement.length > 0)
{
GameData[appID].achievement = true;
if(cbAchievement)
$tagAchievement.css("display", "inline-block");
if(packID != "0")
{
PackageData[packID].achievement = true;
if(PackageData[packID].games.length > 1)
$tagAchievement.attr("href", "http://ruphine.esy.es/steamgifts/achievement.php?packageid="+packID);
else
$tagAchievement.attr("href", pAchievement.link+PackageData[packID].games[0]+"/achievements/");
}
}
}
// get steam apps platforms: linux: boolean, mac: boolean
var platforms = obj.platforms;
if(platforms.linux)
{
GameData[appID].linux = true;
if(cbLinux)
$tagLinux.css("display", "inline-block");
if(packID != "0")
PackageData[packID].linux = true;
}
if(platforms.mac)
{
GameData[appID].mac = true;
if(cbMac)
$tagMac.css("display", "inline-block");
if(packID != "0")
PackageData[packID].mac = true;
}
// get steam apps genres
if(obj.genres !== undefined)
{
var genEarly = $.grep(obj.genres, function(e){ return e.id == "70"; });
if(genEarly.length > 0)
{
GameData[appID].early_access = true;
if(cbEarly)
$tagEarly.css("display", "inline-block");
if(packID != "0")
PackageData[packID].early_access = true;
}
else
{
GameData[appID].early_access = false;
if(packID != "0")
PackageData[packID].early_access = false;
}
}
}
GameData[appID].last_checked = Date.now();
GM_setValue("GameData", JSON.stringify(GameData));
if(packID != "0")
{
PackageData[packID].last_checked = Date.now();
GM_setValue("PackageData", JSON.stringify(PackageData));
}
},
ontimeout: function(data)
{
console.log("[SG Game Tags] Request " + linkGameAPI+appID + " Timeout");
}
});
}
}
function getBundleStatus(appID, type, $tag)
{
var Game = $.grep(arrBundled, function(e){ return (e.AppID == appID && e.Type == type); });
if(Game.length > 0 && cbBundled == 1) //game found in bundle list
{
$tag.css("display", "inline-block");
$tag.attr("title", pBundle.title+Game[0].BundledDate);
}
else if(Game.length == 0 && cbBundled == 2)
$tag.css("display", "inline-block");
}
function getBundleList()
{
// console.log("[SG Game Tags] requesting " + linkBundleAPI);
GM_xmlhttpRequest({
method: "GET",
timeout: 10000,
url: linkBundleAPI,
onload: function(data)
{
BundledGames = data.responseText;
GM_setValue("BundledGames", BundledGames);
BundledCache = Date.now();
GM_setValue("BundledCache", BundledCache);
if((cbWishlist || cbOwned || cbIgnored) && UserdataCache < Date.now() - CACHE_TIME)
getUserdata();
else
main();
},
ontimeout: function(data)
{
console.log("[SG Game Tags] Request " + linkBundleAPI + " Timeout");
if((cbWishlist || cbOwned || cbIgnored) && UserdataCache < Date.now() - CACHE_TIME)
getUserdata();
else
main();
}
});
}
function getUserdata()
{
// console.log("[SG Game Tags] requesting " + linkUserAPI);
GM_xmlhttpRequest({
method: "GET",
timeout: 10000,
url: linkUserAPI,
onload: function(data)
{
var result = JSON.parse(data.responseText);
if(result.rgOwnedApps.length !== 0) //check if user logged in
{
UserdataAPI = data.responseText;
GM_setValue("UserdataAPI", UserdataAPI);
UserdataCache = Date.now();
GM_setValue("UserdataCache", UserdataCache);
}
else
console.log("[SG Game Tags] Unable to get user's steam data. User is not logged in to steam.");
main();
},
ontimeout: function(data)
{
console.log("[SG Game Tags] Request " + linkUserAPI + " Timeout");
main();
}
});
}
function getHiddenStatus(appID, appName, $elems)
{
if(cbHidden)
{
// console.log("[SG Game Tags] requesting " + pHidden.link+appName);
$.get(pHidden.link+appName, function(data)
{
var gamesfound = $(data).find("a.table__column__secondary-link");
for(i=0; i<$(gamesfound).length; i++)
{
var url = $(gamesfound)[i].href;
var ID = getAppIDfromLink(url);
if(appID == ID)
{
//TODO : Save appID + true ke local cache
$elems.css("display", "inline-block");
return true; //exit function
}
}
});
}
}
function getWishlistStatus(appID, $elems)
{
appID = parseInt(appID);
if(rgWishlist.indexOf(appID) >= 0)
$elems.css("display", "inline-block");
}
function getOwnedStatus(appID, $elems, isApp)
{
appID = parseInt(appID);
if(isApp && rgOwnedApps.indexOf(appID) >= 0)
$elems.css("display", "inline-block");
else if(!isApp && rgOwnedPackages.indexOf(appID) >= 0)
$elems.css("display", "inline-block");
}
function getIgnoredStatus(appID, $elems, isApp)
{
appID = parseInt(appID);
if(isApp && rgIgnoredApps.indexOf(appID) >= 0)
$elems.css("display", "inline-block");
else if(!isApp && rgIgnoredPackages.indexOf(appID) >= 0)
$elems.css("display", "inline-block");
}
function getSteamCategoriesFromPackage(packID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly)
{
var needRequest = false;
if(PackageData[packID] === undefined || PackageData[packID].games === undefined)
{
var template = {"cards": false, "achievement": false, "mac": false, "linux": false, "early_access": false, "last_checked": 0, "games":[]};
PackageData[packID] = template;
needRequest = true;
}
else
{
var data = PackageData[packID];
if(cbCards && data.cards)
{
$tagCard.css("display", "inline-block");
if(data.games.length > 1)
{
$tagCard.attr("href", "http://ruphine.esy.es/steamgifts/tradingcard.php?packageid="+packID);
$tagCard.attr("title", "There is " + data.games.length + " games in this package, and at least one of them have trading cards");
}
else
$tagCard.attr("href", pCard.link+data.games[0]);
}
if(cbAchievement && data.achievement)
{
$tagAchievement.css("display", "inline-block");
if(data.games.length > 1)
{
$tagAchievement.attr("href", "http://ruphine.esy.es/steamgifts/achievement.php?packageid="+packID);
$tagAchievement.attr("title", "There is " + data.games.length + " games in this package, and at least one of them have achievements");
}
else
$tagAchievement.attr("href", pAchievement.link+data.games[0]+"/achievements/");
}
if(cbMac && data.mac)
$tagMac.css("display", "inline-block");
if(cbLinux && data.linux)
$tagLinux.css("display", "inline-block");
if(cbEarly && data.early_access)
$tagEarly.css("display", "inline-block");
if(data.last_checked < (Date.now() - (24 * 60 * 60 * 1000))) // 24 hours have passed since last checked
{
if((!data.cards && cbCards) || (!data.achievement && cbAchievement) || (!data.mac && cbMac ) || (!data.linux && cbLinux) || (data.early_access && cbEarly))
needRequest = true;
}
}
if(needRequest)
{
// console.log("[SG Game Tags] requesting " + linkPackAPI+packID);
GM_xmlhttpRequest({
method: "GET",
timeout: 10000,
url: linkPackAPI+packID,
onload: function(data)
{
var IDs = JSON.parse(data.responseText)[packID].data;
if(IDs === undefined)
{
PackageData[packID].cards = false;
PackageData[packID].achievement = false;
PackageData[packID].mac = false;
PackageData[packID].linux = false;
PackageData[packID].early_access = false;
PackageData[packID].games = [];
PackageData[packID].last_checked = Date.now();
GM_setValue("PackageData", JSON.stringify(PackageData));
}
else
{
IDs = IDs.apps;
$.each(IDs, function(index)
{
getSteamCategories(IDs[index].id, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly, packID);
});
}
},
ontimeout: function(data)
{
console.log("[SG Game Tags] Request " + linkPackAPI+packID + " Timeout");
}
});
}
}
function PrepareJSON()
{
var template = {"cards": false, "achievement": false, "mac": false, "linux": false, "early_access": false, "last_checked": 0};
var a = {"0":template};
var temp = JSON.stringify(a);
GameData = JSON.parse(temp);
PackageData = JSON.parse(temp);
GM_setValue("GameData", JSON.stringify(GameData));
GM_setValue("PackageData", JSON.stringify(PackageData));
}
function getAppIDfromLink(link){
var url = link.split("/");
return url[url.length-2];
}
function isApp(link){
return /\/app|apps\/0-9\//.test(link);
}
function isPackage(link){
return /\/sub|subs\/0-9\//.test(link);
}
// ========================================== create new giveaway page ========================================================
function InitGiveawayCreationPage()
{
if($(".js__autocomplete-data").length > 0)
{
var observer = new MutationObserver(function(mutations)
{
$(".tags").remove();
var $table = $(mutations[0].addedNodes).find(".table__row-inner-wrap");
$table.each(function(index, element)
{
var url = $(element).find("a.table__column__secondary-link").text();
var ID = getAppIDfromLink(url);
var Name = $(element).find(".table__column__heading").text();
var $Target = $(element).find(".table__column--width-fill");
var $tagBundle = createTag(pBundle.class, pBundle.title, pBundle.text, pBundle.link+Name, $Target);
$tagBundle.css("float", "right");
var type = isApp(url) ? 'app' : 'sub';
getBundleStatus(ID, type, $tagBundle);
});
$table.on("click", function(event)
{
var url = $(this).find("a.table__column__secondary-link").text();
var ID = getAppIDfromLink(url);
var Name = $(this).find(".table__column__heading").text();
var $Target = $(".js__autocomplete-name");
$tagBundle = createTag(pBundle.class, pBundle.title, pBundle.text, pBundle.link+Name, $Target);
var type = isApp(url) ? 'app' : 'sub';
getBundleStatus(ID, type, $tagBundle);
});
});
var config = {childList: true, attributes: false, characterData: false};
observer.observe($(".js__autocomplete-data")[0], config);
}
}
// ========================================== setting page ========================================================
function initSetting()
{
$("head").html('\
<meta charset="UTF-8">\
<link rel="shortcut icon" href="https://cdn.steamgifts.com/img/favicon.ico">\
<title>SG Game Tags Setting</title>\
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">\
<link rel="stylesheet" type="text/css" href="https://cdn.steamgifts.com/css/minified_v18.css">\
<script src="https://cdn.steamgifts.com/js/minified_v15.js"></script>\
<meta name="viewport" content="width=1200">\
<!-- SGGT Import -->\
<style type="text/css">\
.my__checkbox { cursor:pointer; padding:7px 0; } \
.my__checkbox i { margin-right:7px; } \
.my__checkbox:not(:last-of-type) { border-bottom:1px dotted #d2d6e0; } \
.my__checkbox:not(:hover) .form__checkbox__hover,.my__checkbox.is-selected .form__checkbox__hover,.my__checkbox:not(.is-selected) .form__checkbox__selected,.my__checkbox:hover .form__checkbox__default,.my__checkbox.is-selected .form__checkbox__default { \
display:none; \
} \
.row div { display: inline-block; } \
.preview-tags { width: 80px; margin-left: 10px; } \
.row .markdown {margin-left: 10px; cursor: pointer; }\
</style>\
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.min.css" />\
');
$("head").append('<style type="text/css">' + myCSS + '</style>');
$("body").html("");
GM_xmlhttpRequest({
method: "GET",
timeout: 10000,
url: "/account/settings/giveaways",
dataType: "html",
onload: function(data){
var $header = $(data.responseText).filter("header");
var $page_outer = $(data.responseText).filter(".page__outer-wrap");
var $footer_outer = $(data.responseText).filter(".footer__outer-wrap");
$page_outer.find("form").remove();
$page_outer.find(".sidebar__navigation .is-selected").removeClass("is-selected").find("a i").remove();
var $sidebar_item = $('<li class="sidebar__navigation__item is-selected">\
<a class="sidebar__navigation__item__link" href="/sg-game-tags">\
<i class="fa fa-caret-right"></i>\
<div class="sidebar__navigation__item__name">SG Game Tags</div>\
<div class="sidebar__navigation__item__underline"></div>\
</a>\
</li>');
$($page_outer.find(".sidebar__navigation")[2]).append($sidebar_item);
$("body").append($header).append($page_outer).append($footer_outer);
$(".page__heading").after($('<div class="form__rows"></div>'));
$(".page__heading__breadcrumbs").html('<a href="/sg-game-tags">SG Game Tags Setting</a>');
initTagPositionSetting();
initTagOnOffSetting();
initTagColorSetting();
changeCBColor();
AddShortcutToSettingPage();
},
ontimeout: function()
{
console.log("timeout");
}
});
}
function initTagPositionSetting()
{
var no = $(".form__heading").length + 1;
var CheckIcon = '<i class="form__checkbox__default fa fa-circle-o"></i><i class="form__checkbox__hover fa fa-circle"></i><i class="form__checkbox__selected fa fa-check-circle"></i>';
var $form__row = $('<div class="form__row"></div>');
var $form__heading = $('<div class="form__heading"></div>');
$form__heading
.append('<div class="form__heading__number">' + no + '.</div>')
.append('<div class="form__heading__text" title="This setting doesn\'t affect performance, only visual change."> Tags Style </div>');
var $form__row__indent = $('<div class="form__row__indent"></div>');
var $form__checkbox_1 = createCheckBox("form__checkbox", CheckIcon + "(Original) Full Text tags below game title", cbTagStyle == 1);
var $form__checkbox_2 = createCheckBox("form__checkbox", CheckIcon + "(Minimalist) One letter tags beside game title", cbTagStyle == 2);
$form__checkbox_1.attr("title", 'The tags will display "Trading Cards", "Bundled", etc. This option will increase page height.');
$form__checkbox_2.attr("title", 'The tags will just display first letter. "Trading Cards" becomes "T", "Bundled" becomes "B", etc.');
$form__checkbox_1.click(function()
{
cbTagStyle = 1;
GM_setValue("cbTagStyle", 1);
toggleMinimalist(false);
$form__checkbox_2.removeClass("is-selected");
$form__checkbox_1.addClass("is-selected");
});
$form__checkbox_2.click(function()
{
cbTagStyle = 2;
GM_setValue("cbTagStyle", 2);
toggleMinimalist();
$form__checkbox_1.removeClass("is-selected");
$form__checkbox_2.addClass("is-selected");
});
$form__row__indent.append($form__checkbox_1).append($form__checkbox_2);
$form__row.append($form__heading).append($form__row__indent);
$(".form__rows").append($form__row);
}