Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function BattlefieldPHP()
- {
- // Disable ajax navigation on battlefield
- GetContentTD().innerHTML = GetContentTD().innerHTML;
- // Find the bf table
- var tables = document.getElementsByClassName("table_lines battlefield");
- if(tables.length == 0) return;
- bfTable = tables[0];
- // Dont let the alliance column dominate
- bfTable.rows[0].cells[1].width = "15%";
- // Log bf gold
- var logList = "";
- var statDiv = document.createElement('div');
- statDiv.setAttribute('id', "statDiv");
- 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;");
- statDiv.innerHTML = "Loading...";
- document.body.appendChild(statDiv);
- // Add an option to sort gold
- 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>";
- document.getElementById('SortTreasury').addEventListener('click', function(){ GM_setValue("DEMK_sortTreasury", this.checked ? 1 : 0); window.location = window.location; }, false);
- if(GM_getValue("DEMK_sortTreasury", 1) == 1)
- {
- var bf_gold = [];
- var bf_ids = [];
- var bf_rank = [];
- var bf_ids0 = []; //unsorted original row ids
- var bf_html = [];
- // Sort the treasury
- for(var i = 0; i < bfTable.rows.length; i++)
- {
- if(bfTable.rows[i].cells.length < 7)
- {
- continue;
- }
- // remove the user's own row bg color
- bfTable.rows[i].setAttribute('bgColor', null);
- var gold_i = parseInt( bfTable.rows[i].cells[5].innerHTML.replace(/,/g, "").replace(" Gold", ""), 10 );
- if(isNaN(gold_i))
- {
- gold_i = -1;
- }
- bf_gold.push(gold_i);
- bf_ids.push(i);
- bf_ids0.push(i);
- bf_html[i] = bfTable.rows[i].innerHTML.toString();
- bf_rank.push(parseInt(bfTable.rows[i].cells[6].innerHTML.replace(/,/g, "")));
- }
- // actual sorting is on integers
- for(var i = 0; i < bf_gold.length; i++)
- {
- for(var j = i + 1; j < bf_gold.length; j++)
- {
- var swap = 0;
- if(bf_gold[j] > bf_gold[i])
- {
- swap = 1;
- }
- else if(bf_rank[j] < bf_rank[i])
- {
- swap = 1;
- }
- if(swap)
- {
- var tmp = bf_gold[i];
- bf_gold[i] = bf_gold[j];
- bf_gold[j] = tmp;
- tmp = bf_ids[i];
- bf_ids[i] = bf_ids[j];
- bf_ids[j] = tmp;
- tmp = bf_rank[i];
- bf_rank[i] = bf_rank[j];
- bf_rank[j] = tmp;
- }
- }
- }
- // replace the rows using the sorted row ids
- for(var i = 0; i < bf_gold.length; i++)
- {
- bfTable.rows[bf_ids0[i]].innerHTML = bf_html[bf_ids[i]];
- }
- for(var i = 0; i < bfTable.rows.length; i++)
- {
- if(bfTable.rows[i].cells.length != 7) continue;
- var usernameInner = bfTable.rows[i].cells[2].innerHTML;
- var username = GetTextIn(usernameInner, ">", "<");
- var statid = GetTextIn(usernameInner, "id=", "\"");
- var tff = bfTable.rows[i].cells[3].innerHTML.replace(/,/g, "");
- var treasury = bfTable.rows[i].cells[5].innerHTML.replace(/,/g, "").replace(" Gold", "");
- var rank = bfTable.rows[i].cells[6].innerHTML.replace(/,/g, "");
- var alliance = bfTable.rows[i].cells[1].innerHTML;
- alliance2 = GetTextIn(alliance, '>', '</a>');
- alliance2 = 'None'; //temp
- logList += "[user]" + username + "[/user]" + "[gold]" + treasury + "[/gold]" + "[tff]" + tff + "[/tff]" + "[userid]" + statid + "[/userid]" + "[alliance]" + alliance2 + "[/alliance]" + "[rank]" + rank + "[/rank]";
- // Also make username links open in new tab
- bfTable.rows[i].cells[2].innerHTML = bfTable.rows[i].cells[2].innerHTML.replace("href=", "target=_blank href=");
- }
- GM_xmlhttpRequest(
- {
- method: "GET",
- url: DEMK_server + "general.php?code=logbattlefield&whoami=" + DEMK_username + "&password=" + DEMK_password + "&whoamid=" + DEMK_statid + "&list=" + logList,
- onload: function(r)
- {
- if(r.status != 200) return;
- for(var i = 0; i < bfTable.rows.length; i++)
- {
- if(bfTable.rows[i].cells[5].innerHTML == "??? Gold")
- {
- bfTable.rows[i].cells[5].innerHTML = GetTextIn(r.responseText, "[aGOLD" + (i-1) + "]", "[/aGOLD" + (i-1) + "]") + "   <span style='color:yellow'>" + AddCommas(GetTextIn(r.responseText, "[GOLD" + (i-1) + "]", "[/GOLD" + (i-1) + "]")) + "</span> Gold";
- }
- }
- }
- });
- }
- else
- {
- for(var i = 0; i < bfTable.rows.length; i++)
- {
- if(bfTable.rows[i].cells.length != 7) continue;
- var usernameInner = bfTable.rows[i].cells[2].innerHTML;
- var username = GetTextIn(usernameInner, ">", "<");
- var statid = GetTextIn(usernameInner, "id=", "\"");
- var tff = bfTable.rows[i].cells[3].innerHTML.replace(/,/g, "");
- var treasury = bfTable.rows[i].cells[5].innerHTML.replace(/,/g, "").replace(" Gold", "");
- var rank = bfTable.rows[i].cells[6].innerHTML.replace(/,/g, "");
- var alliance = bfTable.rows[i].cells[1].innerHTML;
- alliance2 = GetTextIn(alliance, '>', '</a>');
- alliance2 = 'None'; //temp
- logList += "[user]" + username + "[/user]" + "[gold]" + treasury + "[/gold]" + "[tff]" + tff + "[/tff]" + "[userid]" + statid + "[/userid]" + "[alliance]" + alliance2 + "[/alliance]" + "[rank]" + rank + "[/rank]";
- // Also make username links open in new tab
- bfTable.rows[i].cells[2].innerHTML = bfTable.rows[i].cells[2].innerHTML.replace("href=", "target=_blank href=");
- }
- GM_xmlhttpRequest(
- {
- method: "GET",
- url: DEMK_server + "general.php?code=logbattlefield&whoami=" + DEMK_username + "&password=" + DEMK_password + "&whoamid=" + DEMK_statid + "&list=" + logList,
- onload: function(r)
- {
- if(r.status != 200) return;
- for(var i = 0; i < bfTable.rows.length; i++)
- {
- if(bfTable.rows[i].cells[5].innerHTML == "??? Gold")
- {
- bfTable.rows[i].cells[5].innerHTML = GetTextIn(r.responseText, "[aGOLD" + (i-1) + "]", "[/aGOLD" + (i-1) + "]") + "   <span style='color:yellow'>" + AddCommas(GetTextIn(r.responseText, "[GOLD" + (i-1) + "]", "[/GOLD" + (i-1) + "]")) + "</span> Gold";
- }
- }
- }
- });
- }
Add Comment
Please, Sign In to add comment