kill.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. items[slot].each(function(item) {
  66. var div = $('slot_' + item['flag']);
  67. var bg_img = div.getStyle('background-image');
  68. if (bg_img == 'none')
  69. set_item(div, item);
  70. else {
  71. var charge_div = $('charge_' + item['flag']);
  72. if (item['capacity']) {
  73. charge_div.setStyle('background-image', bg_img);
  74. charge_div.grab(div.getChildren()[0]);
  75. set_item(div, item);
  76. } else {
  77. set_item(charge_div, item);
  78. }
  79. }
  80. });
  81. });
  82. table = $('attackers');
  83. table.grab(new Element('tr').grab(
  84. new Element('td', {'class': 'attacker_type', 'colspan': 4, 'html': 'final blow'})
  85. ));
  86. show_attacker(table, data['final_blow']);
  87. if (data['attackers'].length) {
  88. table.grab(new Element('tr').grab(
  89. new Element('td', {'class': 'attacker_type', 'colspan': 4, 'html': 'attackers'})
  90. ));
  91. data['attackers'].each(function(char) {
  92. show_attacker(table, char);
  93. });
  94. }
  95. table = $('items');
  96. table.adopt(
  97. new Element('tr').grab(
  98. new Element('td', {'html': 'ship', 'colspan': 4, 'class': 'slot'})
  99. ),
  100. new Element('tr').adopt(
  101. new Element('td').grab(
  102. ykill.portrait(victim['ship_type_id'], victim['ship_name'], 'type', '_32.png')
  103. ),
  104. new Element('td', {'html': victim['ship_name']}),
  105. new Element('td'),
  106. new Element('td', {'html': ykill.format_isk(victim['ship_cost'])})
  107. )
  108. );
  109. var slots = [
  110. 'subsystem', 'high', 'medium', 'low', 'rig', 'drone bay',
  111. 'cargo', 'special hold', 'ship hangar', 'fleet hangar', 'implant', '???'
  112. ];
  113. slots.each(function(slot) {
  114. if (!items[slot])
  115. return;
  116. table.grab(new Element('tr').grab(
  117. new Element('td', {'html': slot, 'colspan': 4, 'class': 'slot'})
  118. ));
  119. if (slot == 'high') {
  120. var highs = {'dropped': {}, 'destroyed': {}};
  121. items[slot].each(function(item) {
  122. var d = item['dropped'] ? 'dropped' : 'destroyed';
  123. var count = item[d];
  124. if (highs[d][item['type_id']])
  125. highs[d][item['type_id']][d] += item[d];
  126. else
  127. highs[d][item['type_id']] = item;
  128. });
  129. items[slot] = [];
  130. Object.each(highs, function(item_class) {
  131. Object.each(item_class, function(item) {
  132. items[slot].push(item);
  133. });
  134. });
  135. }
  136. items[slot].each(function(item) {
  137. var type_id = item['type_id'];
  138. var item_name = item['item_name'];
  139. var item_class = item['dropped'] ? 'dropped' : 'destroyed';
  140. var count = item[item_class];
  141. var cost = item['cost'] * count;
  142. if (item['singleton'] == 2) {
  143. item_name += ' (copy)';
  144. cost /= 1000;
  145. }
  146. if (item['type_id'] == 33329 && item['flag'] == 89) // Genolution 'Auroral' AU-79 in implant slot
  147. cost = 'n/a';
  148. else
  149. cost = ykill.format_isk(cost);
  150. table.grab(new Element('tr').adopt(
  151. new Element('td').grab(
  152. new Element('img', {
  153. 'src': '//image.eveonline.com/Type/' + type_id + '_32.png',
  154. 'alt': item['item_name'],
  155. })
  156. ),
  157. new Element('td', {'html': item_name}),
  158. new Element('td', {'html': count, 'class': item_class}),
  159. new Element('td', {'html': cost})
  160. ));
  161. });
  162. });
  163. });
  164. function set_item(div, item) {
  165. div.setStyle('background-image', 'url(//image.eveonline.com/type/' + item['type_id'] + '_32.png)');
  166. div.grab(new Element('div', {'class': 'tooltip', 'html': item['item_name']}));
  167. }
  168. function show_attacker(table, char) {
  169. var tr = new Element('tr');
  170. var td = new Element('td');
  171. td.grab(ykill.portrait(char['character_id'], char['character_name'], 'character', '_32.jpg'));
  172. if (char['alliance_id'])
  173. td.grab(ykill.portrait(char['alliance_id'], char['alliance_name'], 'alliance', '_32.png'));
  174. else if (char['faction_id'])
  175. td.grab(ykill.portrait(char['faction_id'], char['faction_name'], 'alliance', '_32.png'));
  176. else
  177. td.grab(ykill.portrait(char['corporation_id'], char['corporation_name'], 'corporation', '_32.png'));
  178. tr.grab(td);
  179. td = new Element('td');
  180. td.appendText(char['character_name']);
  181. td.grab(new Element('br'));
  182. td.appendText(char['corporation_name']);
  183. if (char['alliance_id']) {
  184. td.grab(new Element('br'));
  185. td.appendText(char['alliance_name']);
  186. }
  187. if (char['faction_id']) {
  188. td.grab(new Element('br'));
  189. td.appendText(char['faction_name']);
  190. }
  191. tr.grab(td);
  192. td = new Element('td').adopt(
  193. new Element('div').adopt(
  194. ykill.portrait(char['ship_type_id'], char['ship_name'], 'type', '_32.png'),
  195. new Element('div', {'class': 'tooltip', 'html': char['ship_name']})
  196. ),
  197. new Element('div').adopt(
  198. ykill.portrait(char['weapon_type_id'], char['weapon_name'], 'type', '_32.png'),
  199. new Element('div', {'class': 'tooltip', 'html': char['weapon_name']})
  200. )
  201. );
  202. tr.grab(td);
  203. tr.grab(new Element('td').appendText(char['damage'].toLocaleString()));
  204. table.grab(tr);
  205. }
  206. });