kill.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. window.addEvent('domready', function() {
  2. var kill_id = document.location.pathname.split('/').getLast();
  3. ykill.api('/kill/' + kill_id, function(data) {
  4. var kill = data['kill'];
  5. var victim = data['victim'];
  6. document.title += ' - ' + victim['character_name'] + ' - ' + victim['ship_name'];
  7. var table = $('victim');
  8. table.adopt(
  9. new Element('tr').adopt(
  10. new Element('td', {'html': 'time'}),
  11. new Element('td', {'html': kill['kill_time']})
  12. ),
  13. new Element('tr').adopt(
  14. new Element('td', {'html': 'system'}),
  15. new Element('td', {'html': kill['solarSystemName'] + ' (' + kill['security'].toFixed(1) + ')'})
  16. ),
  17. new Element('tr').adopt(
  18. new Element('td').grab(
  19. ykill.portrait(victim['character_id'], victim['character_name'], 'character', '_64.jpg')
  20. ),
  21. new Element('td', {'html': victim['character_name']})
  22. ),
  23. new Element('tr').adopt(
  24. new Element('td').grab(
  25. ykill.portrait(victim['corporation_id'], victim['corporation_name'], 'corporation', '_64.png')
  26. ),
  27. new Element('td', {'html': victim['corporation_name']})
  28. )
  29. );
  30. if (victim['alliance_id'])
  31. table.grab(new Element('tr').adopt(
  32. new Element('td').grab(
  33. ykill.portrait(victim['alliance_id'], victim['alliance_name'], 'alliance', '_64.png')
  34. ),
  35. new Element('td', {'html': victim['alliance_name']})
  36. ));
  37. if (victim['faction_id'])
  38. table.grab(new Element('tr').adopt(
  39. new Element('td').grab(
  40. ykill.portrait(victim['faction_id'], victim['faction_name'], 'alliance', '_64.png')
  41. ),
  42. new Element('td', {'html': victim['faction_name']})
  43. ));
  44. table.grab(
  45. new Element('tr').adopt(
  46. new Element('td', {'html': 'cost'}),
  47. new Element('td', {'html': ykill.format_isk(kill['cost'])})
  48. )
  49. );
  50. var items = data['items'];
  51. var div = $('ship');
  52. div.setStyle('background-image', 'url(//image.eveonline.com/render/' + victim['ship_type_id'] + '_256.png)');
  53. Object.each(data['slots'], function(num, slot) {
  54. var divs = $(slot).getChildren();
  55. for (var i = 0; i < num; i++)
  56. divs[i].addClass('avail');
  57. if (!items[slot])
  58. return;
  59. items[slot].each(function(item) {
  60. var div = $('slot_' + item['flag']);
  61. var bg_img = div.getStyle('background-image');
  62. if (bg_img == 'none')
  63. set_item(div, item);
  64. else {
  65. var charge_div = $('charge_' + item['flag']);
  66. if (item['capacity']) {
  67. charge_div.setStyle('background-image', bg_img);
  68. charge_div.grab(div.getChildren()[0]);
  69. set_item(div, item);
  70. } else {
  71. set_item(charge_div, item);
  72. }
  73. }
  74. });
  75. });
  76. table = $('attackers');
  77. table.grab(new Element('tr').grab(
  78. new Element('td', {'class': 'attacker_type', 'colspan': 4, 'html': 'final blow'})
  79. ));
  80. show_attacker(table, data['final_blow']);
  81. if (data['attackers'].length) {
  82. table.grab(new Element('tr').grab(
  83. new Element('td', {'class': 'attacker_type', 'colspan': 4, 'html': 'attackers'})
  84. ));
  85. data['attackers'].each(function(char) {
  86. show_attacker(table, char);
  87. });
  88. }
  89. table = $('items');
  90. table.adopt(
  91. new Element('tr').grab(
  92. new Element('td', {'html': 'ship', 'colspan': 4, 'class': 'slot'})
  93. ),
  94. new Element('tr').adopt(
  95. new Element('td').grab(
  96. ykill.portrait(victim['ship_type_id'], victim['ship_name'], 'type', '_32.png')
  97. ),
  98. new Element('td', {'html': victim['ship_name']}),
  99. new Element('td'),
  100. new Element('td', {'html': ykill.format_isk(victim['ship_cost'])})
  101. )
  102. );
  103. var slots = ['subsystem', 'high', 'medium', 'low', 'rig', 'drone bay', 'cargo', 'special hold', 'implant', '???'];
  104. slots.each(function(slot) {
  105. if (!items[slot])
  106. return;
  107. table.grab(new Element('tr').grab(
  108. new Element('td', {'html': slot, 'colspan': 4, 'class': 'slot'})
  109. ));
  110. if (slot == 'high') {
  111. var highs = {'dropped': {}, 'destroyed': {}};
  112. items[slot].each(function(item) {
  113. var d = item['dropped'] ? 'dropped' : 'destroyed';
  114. var count = item[d];
  115. if (highs[d][item['type_id']])
  116. highs[d][item['type_id']][d] += item[d];
  117. else
  118. highs[d][item['type_id']] = item;
  119. });
  120. items[slot] = [];
  121. Object.each(highs, function(item_class) {
  122. Object.each(item_class, function(item) {
  123. items[slot].push(item);
  124. });
  125. });
  126. }
  127. items[slot].each(function(item) {
  128. var type_id = item['type_id'];
  129. var item_class = item['dropped'] ? 'dropped' : 'destroyed';
  130. var count = item[item_class];
  131. table.grab(new Element('tr').adopt(
  132. new Element('td').grab(
  133. new Element('img', {
  134. 'src': '//image.eveonline.com/Type/' + type_id + '_32.png',
  135. 'alt': item['item_name'],
  136. })
  137. ),
  138. new Element('td', {'html': item['item_name']}),
  139. new Element('td', {'html': count, 'class': item_class}),
  140. new Element('td', {'html': ykill.format_isk(item['cost'])})
  141. ));
  142. });
  143. });
  144. });
  145. function set_item(div, item) {
  146. div.setStyle('background-image', 'url(//image.eveonline.com/type/' + item['type_id'] + '_32.png)');
  147. div.grab(new Element('div', {'class': 'tooltip', 'html': item['item_name']}));
  148. }
  149. function show_attacker(table, char) {
  150. var tr = new Element('tr');
  151. var td = new Element('td');
  152. td.grab(ykill.portrait(char['character_id'], char['character_name'], 'character', '_32.jpg'));
  153. if (char['alliance_id'])
  154. td.grab(ykill.portrait(char['alliance_id'], char['alliance_name'], 'alliance', '_32.png'));
  155. else if (char['faction_id'])
  156. td.grab(ykill.portrait(char['faction_id'], char['faction_name'], 'alliance', '_32.png'));
  157. else
  158. td.grab(ykill.portrait(char['corporation_id'], char['corporation_name'], 'corporation', '_32.png'));
  159. tr.grab(td);
  160. td = new Element('td');
  161. td.appendText(char['character_name']);
  162. td.grab(new Element('br'));
  163. td.appendText(char['corporation_name']);
  164. if (char['alliance_id']) {
  165. td.grab(new Element('br'));
  166. td.appendText(char['alliance_name']);
  167. }
  168. if (char['faction_id']) {
  169. td.grab(new Element('br'));
  170. td.appendText(char['faction_name']);
  171. }
  172. tr.grab(td);
  173. td = new Element('td').adopt(
  174. ykill.portrait(char['ship_type_id'], char['ship_name'], 'type', '_32.png'),
  175. ykill.portrait(char['weapon_type_id'], char['weapon_name'], 'type', '_32.png')
  176. );
  177. tr.grab(td);
  178. tr.grab(new Element('td').appendText(char['damage'].toLocaleString()));
  179. table.grab(tr);
  180. }
  181. });