The_Fifth_Horseman

MWO Lootbag Calculator

Apr 13th, 2022
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var totals=["C-Bills","MC","GXP","GSP", "Day Active Premium Time"];
  2. var text='';
  3. var text_rows=[];
  4. function summarize(item_type, collection) {
  5.     if (collection.length == 0)
  6.         return '';
  7.     collection=collection.sort();
  8.     var summarized_text ='<br>'+(collection.length)+' '+ item_type +' items:<br>';
  9.     new Set(collection).forEach(
  10.         (value) => summarized_text += (
  11.             collection.reduce(
  12.                 (running, current) => current === value ? ++running : running, 0
  13.             ) + 'x '+value+'<br>'
  14.         )
  15.     );
  16.     return summarized_text;
  17. }
  18. function collection_sum(collection) {
  19.     return collection.reduce(
  20.         function(running,value){
  21.             return running += parseFloat(value.replace(',','').split(' ')[0]) <<0
  22.         },0
  23.     )
  24. }
  25. function indexOf_factory(needle) {
  26.     return function(haystack) {
  27.         return haystack.indexOf(needle)>=0;
  28.     }
  29. }
  30. function indexOf_any(haystack, needlebook){
  31.     for(var i=0;i<needlebook.length;i++)
  32.         if (haystack.indexOf(needlebook[i])>=0)
  33.             return true;
  34.     return false;
  35. }
  36. $(".dataRow td[class^='mode_'],.dataRowBonus td[class^='bonusRow_']").map(
  37.     function() {
  38.         text_rows.push( $(this).text() )
  39.     }
  40. );
  41. totals.map(
  42.     function(category){
  43.         text+=collection_sum(text_rows.filter(indexOf_factory(category)))+' '+category+'<br>'
  44.     }
  45. );
  46. text+=  summarize('cockpit', text_rows.filter(indexOf_factory("Cockpit")).map((element) => element.substring(8)))+
  47.         summarize('consumable', text_rows.filter(indexOf_factory("CBill")).map((element) => element.substring(6)))+
  48.         summarize('other', text_rows.filter((value) => !(indexOf_any(value,totals.concat(["Cockpit","CBill"])))));
  49. $("body").append("<div style='position: fixed;bottom: 0px;right: 0px;color: white;background-color: black;'><h4>"+text+"</h4></div>");
Advertisement
Add Comment
Please, Sign In to add comment