kill.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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': ykill.format_system(kill['system_name'], kill['security'], kill['security_status'])})
  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').grab(new Element('a', {
  22. 'html': victim['character_name'], 'href': '/character/' + victim['character_id']
  23. }))
  24. ),
  25. new Element('tr').adopt(
  26. new Element('td').grab(
  27. ykill.portrait(victim['corporation_id'], victim['corporation_name'], 'corporation', '_64.png')
  28. ),
  29. new Element('td').grab(new Element('a', {
  30. 'html': victim['corporation_name'], 'href': '/corporation/' + victim['corporation_id']
  31. }))
  32. )
  33. );
  34. if (victim['alliance_id'])
  35. table.grab(new Element('tr').adopt(
  36. new Element('td').grab(
  37. ykill.portrait(victim['alliance_id'], victim['alliance_name'], 'alliance', '_64.png')
  38. ),
  39. new Element('td').grab(new Element('a', {
  40. 'html': victim['alliance_name'], 'href': '/alliance/' + victim['alliance_id']
  41. }))
  42. ));
  43. if (victim['faction_id'])
  44. table.grab(new Element('tr').adopt(
  45. new Element('td').grab(
  46. ykill.portrait(victim['faction_id'], victim['faction_name'], 'alliance', '_64.png')
  47. ),
  48. new Element('td', {'html': victim['faction_name']})
  49. ));
  50. table.grab(
  51. new Element('tr').adopt(
  52. new Element('td', {'html': 'cost'}),
  53. new Element('td', {'html': ykill.format_isk(kill['cost'])})
  54. )
  55. );
  56. var items = data['items'];
  57. var div = $('ship');
  58. div.setStyle('background-image', 'url(//image.eveonline.com/render/' + victim['ship_type_id'] + '_256.png)');
  59. Object.each(data['slots'], function(num, slot) {
  60. var divs = $(slot).getChildren();
  61. for (var i = 0; i < num; i++)
  62. divs[i].addClass('avail');
  63. if (!items[slot])
  64. return;
  65. var has_charges = (['high', 'medium', 'low'].indexOf(slot) > -1);
  66. items[slot].each(function(item) {
  67. var div;
  68. if (has_charges && item['charge'])
  69. div = $('charge_' + item['flag']);
  70. else
  71. div = $('slot_' + item['flag']);
  72. div.setStyle('background-image', 'url(//image.eveonline.com/type/' + item['type_id'] + '_32.png)');
  73. div.grab(new Element('div', {'class': 'tooltip', 'html': item['item_name']}));
  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 = [
  104. 'subsystem', 'high', 'medium', 'low', 'rig', 'drone bay',
  105. 'cargo', 'special hold', 'ship hangar', 'fleet hangar', 'implant', '???'
  106. ];
  107. slots.each(function(slot) {
  108. if (!items[slot])
  109. return;
  110. table.grab(new Element('tr').grab(
  111. new Element('td', {'html': slot, 'colspan': 4, 'class': 'slot'})
  112. ));
  113. if (slot == 'high') {
  114. var highs = {'dropped': {}, 'destroyed': {}};
  115. items[slot].each(function(item) {
  116. var d = item['dropped'] ? 'dropped' : 'destroyed';
  117. var count = item[d];
  118. if (highs[d][item['type_id']])
  119. highs[d][item['type_id']][d] += item[d];
  120. else
  121. highs[d][item['type_id']] = item;
  122. });
  123. items[slot] = [];
  124. Object.each(highs, function(item_class) {
  125. Object.each(item_class, function(item) {
  126. items[slot].push(item);
  127. });
  128. });
  129. }
  130. items[slot].each(function(item) {
  131. var type_id = item['type_id'];
  132. var item_name = item['item_name'];
  133. var item_class = item['dropped'] ? 'dropped' : 'destroyed';
  134. var count = item[item_class];
  135. var cost = item['cost'] * count;
  136. if (item['singleton'] == 2) {
  137. item_name += ' (copy)';
  138. cost /= 1000;
  139. }
  140. if (item['type_id'] == 33329 && item['flag'] == 89) // Genolution 'Auroral' AU-79 in implant slot
  141. cost = 'n/a';
  142. else
  143. cost = ykill.format_isk(cost);
  144. table.grab(new Element('tr').adopt(
  145. new Element('td').grab(
  146. new Element('img', {
  147. 'src': '//image.eveonline.com/Type/' + type_id + '_32.png',
  148. 'alt': item['item_name'],
  149. })
  150. ),
  151. new Element('td', {'html': item_name}),
  152. new Element('td', {'html': count, 'class': item_class}),
  153. new Element('td', {'html': cost})
  154. ));
  155. });
  156. });
  157. });
  158. function show_attacker(table, char) {
  159. var tr = new Element('tr');
  160. var td = new Element('td');
  161. td.grab(ykill.portrait(char['character_id'], char['character_name'], 'character', '_32.jpg'));
  162. if (char['alliance_id'])
  163. td.grab(ykill.portrait(char['alliance_id'], char['alliance_name'], 'alliance', '_32.png'));
  164. else if (char['faction_id'])
  165. td.grab(ykill.portrait(char['faction_id'], char['faction_name'], 'alliance', '_32.png'));
  166. else
  167. td.grab(ykill.portrait(char['corporation_id'], char['corporation_name'], 'corporation', '_32.png'));
  168. tr.grab(td);
  169. td = new Element('td');
  170. td.appendText(char['character_name']);
  171. td.grab(new Element('br'));
  172. td.appendText(char['corporation_name']);
  173. if (char['alliance_id']) {
  174. td.grab(new Element('br'));
  175. td.appendText(char['alliance_name']);
  176. }
  177. if (char['faction_id']) {
  178. td.grab(new Element('br'));
  179. td.appendText(char['faction_name']);
  180. }
  181. tr.grab(td);
  182. td = new Element('td').adopt(
  183. new Element('div').adopt(
  184. ykill.portrait(char['ship_type_id'], char['ship_name'], 'type', '_32.png'),
  185. new Element('div', {'class': 'tooltip', 'html': char['ship_name']})
  186. ),
  187. new Element('div').adopt(
  188. ykill.portrait(char['weapon_type_id'], char['weapon_name'], 'type', '_32.png'),
  189. new Element('div', {'class': 'tooltip', 'html': char['weapon_name']})
  190. )
  191. );
  192. tr.grab(td);
  193. tr.grab(new Element('td').appendText(char['damage'].toLocaleString()));
  194. table.grab(tr);
  195. }
  196. });