kill.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.adopt(
  45. new Element('tr').adopt(
  46. new Element('td').grab(
  47. ykill.portrait(victim['ship_type_id'], victim['ship_name'], 'type', '_64.png')
  48. ),
  49. new Element('td', {'html': victim['ship_name']})
  50. ),
  51. new Element('tr').adopt(
  52. new Element('td', {'html': 'cost'}),
  53. new Element('td', {'html': ykill.format_isk(kill['cost'] / 100)})
  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. var slots = ['subsystem', 'high', 'medium', 'low', 'rig', 'drone bay', 'cargo', 'special hold', 'implant', '???'];
  97. slots.each(function(slot) {
  98. if (!items[slot])
  99. return;
  100. table.grab(new Element('tr').grab(
  101. new Element('td', {'html': slot, 'colspan': 4, 'class': 'slot'})
  102. ));
  103. if (slot == 'high') {
  104. var highs = {'dropped': {}, 'destroyed': {}};
  105. items[slot].each(function(item) {
  106. var d = item['dropped'] ? 'dropped' : 'destroyed';
  107. var count = item[d];
  108. if (highs[d][item['type_id']])
  109. highs[d][item['type_id']][d] += item[d];
  110. else
  111. highs[d][item['type_id']] = item;
  112. });
  113. items[slot] = [];
  114. Object.each(highs, function(item_class) {
  115. Object.each(item_class, function(item) {
  116. items[slot].push(item);
  117. });
  118. });
  119. }
  120. items[slot].each(function(item) {
  121. var type_id = item['type_id'];
  122. var item_class = item['dropped'] ? 'dropped' : 'destroyed';
  123. var count = item[item_class];
  124. table.grab(new Element('tr').adopt(
  125. new Element('td').grab(
  126. new Element('img', {
  127. 'src': '//image.eveonline.com/Type/' + type_id + '_32.png',
  128. 'alt': item['item_name'],
  129. })
  130. ),
  131. new Element('td', {'html': item['item_name']}),
  132. new Element('td', {'html': count, 'class': item_class}),
  133. new Element('td', {'html': ykill.format_isk(item['cost'] / 100)})
  134. ));
  135. });
  136. });
  137. });
  138. function set_item(div, item) {
  139. div.setStyle('background-image', 'url(//image.eveonline.com/type/' + item['type_id'] + '_32.png)');
  140. div.grab(new Element('div', {'class': 'tooltip', 'html': item['item_name']}));
  141. }
  142. function show_attacker(table, char) {
  143. var tr = new Element('tr');
  144. var td = new Element('td');
  145. td.grab(ykill.portrait(char['character_id'], char['character_name'], 'character', '_32.jpg'));
  146. if (char['alliance_id'])
  147. td.grab(ykill.portrait(char['alliance_id'], char['alliance_name'], 'alliance', '_32.png'));
  148. else if (char['faction_id'])
  149. td.grab(ykill.portrait(char['faction_id'], char['faction_name'], 'alliance', '_32.png'));
  150. else
  151. td.grab(ykill.portrait(char['corporation_id'], char['corporation_name'], 'corporation', '_32.png'));
  152. tr.grab(td);
  153. td = new Element('td');
  154. td.appendText(char['character_name']);
  155. td.grab(new Element('br'));
  156. td.appendText(char['corporation_name']);
  157. if (char['alliance_id']) {
  158. td.grab(new Element('br'));
  159. td.appendText(char['alliance_name']);
  160. }
  161. if (char['faction_id']) {
  162. td.grab(new Element('br'));
  163. td.appendText(char['faction_name']);
  164. }
  165. tr.grab(td);
  166. td = new Element('td').adopt(
  167. ykill.portrait(char['ship_type_id'], char['ship_name'], 'type', '_32.png'),
  168. ykill.portrait(char['weapon_type_id'], char['weapon_name'], 'type', '_32.png')
  169. );
  170. tr.grab(td);
  171. tr.grab(new Element('td').appendText(char['damage']));
  172. table.grab(tr);
  173. }
  174. });