forked from jshackles/Enhanced_Steam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enhancedsteam.js
7034 lines (6267 loc) · 319 KB
/
enhancedsteam.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
var version = "7.3"
var console_info=["%c Enhanced %cSteam v"+version+" by jshackles %c http://www.enhancedsteam.com ","background: #000000;color: #7EBE45", "background: #000000;color: #ffffff",""];
console.log.apply(console,console_info);
var storage = chrome.storage.sync;
var info = 0;
var total_requests = 0;
var processed_requests = 0;
var cookie = document.cookie;
if (cookie.match(/steam_language=([a-z]{3})/i)) {
var language = cookie.match(/steam_language=([a-z]{3})/i)[1];
} else {
var language = "eng";
}
if (localized_strings[language] === undefined) { language = "eng"; }
// Set language for options page
chrome.storage.sync.set({'language': language});
// Check if the user is signed in
var is_signed_in = false;
var signed_in_promise = (function () {
var deferred = new $.Deferred();
if (window.location.protocol != "https:") {
if ($("#global_actions").find(".playerAvatar").length > 0) {
var user_name = $("#global_actions").find(".playerAvatar")[0].outerHTML.match(/\/id\/(.+?)"/);
if (user_name) {
if (getValue("steamID")) {
is_signed_in = getValue("steamID");
deferred.resolve();
} else {
get_http("http://steamcommunity.com/id/" + user_name[1], function(txt) {
is_signed_in = txt.match(/steamid"\:"(.+)","personaname/)[1];
setValue("steamID", is_signed_in);
deferred.resolve();
});
}
} else {
deferred.resolve();
}
} else {
deferred.resolve();
}
} else {
deferred.resolve();
}
return deferred.promise();
})();
// Global scope promise storage; to prevent unecessary API requests
var loading_inventory;
var library_all_games = [];
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
// Run script in the context of the current tab
function runInPageContext(fun){
var script = document.createElement('script');
script.textContent = '(' + fun + ')();';
document.documentElement.appendChild(script);
script.parentNode.removeChild(script);
}
// Chrome storage functions
function setValue(key, value) {
localStorage.setItem(key, JSON.stringify(value));
}
function getValue(key) {
var v = localStorage.getItem(key);
if (v === undefined) return v;
return JSON.parse(v);
}
function delValue(key) {
localStorage.removeItem(key);
}
// Helper prototypes
String.prototype.startsWith = function(prefix) {
return this.indexOf(prefix) === 0;
};
String.prototype.contains = function(it) {
return this.indexOf(it) != -1;
};
var currency_format_info = {
"BRL": { places: 2, hidePlacesWhenZero: false, symbolFormat: "R$ ", thousand: ".", decimal: ",", right: false },
"EUR": { places: 2, hidePlacesWhenZero: false, symbolFormat: "€", thousand: " ", decimal: ",", right: true },
"GBP": { places: 2, hidePlacesWhenZero: false, symbolFormat: "£", thousand: ",", decimal: ".", right: false },
"RUB": { places: 2, hidePlacesWhenZero: true, symbolFormat: " pуб.", thousand: "", decimal: ",", right: true },
"JPY": { places: 0, hidePlacesWhenZero: false, symbolFormat: "¥ ", thousand: ",", decimal: ".", right: false },
"MYR": { places: 2, hidePlacesWhenZero: false, symbolFormat: "RM", thousand: ",", decimal: ".", right: false },
"NOK": { places: 2, hidePlacesWhenZero: false, symbolFormat: " kr", thousand: ".", decimal: ",", right: true },
"IDR": { places: 0, hidePlacesWhenZero: false, symbolFormat: "Rp ", thousand: " ", decimal: ".", right: false },
"PHP": { places: 2, hidePlacesWhenZero: false, symbolFormat: "P", thousand: ",", decimal: ".", right: false },
"SGD": { places: 2, hidePlacesWhenZero: false, symbolFormat: "S$", thousand: ",", decimal: ".", right: false },
"THB": { places: 2, hidePlacesWhenZero: false, symbolFormat: "฿", thousand: ",", decimal: ".", right: false },
"VND": { places: 2, hidePlacesWhenZero: false, symbolFormat: "₫", thousand: ",", decimal: ".", right: false },
"KRW": { places: 2, hidePlacesWhenZero: false, symbolFormat: "₩", thousand: ",", decimal: ".", right: false },
"TRY": { places: 2, hidePlacesWhenZero: false, symbolFormat: " TL", thousand: "", decimal: ",", right: true },
"UAH": { places: 2, hidePlacesWhenZero: false, symbolFormat: "₴", thousand: "", decimal: ",", right: true },
"MXN": { places: 2, hidePlacesWhenZero: false, symbolFormat: "Mex$ ", thousand: ",", decimal: ".", right: false },
"CAD": { places: 2, hidePlacesWhenZero: false, symbolFormat: "CDN$ ", thousand: ",", decimal: ".", right: false },
"AUD": { places: 2, hidePlacesWhenZero: false, symbolFormat: "A$ ", thousand: ",", decimal: ".", right: false },
"NZD": { places: 2, hidePlacesWhenZero: false, symbolFormat: "NZ$ ", thousand: ",", decimal: ".", right: false },
"USD": { places: 2, hidePlacesWhenZero: false, symbolFormat: "$", thousand: ",", decimal: ".", right: false }
};
function formatCurrency(number, type) {
var info = currency_format_info[type];
if (info.hidePlacesWhenZero && (number % 1 === 0)) {
info.places = 0;
}
var negative = number < 0 ? "-" : "",
i = parseInt(number = Math.abs(+number || 0).toFixed(info.places), 10) + "",
j = (j = i.length) > 3 ? j % 3 : 0,
formatted;
formatted = negative +
(j ? i.substr(0, j) + info.thousand : "") +
i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + info.thousand) +
(info.places ? info.decimal + Math.abs(number - i).toFixed(info.places).slice(2) : "");
if (info.right)
formatted += info.symbolFormat;
else
formatted = info.symbolFormat + formatted;
return formatted;
}
function parse_currency(str) {
var currency_symbol = currency_symbol_from_string(str);
var currency_type = currency_symbol_to_type(currency_symbol);
var currency_number = currency_symbol_to_number(currency_symbol);
var info = currency_format_info[currency_type];
// remove thousand sep, replace decimal with dot, remove non-numeric
str = str.replace(info.thousand, '')
.replace(info.decimal, '.')
.replace(/[^\d\.]/g, '')
.trim();
var value = parseFloat(str);
if (isNaN(value))
return null;
return {
value: value,
currency_type: currency_type,
currency_symbol: currency_symbol,
currency_number: currency_number
};
}
function currency_symbol_to_type (currency_symbol) {
switch (currency_symbol) {
case "pуб":
return "RUB";
case "€":
return "EUR";
case "£":
return "GBP";
case "R$":
return "BRL";
case "¥":
return "JPY";
case "kr":
return "NOK";
case "Rp":
return "IDR";
case "RM":
return "MYR";
case "P":
return "PHP";
case "S$":
return "SGD";
case "฿":
return "THB";
case "₫":
return "VND";
case "₩":
return "KRW";
case "TL":
return "TRY";
case "₴":
return "UAH";
case "Mex$":
return "MXN";
case "CDN$":
return "CAD";
case "A$":
return "AUD";
case "NZ$":
return "NZD";
default:
return "USD";
}
}
function currency_symbol_to_number (currency_symbol) {
switch (currency_symbol) {
case "pуб":
return 5;
case "€":
return 3;
case "£":
return 2;
case "R$":
return 7;
case "¥":
return 8;
case "kr":
return 9;
case "Rp":
return 10;
case "RM":
return 11;
case "P":
return 12;
case "S$":
return 13;
case "฿":
return 14;
case "₫":
return 15;
case "₩":
return 16;
case "TL":
return 17;
case "₴":
return 18;
case "Mex$":
return 19;
case "CDN$":
return 20;
case "A$":
return 21;
case "NZ$":
return 22;
default:
return 1;
}
}
function currency_symbol_from_string (string_with_symbol) {
var re = /(?:R\$|S\$|\$|RM|kr|Rp|€|¥|£|฿|pуб|P|₫|₩|TL|₴|Mex\$|CDN\$|A\$|NZ\$)/;
var match = string_with_symbol.match(re);
return match ? match[0] : '';
}
function escapeHTML(str) {
return str.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') ;
}
function getCookie(name) {
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}
function matchAll(re, str) {
var p, r = [];
while(p = re.exec(str))
r.push(p[1]);
return r;
}
function get_http(url, callback) {
total_requests += 1;
$("#es_progress").attr({"max": 100, "title": localized_strings[language].ready.loading});
$("#es_progress").removeClass("complete");
var http = new XMLHttpRequest();
http.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
processed_requests += 1;
var complete_percentage = (processed_requests / total_requests) * 100;
$("#es_progress").val(complete_percentage);
if (complete_percentage == 100) { $("#es_progress").addClass("complete").attr("title", localized_strings[language].ready.ready); }
callback(this.responseText);
}
if (this.readyState == 4 && this.status != 200) {
$("#es_progress").val(100).addClass("error").attr({"title":localized_strings[language].ready.errormsg, "max":1});
}
};
http.open('GET', url, true);
http.send(null);
}
function get_appid(t) {
if (t && t.match(/(?:store\.steampowered|steamcommunity)\.com\/app\/(\d+)\/?/)) return RegExp.$1;
else return null;
}
function get_appids(t) {
var res = matchAll(/(?:store\.steampowered|steamcommunity)\.com\/app\/(\d+)\/?/g, t);
return (res.length > 0) ? res : null;
}
function get_subid(t) {
if (t && t.match(/(?:store\.steampowered|steamcommunity)\.com\/sub\/(\d+)\/?/)) return RegExp.$1;
else return null;
}
function get_appid_wishlist(t) {
if (t && t.match(/game_(\d+)/)) return RegExp.$1;
else return null;
}
// Color the tile for owned games
function highlight_owned(node) {
storage.get(function(settings) {
node.classList.add("es_highlight_owned");
if (settings.highlight_owned_color === undefined) { settings.highlight_owned_color = "#5c7836"; storage.set({'highlight_owned_color': settings.highlight_owned_color}); }
if (settings.highlight_owned === undefined) { settings.highlight_owned = false; storage.set({'highlight_owned': settings.highlight_owned}); }
if (settings.hide_owned === undefined) { settings.hide_owned = false; chrome.storage.sync.set({'hide_owned': settings.hide_owned}); }
if (settings.highlight_owned) highlight_node(node, settings.highlight_owned_color);
if (settings.hide_owned) hide_node(node);
if (settings.tag_owned === undefined) { settings.tag_owned = false; storage.set({'tag_owned': settings.tag_owned}); }
if (settings.tag_owned_color === undefined) { settings.tag_owned_color = "#5c7836"; storage.set({'tag_owned_color': settings.tag_owned_color}); }
if (settings.tag_owned) add_tag(node, localized_strings[language].tag.owned, settings.tag_owned_color);
});
}
// Color the tile for wishlist games
function highlight_wishlist(node) {
storage.get(function(settings) {
node.classList.add("es_highlight_wishlist");
if (settings.highlight_wishlist_color === undefined) { settings.highlight_wishlist_color = "#d3deea"; storage.set({'highlight_wishlist_color': settings.highlight_wishlist_color}); }
if (settings.highlight_wishlist === undefined) { settings.highlight_wishlist = false; storage.set({'highlight_wishlist': settings.highlight_wishlist}); }
if (settings.hide_wishlist === undefined) { settings.hide_wishlist = false; chrome.storage.sync.set({'hide_wishlist': settings.hide_wishlist}); }
if (settings.highlight_wishlist) highlight_node(node, settings.highlight_wishlist_color);
if (settings.hide_wishlist) hide_node(node);
if (settings.tag_wishlist_color === undefined) { settings.tag_wishlist_color = "#d3deea"; storage.set({'tag_wishlist_color': settings.tag_wishlist_color}); }
if (settings.tag_wishlist === undefined) { settings.tag_wishlist = false; storage.set({'tag_wishlist': settings.tag_wishlist}); }
if (settings.tag_wishlist) add_tag(node, localized_strings[language].tag.wishlist, settings.highlight_wishlist_color);
});
}
function highlight_cart(node) {
storage.get(function(settings) {
node.classList.add("es_highlight_cart");
if (settings.hide_cart === undefined) { settings.hide_cart = false; chrome.storage.sync.set({'hide_cart': settings.hide_cart}); }
if (settings.hide_cart) hide_node(node);
});
}
// Color the tile for items with coupons
function highlight_coupon(node, discount) {
storage.get(function(settings) {
node.classList.add("es_highlight_coupon");
if (settings.highlight_coupon_color === undefined) { settings.highlight_coupon_color = "#6b2269"; storage.set({'highlight_coupon_color': settings.highlight_coupon_color}); }
if (settings.highlight_coupon === undefined) { settings.highlight_coupon = false; storage.set({'highlight_coupon': settings.highlight_coupon}); }
if (settings.highlight_coupon) highlight_node(node, settings.highlight_coupon_color);
if (settings.tag_coupon_color === undefined) { settings.tag_coupon_color = "#6b2269"; storage.set({'tag_coupon_color': settings.tag_coupon_color}); }
if (settings.tag_coupon === undefined) { settings.tag_coupon = false; storage.set({'tag_coupon': settings.tag_coupon}); }
if (settings.tag_coupon) add_tag(node, localized_strings[language].tag.coupon + " (" + discount + "%)", settings.highlight_coupon_color);
});
}
// Color the tile for items in inventory
function highlight_inv_gift(node) {
storage.get(function(settings) {
node.classList.add("es_highlight_inv_gift");
if (settings.highlight_inv_gift_color === undefined) { settings.highlight_inv_gift_color = "#a75124"; storage.set({'highlight_inv_gift_color': settings.highlight_inv_gift_color}); }
if (settings.highlight_inv_gift === undefined) { settings.highlight_inv_gift = false; storage.set({'highlight_inv_gift': settings.highlight_inv_gift}); }
if (settings.highlight_inv_gift) highlight_node(node, settings.highlight_inv_gift_color);
if (settings.tag_inv_gift_color === undefined) { settings.tag_inv_gift_color = "#a75124"; storage.set({'tag_inv_gift_color': settings.tag_inv_gift_color}); }
if (settings.tag_inv_gift === undefined) { settings.tag_inv_gift = false; storage.set({'tag_inv_gift': settings.tag_inv_gift}); }
if (settings.tag_inv_gift) add_tag(node, localized_strings[language].tag.inv_gift, settings.highlight_inv_gift_color);
});
}
// Color the tile for items in inventory
function highlight_inv_guestpass(node) {
storage.get(function(settings) {
node.classList.add("es_highlight_inv_guestpass");
if (settings.highlight_inv_guestpass_color === undefined) { settings.highlight_inv_guestpass_color = "#a75124"; storage.set({'highlight_inv_guestpass_color': settings.highlight_inv_guestpass_color}); }
if (settings.highlight_inv_guestpass === undefined) { settings.highlight_inv_guestpass = false; storage.set({'highlight_inv_guestpass': settings.highlight_inv_guestpass}); }
if (settings.highlight_inv_guestpass) highlight_node(node, settings.highlight_inv_guestpass_color);
if (settings.tag_inv_guestpass_color === undefined) { settings.tag_inv_guestpass_color = "#a75124"; storage.set({'tag_inv_guestpass_color': settings.tag_inv_guestpass_color}); }
if (settings.tag_inv_guestpass === undefined) { settings.tag_inv_guestpass = false; storage.set({'tag_inv_guestpass': settings.tag_inv_guestpass}); }
if (settings.tag_inv_guestpass) add_tag(node, localized_strings[language].tag.inv_guestpass, settings.highlight_inv_guestpass_color);
});
}
function highlight_nondiscounts(node) {
storage.get(function(settings) {
if (settings.hide_notdiscounted === undefined) { settings.hide_notdiscounted = false; chrome.storage.sync.set({'hide_notdiscounted': settings.hide_notdiscounted}); }
if (settings.hide_notdiscounted) {
$(node).css("display", "none");
}
});
}
function highlight_notinterested(node) {
var notinterested_promise = (function () {
var deferred = new $.Deferred();
if (is_signed_in && window.location.protocol != "https:") {
var expire_time = parseInt(Date.now() / 1000, 10) - 1 * 60 * 60; // One hour ago
var last_updated = getValue("dynamiclist_time") || expire_time - 1;
if (last_updated < expire_time) {
get_http("http://store.steampowered.com/dynamicstore/userdata/", function(txt) {
var data = JSON.parse(txt);
if (data["rgIgnoredApps"]) {
setValue("ignored_apps", data["rgIgnoredApps"].toString());
}
setValue("dynamiclist_time", parseInt(Date.now() / 1000, 10));
deferred.resolve();
});
} else {
deferred.resolve();
}
} else {
deferred.resolve();
}
return deferred.promise();
})();
$.when.apply($, [notinterested_promise]).done(function() {
storage.get(function(settings) {
if (settings.hide_notinterested === undefined) { settings.hide_notinterested = false; chrome.storage.sync.set({'hide_notinterested': settings.hide_notinterested}); }
var notinterested = getValue("ignored_apps").split(",");
if ($(node).hasClass("search_result_row")) {
var appid = get_appid(node.href);
if (settings.hide_notinterested && $.inArray(appid, notinterested) !== -1) {
$(node).css("display", "none");
}
}
});
});
}
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
function highlight_node(node, color) {
var $node = $(node);
storage.get(function(settings) {
if (settings.highlight_excludef2p === undefined) { settings.highlight_excludef2p = false; storage.set({'highlight_excludef2p': settings.highlight_excludef2p}); }
if (settings.highlight_excludef2p) {
if ($(node).html().match(/<div class="(tab_price|large_cap_price|col search_price|main_cap_price)">\n?(.+)?(Free to Play|Play for Free!)(.+)?<\/div>/i)) {
return;
}
if ($(node).html().match(/<h5>(Free to Play|Play for Free!)<\/h5>/i)) {
return;
}
if ($(node).html().match(/genre_release/)) {
if ($(node).find(".genre_release").html().match(/Free to Play/i)) {
return;
}
}
if (node.classList.contains("search_result_row")) {
if ($(node).html().match(/Free to Play/i)) {
return;
}
}
}
// Carousel item
if (node.classList.contains("cluster_capsule")) {
$node = $(node).find(".main_cap_content");
}
// Genre Carousel items
if (node.classList.contains("large_cap")) {
$node = $(node).find(".large_cap_content");
}
// App and community hub page headers
if (node.classList.contains("apphub_HeaderTop") || node.classList.contains("apphub_HeaderStandardTop")) {
$node = $(node).find(".apphub_AppName");
$node.css("color", color);
return;
}
// Blotter activity
if ($node.parent().parent()[0].classList.contains("blotter_daily_rollup_line") || $node.parent().parent()[0].classList.contains("blotter_author_block") || $node.parent().parent()[0].classList.contains("blotter_gamepurchase") || $node.parent().parent()[0].classList.contains("blotter_recommendation")) {
$node.css("color", color);
return;
}
var rgb = hexToRgb(color);
$node.css("backgroundImage", "none");
$node.css("background", "linear-gradient(135deg, rgba(0,0,0,1) 0%, rgba("+rgb.r+","+rgb.g+","+rgb.b+",0.8) 100%)");
$(node).find("img").css("opacity", "1");
$(node).find(".search_capsule").css("opacity", "1");
$(node).find(".ds_flag").remove();
// Set text colour to not conflict with highlight
if (node.classList.contains("tab_item")) $node.find("div").css("color", "lightgrey");
if (node.classList.contains("search_result_row")) $node.find(".search_name").css("color", "lightgrey");
});
}
function hide_node(node) {
storage.get(function(settings) {
if (settings.hide_owned === undefined) { settings.hide_owned = false; chrome.storage.sync.set({'hide_owned': settings.hide_owned}); }
if (settings.hide_dlcunownedgames === undefined) { settings.hide_dlcunownedgames = false; chrome.storage.sync.set({'hide_dlcunownedgames': settings.hide_dlcunownedgames}); }
if ($(node).hasClass("info") || $(node).hasClass("dailydeal") || $(node).hasClass("spotlight_content") || $(node).hasClass("browse_tag_game_cap")) { node = $(node).parent()[0]; }
if (settings.hide_owned) {
if (node.classList.contains("search_result_row") || node.classList.contains("item") || node.classList.contains("cluster_capsule") || node.classList.contains("browse_tag_game")) {
hide_the_node(node);
if ($(document).height() <= $(window).height()) {
load_search_results();
}
}
}
// Hide DLC for unowned items
if (settings.hide_dlcunownedgames) {
if (node.classList.contains("search_result_row") || node.classList.contains("game_area_dlc_row") || node.classList.contains("item") || node.classList.contains("cluster_capsule")) {
hide_the_node(node);
}
}
});
}
function hide_the_node(node) {
$(node).css("display", "none");
}
function add_tag (node, string, color) {
/* To add coloured tags to the end of app names instead of colour
highlighting; this allows an to be "highlighted" multiple times; e.g.
inventory and owned. */
node.tags = node.tags || [];
var tagItem = [string, color];
var already_tagged = false;
// Check if it isn't already tagged
for (var i = 0; i < node.tags.length; i++) {
if (node.tags[i][0] === tagItem[0]) already_tagged = true;
}
if (!already_tagged) {
node.tags.push(tagItem);
display_tags(node);
}
}
function display_tags(node) {
var remove_existing_tags = function remove_existing_tags(tag_root) {
if (tag_root.find(".tags").length > 0) {
tag_root.find(".tags").remove();
}
},
new_display_tag = function new_display_tag(text, color) {
var $tag = $("<span>" + tag[0] + "</span>");
$tag.css({
"backgroundColor": tag[1],
"color": "white",
"float": "right",
"padding": "2px",
"margin-right": "4px",
"margin-bottom": "4px",
"border": "1px solid #262627"
});
return $tag;
};
if (node.tags) {
// Make tags
$tags = $("<div class=\"tags\"></div>");
for (var i = 0; i < node.tags.length; i++) {
var tag = node.tags[i];
var $tag = new_display_tag(tag[0], tag[1]);
$tags.append($tag);
}
// Apply tags differently per type of node
var $tag_root;
if (node.classList.contains("tab_row")) {
$tag_root = $(node).find(".tab_desc").removeClass("with_discount");
remove_existing_tags($tag_root);
$(node).find(".tab_discount").css("top","15px");
$tag_root.find("h4").after($tags);
}
else if (node.classList.contains("search_result_row")) {
$tag_root = $(node).find(".search_name");
remove_existing_tags($tag_root);
$tags.css({
"display": "inline-block",
"vertical-align": "middle",
"font-size": "small"
});
$tag_root.find("p").prepend($tags);
// Remove margin-bottom, border, and tweak padding on carousel lists
$.each($tag_root.find(".tags span"), function (i, obj) {
$(obj).css({
"margin-bottom": "0",
"border": "0",
"padding": "3px"
});
});
}
else if (node.classList.contains("dailydeal")) {
$tag_root = $(node).parent();
remove_existing_tags($tag_root);
$tag_root.find(".game_purchase_action").before($tags);
$tag_root.find(".game_purchase_action").before($("<div style=\"clear: right;\"></div>"));
}
else if (node.classList.contains("small_cap")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
// small_cap will have extra height
$tags.css({
"display": "table",
"margin-top": "4px"
});
$tag_root.find("h4").before($tags);
}
else if (node.classList.contains("browse_tag_game")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
$tags.css("display", "table");
$tags.css("margin-left", "8px");
$tag_root.find(".browse_tag_game_price").after($tags);
}
else if (node.classList.contains("game_area_dlc_row")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
var clone = $(node).clone();
clone.css({
visibility:'hidden',
width : '',
height: '',
maxWidth : '',
maxHeight: ''
});
$('body').append(clone);
var width = $(clone).find(".game_area_dlc_price").width();
clone.remove();
$tags.css("margin-right", width + 3);
$tag_root.find(".game_area_dlc_name").before($tags);
// Remove margin-bottom on DLC lists to prevent horrible pyramidding
$.each($tag_root.find(".tags span"), function (i, obj) {
$(obj).css("margin-bottom", "0");
$(obj).css("padding", "0 2px");
});
}
else if (node.classList.contains("wishlistRow")) {
$tag_root = $(node).find(".wishlistRowItem");
remove_existing_tags($tag_root);
$tags.css("float", "left");
$tag_root.find(".bottom_controls").append($tags);
}
else if (node.classList.contains("match")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
$tags.css({
"float": "right",
"width": "130px",
"margin-top": "30px"
});
$tag_root.find(".match_price").after($tags);
}
else if (node.classList.contains("cluster_capsule")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
$tags.css({
"display": "inline-block",
"vertical-align": "middle",
"font-size": "small"
});
$tags.each(function() {
$(this).children().css("float", "none");
});
$tag_root.find(".main_cap_platform_area").append($tags);
// Remove margin-bottom, border, and tweak padding on carousel lists
$.each($tag_root.find(".tags span"), function (i, obj) {
$(obj).css({
"margin-bottom": "0",
"border": "0",
"padding": "3px"
});
});
}
else if (node.classList.contains("recommendation_highlight")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
if ($(".game_purchase_action").length > 0) {
$tags.css("float", "left");
$tag_root.find(".game_purchase_action").before($tags);
$tag_root.find(".game_purchase_action").before($("<div style=\"clear: right;\"></div>"));
} else {
$tags.css("float", "right");
$tag_root.find(".price").parent().before($tags);
}
}
else if (node.classList.contains("similar_grid_item")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
$tags.css("float", "right");
$tag_root.find(".similar_grid_price").find(".price").append($tags);
}
else if (node.classList.contains("recommendation_carousel_item")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
$tags.css("float", "left");
$tag_root.find(".buttons").before($tags);
}
else if (node.classList.contains("friendplaytime_game")) {
$tag_root = $(node);
remove_existing_tags($tag_root);
$tags.css("float", "left");
$tag_root.find(".friendplaytime_buttons").before($tags);
}
else if (node.classList.contains("inline_tags")) {
$tag_root = $(node);
remove_existing_tags($tag_root.parent());
$tags.css("display", "inline-block");
$tags.css("margin-left", "4px");
$tags.children().remove();
// Display inline as text only
$.each(node.tags, function (i, obj) {
var $obj = $("<span>" + obj[0] + "</span>");
// $obj.css("border-bottom", "2px solid " + obj[1]);
// $obj.css("background-color", obj[1]);
// $obj.css("color", "white");
if (i === 0) $tags.append(" (");
$tags.append($obj);
if (i === node.tags.length - 1) {
$tags.append(")");
}
else {
$tags.append(", ");
}
});
$tag_root.after($tags);
}
else if (node.classList.contains("apphub_HeaderStandardTop")) {
$tag_root = $(node);
// Height to accomodate tags
$tag_root.css("height", "auto");
remove_existing_tags($tag_root);
$tags.css({
"float": "left",
"margin-top": "4px",
"margin-left": "4px"
});
$tag_root.find(".apphub_AppName").after($tags);
$tag_root.find(".apphub_AppName").after($("<div style=\"clear: right;\"></div>"));
}
else if (node.classList.contains("apphub_HeaderTop")) {
$tag_root = $(node);
$tag_root.find(".apphub_AppName").css("width", "0px")
remove_existing_tags($tag_root);
$tags.css({
"float": "left",
"margin-top": "4px",
"margin-left": "4px"
});
$tag_root.find(".apphub_OtherSiteInfo").append($tags);
$tag_root.find(".apphub_AppName").after($("<div style=\"clear: right;\"></div>"));
var max_width = 948-($(".apphub_OtherSiteInfo").width() + 69);
$tag_root.find(".apphub_AppName").css("max-width", max_width+"px").attr("title", $tag_root.find(".apphub_AppName").text());
$tag_root.find(".apphub_AppName").css("width", "auto")
$tag_root.find(".apphub_AppName").css("overflow", "hidden");
}
}
}
function load_inventory() {
if (is_signed_in) {
if ($(".user_avatar").length > 0) { var profileurl = $(".user_avatar")[0].href || $(".user_avatar a")[0].href; }
var gift_deferred = new $.Deferred();
var coupon_deferred = new $.Deferred();
var card_deferred = new $.Deferred();
var handle_inv_ctx1 = function (txt) {
if (txt.charAt(0) != "<") {
localStorage.setItem("inventory_1", txt);
var data = JSON.parse(txt);
if (data.success) {
$.each(data.rgDescriptions, function(i, obj) {
var is_package = false;
var appids;
if (obj.descriptions) {
for (var d = 0; d < obj.descriptions.length; d++) {
if (obj.descriptions[d].type == "html") {
appids = get_appids(obj.descriptions[d].value);
if (appids) {
// Gift package with multiple apps
is_package = true;
for (var j = 0; j < appids.length; j++) {
if (appids[j]) setValue(appids[j] + (obj.type === "Gift" ? "gift" : "guestpass"), true);
}
break;
}
}
}
}
if (!is_package && obj.actions) {
// Single app
var appid = get_appid(obj.actions[0].link);
if (appid) setValue(appid + (obj.type === "Gift" ? "gift" : "guestpass"), true);
}
});
}
gift_deferred.resolve();
}
};
var handle_inv_ctx6 = function (txt) {
if (txt) {
if (txt.charAt(0) != "<") {
localStorage.setItem("inventory_6", txt);
var data = JSON.parse(txt);
if (data.success) {
$.each(data.rgDescriptions, function(i, obj) {
if (obj.market_hash_name) {
setValue("card:" + obj.market_hash_name, true);
}
});
}
card_deferred.resolve();
}
}
};
var handle_inv_ctx3 = function (txt) {
if (txt.charAt(0) != "<") {
localStorage.setItem("inventory_3", txt);
var data = JSON.parse(txt);
if (data.success) {
$.each(data.rgDescriptions, function(i, obj) {
var appid;
if (obj.type === "Coupon") {
if (obj.actions) {
var packageids = [];
for (var j = 0; j < obj.actions.length; j++) {
//obj.actions[j]
var link = obj.actions[j].link;
var packageid = /http:\/\/store.steampowered.com\/search\/\?list_of_subs=([0-9]+)/.exec(link)[1];
// If sub+packageid is in localStorage then we don't need to get this info reloaded.
// This sick optimization saves 268ms per page load! Woo!
if (!getValue("sub" + packageid)) packageids.push(packageid);
}
if (packageids.length > 0){
get_http("//store.steampowered.com/api/packagedetails/?packageids=" + packageids.join(","), function(txt) {
var package_data = JSON.parse(txt);
$.each(package_data, function(package_id, _package) {
if (_package.success) {
setValue("sub" + package_id, true);
$.each(_package.data.apps, function(i, app) {
if (getValue(app.id + "coupon")) {
if (getValue(app.id + "coupon_discount") >= obj.name.match(/([1-9][0-9])%/)[1]) { return; }
}
setValue(app.id + "coupon", true);
setValue(app.id + "coupon_sub", package_id);
setValue(app.id + "coupon_imageurl", obj.icon_url);
setValue(app.id + "coupon_title", obj.name);
setValue(app.id + "coupon_discount", obj.name.match(/([1-9][0-9])%/)[1]);
for (var i = 0; i < obj.descriptions.length; i++) {
if (obj.descriptions[i].value.startsWith("Can't be applied with other discounts.")) {
setValue(app.id + "coupon_discount_note", obj.descriptions[i].value);
setValue(app.id + "coupon_discount_doesnt_stack", true);
}
else if (obj.descriptions[i].value.startsWith("(Valid")) {
setValue(app.id + "coupon_valid", obj.descriptions[i].value);
}
};
});
}
});
coupon_deferred.resolve();
});
}
else {
coupon_deferred.resolve();
}
}
}
});
}
}
}
// Yes caching!
var expire_time = parseInt(Date.now() / 1000, 10) - 1 * 60 * 60; // One hour ago
var last_updated = localStorage.getItem("inventory_time") || expire_time - 1;
if (last_updated < expire_time || !localStorage.getItem("inventory_1") || !localStorage.getItem("inventory_3")) {
// purge stale information from localStorage
var i = 0, sKey;
for (; sKey = window.localStorage.key(i); i++) {
if (sKey.match(/coupon/)) { delValue(sKey); }
if (sKey.match(/card:/)) { delValue(sKey); }
if (sKey.match(/gift/)) { delValue(sKey); }
if (sKey.match(/guestpass/)) { delValue(sKey); }
}
localStorage.setItem("inventory_time", parseInt(Date.now() / 1000, 10))
// Context ID 1 is gifts and guest passes
get_http(profileurl + '/inventory/json/753/1/', handle_inv_ctx1);
// Context ID 3 is coupons
get_http(profileurl + '/inventory/json/753/3/', handle_inv_ctx3);
// Context ID 6 is trading card stuff
get_http(profileurl + '/inventory/json/753/6/', handle_inv_ctx6);
}
else {
// No need to load anything, its all in localStorage.
handle_inv_ctx1(localStorage.getItem("inventory_1"));
handle_inv_ctx3(localStorage.getItem("inventory_3"));
handle_inv_ctx6(localStorage.getItem("inventory_6"));
gift_deferred.resolve();
coupon_deferred.resolve();
card_deferred.resolve();
}
var deferred = new $.Deferred();
$.when.apply(null, [gift_deferred.promise(), card_deferred.promise(), coupon_deferred.promise()]).done(function (){
deferred.resolve();
});
return deferred.promise();
} else {
var deferred = new $.Deferred();
deferred.resolve();
return deferred.promise();
}