Advertisement
Guest User

OSTM efficiency building script

a guest
Aug 28th, 2014
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Evaluate(a, b)
  2. {
  3.     return document.evaluate('//div[@id="' + a + '"]//*[@id="' + b + '"]/text()', document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent;
  4. }
  5.  
  6. function GetMed(a)
  7. {
  8.     return numberWithCommas(Evaluate(a, "cost")) / numberWithCommas(Evaluate(a, "description").substring(1));
  9. }
  10.  
  11. function numberWithCommas(x) {
  12.     return parseFloat(x.replace(new RegExp(',', 'g'), ''));
  13. }
  14.  
  15. function MarkBest()
  16. {
  17.     var buildings = ["tent-building", "shack-building", "cabin-building", "cottage-building", "house-building", "manor-building", "dorm-building", "apartment-building", "condo-building"];
  18.     var bestIndex = 0;
  19.     for (i = 0; i < buildings.length; ++i) {
  20.         var priceForOneGPS = document.getElementById(buildings[i] + "_gps-price");
  21.         if (priceForOneGPS === null) {
  22.             priceForOneGPS = document.createElement('div');
  23.             priceForOneGPS.setAttribute("id", buildings[i] + "_gps-price");
  24.         }
  25.        
  26.         priceForOneGPS.innerHTML = GetMed(buildings[i]);
  27.         document.getElementById(buildings[i]).appendChild(priceForOneGPS);
  28.        
  29.         document.getElementById(buildings[i]).style.color = "red";
  30.         if (i == 0) {
  31.             bestIndex = i;
  32.         }
  33.         else {
  34.             if (GetMed(buildings[i]) < GetMed(buildings[bestIndex])) {
  35.                 bestIndex = i;
  36.             }
  37.         }      
  38.     }
  39.     document.getElementById(buildings[bestIndex]).style.color = "green";
  40. }
  41. MarkBest();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement