Guest User

Untitled

a guest
Jan 13th, 2018
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function BattlefieldPHP()
  2. {
  3.     // Disable ajax navigation on battlefield
  4.     GetContentTD().innerHTML = GetContentTD().innerHTML;
  5.  
  6.     // Find the bf table
  7.     var tables = document.getElementsByClassName("table_lines battlefield");
  8.     if(tables.length == 0) return;
  9.  
  10.     bfTable = tables[0];
  11.  
  12.     // Dont let the alliance column dominate
  13.     bfTable.rows[0].cells[1].width = "15%";
  14.  
  15.     // Log bf gold
  16.     var logList = "";
  17.  
  18.     var statDiv = document.createElement('div');
  19.     statDiv.setAttribute('id', "statDiv");
  20.     statDiv.setAttribute('style', "text-align:center; position:fixed; right:10px; bottom:10px; width:15ex; border:1px solid gray; background-color:black; color:white; font-size:10pt;");
  21.     statDiv.innerHTML = "Loading...";
  22.     document.body.appendChild(statDiv);
  23.  
  24.         // Add an option to sort gold
  25.     bfTable.rows[0].cells[4].innerHTML = "<input type=checkbox style='verticle-align:middle' id=SortTreasury " + (GM_getValue("DEMK_sortTreasury", 1) == 1 ? "checked" : "") + "><label for=SortTreasury>Sort Treasury</label>";
  26.     document.getElementById('SortTreasury').addEventListener('click', function(){ GM_setValue("DEMK_sortTreasury", this.checked ? 1 : 0); window.location = window.location; }, false);
  27.  
  28.     if(GM_getValue("DEMK_sortTreasury", 1) == 1)
  29.     {
  30.         var bf_gold = [];
  31.         var bf_ids = [];
  32.         var bf_rank = [];
  33.         var bf_ids0 = [];   //unsorted original row ids
  34.         var bf_html = [];
  35.  
  36.         // Sort the treasury
  37.         for(var i = 0; i < bfTable.rows.length; i++)
  38.         {
  39.             if(bfTable.rows[i].cells.length < 7)
  40.             {
  41.                 continue;
  42.             }
  43.  
  44.             // remove the user's own row bg color
  45.             bfTable.rows[i].setAttribute('bgColor', null);
  46.  
  47.             var gold_i = parseInt( bfTable.rows[i].cells[5].innerHTML.replace(/,/g, "").replace(" Gold", ""), 10 );
  48.  
  49.             if(isNaN(gold_i))
  50.             {
  51.                 gold_i = -1;
  52.             }
  53.  
  54.             bf_gold.push(gold_i);
  55.             bf_ids.push(i);
  56.             bf_ids0.push(i);
  57.             bf_html[i] = bfTable.rows[i].innerHTML.toString();
  58.             bf_rank.push(parseInt(bfTable.rows[i].cells[6].innerHTML.replace(/,/g, "")));
  59.         }
  60.  
  61.         // actual sorting is on integers
  62.         for(var i = 0; i < bf_gold.length; i++)
  63.         {
  64.             for(var j = i + 1; j < bf_gold.length; j++)
  65.             {
  66.                 var swap = 0;
  67.  
  68.                 if(bf_gold[j] > bf_gold[i])
  69.                 {
  70.                     swap = 1;
  71.                 }
  72.                 else if(bf_rank[j] < bf_rank[i])
  73.                 {
  74.                     swap = 1;
  75.                 }
  76.  
  77.                 if(swap)
  78.                 {
  79.                     var tmp = bf_gold[i];
  80.                     bf_gold[i] = bf_gold[j];
  81.                     bf_gold[j] = tmp;
  82.  
  83.                     tmp = bf_ids[i];
  84.                     bf_ids[i] = bf_ids[j];
  85.                     bf_ids[j] = tmp;
  86.  
  87.                     tmp = bf_rank[i];
  88.                     bf_rank[i] = bf_rank[j];
  89.                     bf_rank[j] = tmp;
  90.                 }
  91.             }
  92.         }
  93.  
  94.         // replace the rows using the sorted row ids
  95.         for(var i = 0; i < bf_gold.length; i++)
  96.         {
  97.             bfTable.rows[bf_ids0[i]].innerHTML = bf_html[bf_ids[i]];
  98.         }
  99.  
  100.                 for(var i = 0; i < bfTable.rows.length; i++)
  101.                 {
  102.                         if(bfTable.rows[i].cells.length != 7) continue;
  103.  
  104.                         var usernameInner = bfTable.rows[i].cells[2].innerHTML;
  105.                         var username = GetTextIn(usernameInner, ">", "<");
  106.                         var statid = GetTextIn(usernameInner, "id=", "\"");
  107.  
  108.                         var tff = bfTable.rows[i].cells[3].innerHTML.replace(/,/g, "");
  109.                         var treasury = bfTable.rows[i].cells[5].innerHTML.replace(/,/g, "").replace(" Gold", "");
  110.                         var rank = bfTable.rows[i].cells[6].innerHTML.replace(/,/g, "");
  111.  
  112.                         var alliance = bfTable.rows[i].cells[1].innerHTML;
  113.                         alliance2 = GetTextIn(alliance, '>', '</a>');
  114.  
  115.                         alliance2 = 'None'; //temp
  116.  
  117.                         logList += "[user]" + username + "[/user]" + "[gold]" + treasury + "[/gold]" + "[tff]" + tff + "[/tff]" + "[userid]" + statid + "[/userid]" + "[alliance]" + alliance2 + "[/alliance]" + "[rank]" + rank + "[/rank]";
  118.  
  119.                         // Also make username links open in new tab
  120.                         bfTable.rows[i].cells[2].innerHTML = bfTable.rows[i].cells[2].innerHTML.replace("href=", "target=_blank href=");
  121.                 }
  122.  
  123.                 GM_xmlhttpRequest(
  124.                 {
  125.                         method: "GET",
  126.                         url: DEMK_server + "general.php?code=logbattlefield&whoami=" + DEMK_username + "&password=" + DEMK_password + "&whoamid=" + DEMK_statid + "&list=" + logList,
  127.                         onload: function(r)
  128.                         {
  129.                                 if(r.status != 200) return;
  130.  
  131.                                 for(var i = 0; i < bfTable.rows.length; i++)
  132.                                 {
  133.                                         if(bfTable.rows[i].cells[5].innerHTML == "??? Gold")
  134.                                         {
  135.                                                 bfTable.rows[i].cells[5].innerHTML =  GetTextIn(r.responseText, "[aGOLD" + (i-1) + "]", "[/aGOLD" + (i-1) + "]") + " &nbsp <span style='color:yellow'>" + AddCommas(GetTextIn(r.responseText, "[GOLD" + (i-1) + "]", "[/GOLD" + (i-1) + "]")) + "</span> Gold";
  136.                                         }
  137.                                 }
  138.                         }
  139.                 });
  140.     }
  141.         else
  142.         {
  143.                 for(var i = 0; i < bfTable.rows.length; i++)
  144.                 {
  145.                         if(bfTable.rows[i].cells.length != 7) continue;
  146.  
  147.                         var usernameInner = bfTable.rows[i].cells[2].innerHTML;
  148.                         var username = GetTextIn(usernameInner, ">", "<");
  149.                         var statid = GetTextIn(usernameInner, "id=", "\"");
  150.  
  151.                         var tff = bfTable.rows[i].cells[3].innerHTML.replace(/,/g, "");
  152.                         var treasury = bfTable.rows[i].cells[5].innerHTML.replace(/,/g, "").replace(" Gold", "");
  153.                         var rank = bfTable.rows[i].cells[6].innerHTML.replace(/,/g, "");
  154.  
  155.                         var alliance = bfTable.rows[i].cells[1].innerHTML;
  156.                         alliance2 = GetTextIn(alliance, '>', '</a>');
  157.  
  158.                         alliance2 = 'None'; //temp
  159.  
  160.                         logList += "[user]" + username + "[/user]" + "[gold]" + treasury + "[/gold]" + "[tff]" + tff + "[/tff]" + "[userid]" + statid + "[/userid]" + "[alliance]" + alliance2 + "[/alliance]" + "[rank]" + rank + "[/rank]";
  161.  
  162.                         // Also make username links open in new tab
  163.                         bfTable.rows[i].cells[2].innerHTML = bfTable.rows[i].cells[2].innerHTML.replace("href=", "target=_blank href=");
  164.                 }
  165.  
  166.                 GM_xmlhttpRequest(
  167.                 {
  168.                         method: "GET",
  169.                         url: DEMK_server + "general.php?code=logbattlefield&whoami=" + DEMK_username + "&password=" + DEMK_password + "&whoamid=" + DEMK_statid + "&list=" + logList,
  170.                         onload: function(r)
  171.                         {
  172.                                 if(r.status != 200) return;
  173.  
  174.                                 for(var i = 0; i < bfTable.rows.length; i++)
  175.                                 {
  176.                                         if(bfTable.rows[i].cells[5].innerHTML == "??? Gold")
  177.                                         {
  178.                                                 bfTable.rows[i].cells[5].innerHTML =  GetTextIn(r.responseText, "[aGOLD" + (i-1) + "]", "[/aGOLD" + (i-1) + "]") + " &nbsp <span style='color:yellow'>" + AddCommas(GetTextIn(r.responseText, "[GOLD" + (i-1) + "]", "[/GOLD" + (i-1) + "]")) + "</span> Gold";
  179.                                         }
  180.                                 }
  181.                         }
  182.                 });
  183.         }
Add Comment
Please, Sign In to add comment