forked from onur/DotaBuffCP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
773 lines (621 loc) · 20.5 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Dota 2 Counter Picker and advantage browser based on DotaBuff.">
<meta name="keywords" content="dota 2, counter, picker, picking, dotabuff">
<meta name="author" content="Onur Aslan">
<title>Counter Picker based on DotaBuff</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7/html5shiv.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="data.js"></script>
<script type="text/javascript">
// Fun part starts from here
var DotaBuffCP = {
VERSION: '0.3.1',
initialized: false,
initialize: function () {
this.lineup = [ -1, -1, -1, -1, -1 ];
this.initialized = true;
},
heroId: function (name) {
for (var i in heroes)
if (heroes[i].toLowerCase ().indexOf (name.toLowerCase ()) >= 0
&& heroes[i].length === name.length)
return i;
return -1;
},
heroAbbrLookup: {
"abaddon": ["avernus"],
"alchemist": ["razzil"],
"ancient apparition": ["kaldr", "aa"],
"anti-mage": ["am"],
"axe": [],
"bane": ["atropos"],
"batrider": [],
"beastmaster": ["karroch", "rexxar", "bm"],
"bloodseeker": ["strygwyr", "bs"],
"bounty hunter": ["gondar", "bh"],
"brewmaster": ["mangix", "bm"],
"bristleback": ["rigwarl", "bb"],
"broodmother": ["bm"],
"centaur warrunner": ["bradwarden", "cw"],
"chaos knight": ["ck"],
"chen": [],
"clinkz": ["bone"],
"clockwerk": ["rattletrap", "cw"],
"crystal maiden": ["rylai", "cm"],
"dark seer": ["ish", "ds"],
"dazzle": [],
"death prophet": ["krobelus", "grobulus", "dp"],
"disruptor": [],
"doom": [],
"dragon knight": ["davion", "dk"],
"drow ranger": ["traxex", "dr"],
"earthshaker": ["raigor", "es"],
"earth spirit": ["kaolin", "es"],
"elder titan": ["et"],
"ember spirit": ["xin", "es"],
"enchantress": ["aiushtha"],
"enigma": [],
"faceless void": ["darkterror"],
"gyrocopter": ["aurel"],
"huskar": [],
"invoker": ["kael", "karl", "carl"],
"io": ["wisp"],
"jakiro": ["thd"],
"juggernaut": ["yurnero"],
"keeper of the light": ["ezalor", "kotl"],
"kunkka": [],
"legion commander": ["tresdin", "lc"],
"leshrac": [],
"lich": ["ethreain"],
"lifestealer": ["naix"],
"lina": [],
"lion": [],
"lone druid": ["sylla", "ld"],
"luna": [],
"lycan": ["banehallow"],
"magnus": [],
"medusa": ["gorgon"],
"meepo": ["geomancer"],
"mirana": ["potm"],
"morphling": [],
"naga siren": ["slithice", "ns"],
"natures prophet": ["furion", "np"],
"necrophos": [],
"night stalker": ["ns", "balanar"],
"nyx assassin": ["na"],
"ogre magi": ["aggron", "om"],
"omniknight": ["ok"],
"outworld devourer": ["od", "harbinger"],
"phantom assassin": ["pa", "mortred"],
"phantom lancer": ["azwraith", "pl"],
"phoenix": [],
"puck": [],
"pudge": ["butcher"],
"pugna": [],
"queen of pain": ["akasha", "qop"],
"razor": [],
"riki": [],
"rubick": [],
"sand king": ["crixalis", "sk"],
"shadow demon": ["sd"],
"shadow fiend": ["nevermore", "sf"],
"shadow shaman": ["rhasta", "ss"],
"silencer": ["nortrom"],
"skywrath mage": ["dragonus", "sm"],
"slardar": [],
"sniper": ["kardel"],
"spectre": ["mercurial"],
"spirit breaker": ["barathrum", "sb"],
"storm spirit": ["raijin", "ss"],
"sven": [],
"techies": ["goblin","gt","sqee","spleen","spoon"],
"templar assassin": ["lanaya", "ta"],
"terrorblade": ["tb"],
"tidehunter": ["leviathan"],
"timbersaw": ["rizzrack"],
"tinker": ["boush"],
"tiny": [],
"treant protector": ["rooftrellen"],
"troll warlord": ["tw"],
"tusk": ["ymir"],
"undying": ["dirge"],
"vengeful spirit": ["shendelzare", "vs"],
"venomancer": ["lesale"],
"visage": [],
"warlock": ["demnok", "wl"],
"weaver": ["skitskurr"],
"windranger": ["lyralei", "wr"],
"witch doctor": ["zharvakko", "wd"],
"wraith king": ["ostarion", "skeleton king", "wk", "sk"],
"zeus": []
},
checkHeroAbbr: function (hero, name) {
var heroAbbr = this.heroAbbrLookup[hero.toLowerCase ()];
if (_.isUndefined (name) || _.isUndefined (heroAbbr))
return false;
name = name.toLowerCase ();
for (var i = 0; i < heroAbbr.length; ++i)
if (heroAbbr[i].indexOf (name) >= 0)
return true;
return false;
},
listHeroes: function (name) {
$('#hero-list').html ('');
_.each (heroes, function (hero, key) {
if (!_.isUndefined (name) &&
!DotaBuffCP.checkHeroAbbr (hero, name) &&
hero.toLowerCase ().indexOf (name.toLowerCase ()) < 0) {
return;
}
$('#hero-list').append (
$('<li>').attr ('data-hero-id', key).html (
$('<img>').attr ('src', 'http://www.dotabuff.com/' + heroes_bg[key])
).append (hero)
);
});
},
calculate: function () {
var advantages = Array.apply (null, new Array (heroes.length))
.map (Number.prototype.valueOf, 0.0);
for (var h in this.lineup) {
var hid = this.lineup[h];
if (hid == -1)
continue;
for (var i = 0; i < heroes.length; ++i) {
if (_.isUndefined (win_rates[hid][i]) || _.isNull (win_rates[hid][i]))
continue;
advantages[i] += parseFloat (win_rates[hid][i][0]);
}
}
return advantages;
},
generateLink: function () {
var link = '#';
for (var i in this.lineup) {
if (this.lineup[i] == -1)
link += '/';
else
link += heroes[this.lineup[i]] + '/';
}
link = link.replace (/ /g, '_');
link = link.replace (/\/+$/, '');
return link;
},
getVersion: function () {
var d = new Date (update_time);
var month = d.getMonth () + 1;
if (month < 10)
month = '0' + month;
var day = d.getDate ();
if (day < 10)
day = '0' + day;
var database_version = d.getFullYear () + month + '' + day;
return this.VERSION + '.' + database_version;
}
};
var MainView = Backbone.View.extend ({
el: '#main-container',
initialize: function () {
this.$el.html (_.template ($('#main-view-template').html ()));
DotaBuffCP.listHeroes ();
$('#hero-search').focus ();
},
events: {
'keyup #hero-search': 'heroSearch',
'click #hero-search-reset': 'heroSearchReset',
'click #hero-list li': 'addHero',
'click div.lineup div.col-md-2 img': 'removeHero',
'click #reset-all': 'resetAll',
'submit form': function () { return false; }
},
heroSearch: function (ev) {
// reset if Esc pressed
if (ev.keyCode == 27) {
$(ev.currentTarget).val ('');
this.heroSearchReset ();
}
// add first hero if enter pressed
else if (ev.keyCode == 13) {
this.addFirstHero ();
}
else {
DotaBuffCP.listHeroes ($(ev.currentTarget).val ());
}
return false;
},
heroSearchReset: function () {
DotaBuffCP.listHeroes ();
},
switchLink: function () {
var link = DotaBuffCP.generateLink ();
location.href = link;
},
addFirstHero: function () {
$('#hero-list li:first').trigger ('click');
},
addHero: function (ev) {
var hid = $(ev.currentTarget).attr ('data-hero-id');
var pick_i = -1;
this.heroSearchReset ();
$('#hero-search').val ('');
$('#hero-search').focus ();
for (var i in DotaBuffCP.lineup)
if (DotaBuffCP.lineup[i] == hid)
return;
for (var i in DotaBuffCP.lineup) {
if (DotaBuffCP.lineup[i] == -1) {
pick_i = i;
break;
}
}
if (pick_i == -1)
return;
DotaBuffCP.lineup[pick_i] = hid;
$('#hero-' + pick_i).html ($('<img>').attr ('src', 'http://www.dotabuff.com/' + heroes_bg[hid])
.attr ('data-idx', pick_i));
this.calculateAndShow ();
this.switchLink ();
},
addHeroToIndex: function (hid, pick_i) {
$('#hero-' + pick_i).html ($('<img>').attr ('src', 'http://www.dotabuff.com/' + heroes_bg[hid])
.attr ('data-idx', pick_i));
},
removeHero: function (ev) {
var i = $(ev.currentTarget).attr ('data-idx');
DotaBuffCP.lineup[i] = -1;
$('#hero-' + i).html ('');
this.calculateAndShow ();
this.switchLink ();
},
resetAll: function () {
for (var i = 0; i < 5; ++i) {
DotaBuffCP.lineup[i] = -1;
$('#hero-' + i).html ('');
}
this.calculateAndShow ();
this.switchLink ();
},
isEmpty: function () {
for (var i in DotaBuffCP.lineup)
if (DotaBuffCP.lineup[i] != -1)
return false;
return true;
},
showAdvantages: function (div, advantages) {
var template = $('#counter-template').html ();
$('#' + div).html ('');
_.each (advantages, function (advantage, i) {
for (var l in DotaBuffCP.lineup)
if (advantage[1] == DotaBuffCP.lineup[l])
return;
$('#' + div).append (_.template (template, {
hero_bg: heroes_bg[advantage[1]],
hero_name: heroes[advantage[1]],
advantage: advantage[0].toFixed (2) * -1
}));
});
},
calculateAndShow: function () {
if (this.isEmpty ()) {
$('div.lineup-title').show ();
$('div.pick-title').hide ();
$('#reset-all').hide ();
$('#counters').hide ();
return;
} else {
$('div.lineup-title').hide ();
$('div.pick-title').show ();
$('#reset-all').show ();
$('#counters').show ();
}
var advantages = DotaBuffCP.calculate ();
// lets add indexes (hero ids) first
for (var i in advantages)
advantages[i] = [advantages[i], i];
advantages.sort (function (l, r) {
return l[0] < r[0] ? -1 : 1;
});
this.showAdvantages ('best-picks',
advantages.slice (0, advantages.length / 2));
this.showAdvantages ('worse-picks',
advantages.reverse ().slice (0, advantages.length / 2));
$('#counters').scrollTop (0);
}
});
var AppRouter = Backbone.Router.extend ({
initialize: function () {
this.route (/^(.*?)$/, 'sozdeHerolar');
this.route (/^about$/, 'about');
},
sozdeHerolar: function (heroSelection) {
if (DotaBuffCP.initialized)
return;
else
DotaBuffCP.initialize ();
var mainView = new MainView ();
if (_.isNull (heroSelection))
return;
heroSelection = heroSelection.replace (/_/g, ' ');
var selectedHeroes = heroSelection.split ('/');
for (var i in selectedHeroes) {
if (i > 4)
break;
if (_.isEmpty (selectedHeroes[i]))
continue;
var hid = DotaBuffCP.heroId (selectedHeroes[i]);
if (hid == -1)
continue;
DotaBuffCP.lineup[i] = hid;
mainView.addHeroToIndex (hid, i);
}
mainView.calculateAndShow ();
},
about: function () {
$('#main-container').html (_.template ($('#about-page').html (),
{ version: DotaBuffCP.VERSION,
last_update: update_time }));
DotaBuffCP.initialized = false;
}
});
$(document).ready (function () {
// set version
$('#version').text (DotaBuffCP.getVersion ());
var appRouter = new AppRouter ();
Backbone.history.start ({ pushState: false, root: '/dotabuffcp/' });
});
</script>
<style type="text/css">
html, body {
height: 100%;
}
body {
padding: 20px 0 20px 0;
}
img {
border: 1px solid #aaa;
box-shadow: 2px 2px 8px 0px rgba(50, 50, 50, 0.38);
}
.navbar {
margin-bottom: 20px;
}
div.main-wrapper {
width: 967px !important;
position: relative;
height: 100%;
}
#main-container {
position: absolute;
bottom: 0;
top: 70px;
width: 967px !important;
padding-right: 30px;
}
div.main-col {
position: absolute;
bottom: 0;
top: 0;
}
div.second-col {
position: absolute;
bottom: 0;
top: 0;
right: 30px;
}
#hero-list {
position: absolute;
top: 50px;
bottom: 0;
overflow-y: auto;
left: 15px;
right: 20px;
}
#hero-list,
#hero-list li {
list-style-type: none;
margin: 0;
padding: 0;
}
#hero-list li {
margin-bottom: 10px;
cursor: pointer;
}
#hero-list li img {
max-width: 100px;
margin-right: 10px;
}
form.hero-search-form {
margin-bottom: 10px;
}
div.lineup img {
max-width: 100px;
}
div.lineup div.col-md-2 {
cursor: pointer;
}
div.lineup-title {
margin: 0 20px 0 20px;
text-align: center;
}
#counters {
position: absolute;
top: 180px;
bottom: 0;
overflow-y: auto;
overflow-x: hidden;
left: 30px;
right: 20px;
padding-right: 20px;
}
#counters div.row img {
max-width: 90px;
}
div.pick-title {
text-align: center;
padding-top: 20px;
font-size: 1.2em;
}
div.addthis_toolbox {
margin-top: 10px;
}
div.faq {
padding: 0 200px 0 200px;
}
div.reset-all-div {
padding-bottom: 20px;
text-align: center;
}
#reset-all,
#counters,
div.pick-title {
display: none;
}
</style>
</head>
<body>
<div class="container main-wrapper">
<!-- lets put a navbar -->
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">DotaBuff CP</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#about">About</a></li>
<li><a href="https://github.com/onuraslan/DotaBuffCP">GitHub</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://raw.githubusercontent.com/onuraslan/DotaBuffCP/gh-pages/CHANGELOG" id="version"></a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</div>
<div id="main-container"></div>
</div><!-- main wrapper -->
<script type="text/template" id="main-view-template">
<div class="row">
<div class="col-md-4 col-xs-4 main-col">
<form class="form-inline hero-search-form" role="form">
<div class="form-group">
<label class="sr-only" for="hero-search">Hero Name</label>
<input type="text" class="form-control" id="hero-search" placeholder="Search" autocomplete="off">
</div>
<button id="hero-search-reset" type="reset" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></button>
</form>
<ul id="hero-list"></ul>
</div>
<div class="col-md-8 col-xs-8 second-col">
<div class="row alert alert-info row lineup-title">
<p>Choose enemy heroes from the list on the left</p>
<p>You can search heroes, and add them quickly by pressing enter</p>
</div>
<div class="row reset-all-div">
<a id="reset-all" class="btn btn-default">Reset all</a>
</div>
<div class="row lineup">
<div class="col-md-1 col-xs-1"></div>
<div class="col-md-2 col-xs-2" id="hero-0"></div>
<div class="col-md-2 col-xs-2" id="hero-1"></div>
<div class="col-md-2 col-xs-2" id="hero-2"></div>
<div class="col-md-2 col-xs-2" id="hero-3"></div>
<div class="col-md-2 col-xs-2" id="hero-4"></div>
<div class="col-md-1 col-xs-1"></div>
</div>
<div class="row pick-title">
<div class="row">
<div class="col-md-12 col-xs-12">Advantages</div>
</div>
<div class="col-md-6 col-xs-6">Best picks</div>
<div class="col-md-6 col-xs-6">Worst picks</div>
</div>
<div id="counters" class="row">
<div class="row">
<div class="col-md-6 col-xs-6">
<table class="table table-striped">
<tbody id="best-picks"></tbody>
</table>
</div>
<div class="col-md-6 col-xs-6">
<table class="table table-striped">
<tbody id="worse-picks"></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</script>
<script type="text/template" id="counter-template">
<tr class="<%
if (advantage > 10) { %>success<% }
else if (advantage > 7.5) { %>info<% }
else if (advantage > 5) { %>warning<% }
else if (advantage < 0) { %>danger<% }
%>">
<td><img src="<%= 'http://www.dotabuff.com' + hero_bg %>"></td>
<td><%= hero_name %></td>
<td><%= advantage %>%</td>
</tr>
</script>
<script type="text/template" id="about-page">
<div class="jumbotron">
<h2>DotaBuffCP v<%= version %></h2>
<p>Database last updated on <em><%= last_update %></em></p>
</div>
<div class="faq">
<h1>FAQ</h1>
<h3>What is this?</h3>
<p>This is a counter picker for Dota 2. It shows the advantage percentages
against a hero or team. Advantage percentages are collected from
<a href="http://dotabuff.com/">dotabuff.com</a>. This tool simply adds
advantages together and shows the sum of advantage of each hero.
It updates database each day, so it will be always sycnhed with dotabuff.
</p>
<p>DotaBuffCP designed to be a single page application. This allows you
to quickly browse advantages. There is no page reloads,
HTTP requests etc. You can instantly see the result and you can use
this tool to counter-pick your enemies before matches.</p>
<h3>Why do I need this?</h3>
<p>If you don't know what to pick, then this tool may help you.
You can run it in your in-game browser.</p>
<p>It's also useful to browse advantages quickly. I was using well-known
user voted counter picker website. It was slow, not up to date and
everyone have their own opinion. I needed a stats based fast tool,
and made this eventually.</p>
<h3>How can I help?</h3>
<p>DotaBuffCP is free software. You can contribute to it's development.
Check <a href="https://github.com/onuraslan/DotaBuffCP">github</a> page
for bug reports, feature requests, etc. I also love pull requests.</p>
<h3>Is there an easy way to access?</h3>
<p>You can also access this page from
<strong>tinyurl.com/dotabuffcp</strong>. It's easy to remember.</p>
</div>
</script>
<!-- google analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-50635373-1', 'onuraslan.github.io');
ga('send', 'pageview');
</script>
</body>
</html>