Advertisement
Guest User

Untitled

a guest
Nov 29th, 2013
3,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Los Clickos Hermanos
  3. // @namespace   *
  4. // @include     http://clickingbad.nullism.com/
  5. // @version     1
  6. // @grant       none
  7. // ==/UserScript==
  8.  
  9. // LAST UPDATE : 23/11/13 for version 0.8.1
  10. // - shows efficiency and potential gain for each Manufacturing item : "Costs $4.81M/batch; Is worth $249.63B/s"
  11. // - shows efficiency and gain for each Distribution item : "Costs $4.81M/sold batch; Yields $249.63B/s"
  12. // - shows efficiency for each Laundering item : "Costs $17,275/laundered $"
  13. // - colors! Red = bad value for money, Green = good value for money, White = the average item regarding value for money
  14. // - change items description text color as it becomes unreadable when the item becomes Orange/Red
  15.  
  16. function addCommas(nStr) {
  17.     nStr += '';
  18.     x = nStr.split('.');
  19.     x1 = x[0];
  20.     x2 = x.length > 1 ? '.' + x[1] : '';
  21.     var rgx = /(\d+)(\d{3})/;
  22.     while (rgx.test(x1)) {
  23.         x1 = x1.replace(rgx, '$1' + ',' + '$2');
  24.     }
  25.     return x1 + x2;
  26. }
  27.  
  28. function makeRealNumber(nb) {
  29.     return eval(
  30.         nb.replace(/,/g,"")
  31.           .replace(/M/,"*1E6")
  32.           .replace(/B/,"*1E9")
  33.           .replace(/T/,"*1E12")
  34.           .replace(/Qt/,"*1E18")
  35.           .replace(/Q/,"*1E15")
  36.     )
  37. }
  38.  
  39. // map
  40. sortables = {}
  41.  
  42. function buildLabels(divName, text1, text2) {
  43.     divs = document.querySelectorAll("div#"+divName+" > div.s_div")
  44.    
  45.     sortables[divName] = []
  46.    
  47.     batchPrice = document.querySelector("span#sell_roi").textContent
  48.    
  49.     for (i=0; i<divs.length; i++) {
  50.         div = divs[i]
  51.         cost = makeRealNumber(div.querySelector("p.small > b > span").textContent)
  52.         p = div.querySelector("p[class='pull_right small']")
  53.         infosSpans = p.querySelectorAll("b > span")
  54.         batchesPerS = makeRealNumber(infosSpans[0].textContent)
  55.        
  56.         efficiency = Math.round(cost / batchesPerS)
  57.         dollarsPerS = Math.round(batchesPerS * batchPrice)
  58.  
  59.         zboub1 = p.querySelector("span#zboub1")
  60.         zboub2 = p.querySelector("span#zboub2")
  61.         if (zboub1 == undefined) {
  62.             p.appendChild(document.createElement("br"))
  63.             p.appendChild(document.createTextNode(text1[0]))
  64.            
  65.             b1 = document.createElement("b")
  66.             zboub1 = document.createElement("span")
  67.             zboub1.id = "zboub1"
  68.             b1.appendChild(zboub1)
  69.             p.appendChild(b1)
  70.            
  71.             p.appendChild(document.createTextNode(text1[1]))
  72.            
  73.             if (text2 !== undefined) {
  74.                 p.appendChild(document.createTextNode(text2[0]))
  75.                
  76.                 b2 = document.createElement("b")
  77.                 zboub2 = document.createElement("span")
  78.                 zboub2.id = "zboub2"
  79.                 b2.appendChild(zboub2)
  80.                 p.appendChild(b2)
  81.                
  82.                 p.appendChild(document.createTextNode(text2[1]))
  83.             }
  84.         }
  85.  
  86.         newValue = "$"+ unsafeWindow.pretty_bigint(efficiency)
  87.         if (newValue != zboub1.textContent) {
  88.             zboub1.textContent = newValue
  89.         }
  90.         if (text2 !== undefined) {
  91.             newValue = "$"+ unsafeWindow.pretty_bigint(dollarsPerS)
  92.             if (newValue != zboub2.textContent) {
  93.                 zboub2.textContent = newValue
  94.             }
  95.         }
  96.        
  97.         sortables[divName].push({"efficiency":efficiency, "element":div})
  98.     }
  99.     sortables[divName].sort(function(a,b) {return parseFloat(b.efficiency) - parseFloat(a.efficiency)})
  100.  
  101.     colorize(sortables[divName])
  102.    
  103. }
  104.  
  105. function decimalToHex(d, padding) {
  106.     var hex = Number(d).toString(16);
  107.     padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
  108.  
  109.     while (hex.length < padding) {
  110.         hex = "0" + hex;
  111.     }
  112.  
  113.     return hex;
  114. }
  115.  
  116. function colorize(theArray) {
  117.     // bad half: red to yellow, FF0000 to FFFF00
  118.     // good half: yellow to green, FFFF00 to 00FF00
  119.     step = Math.round(206 / (theArray.length-1))
  120.     colors=[]
  121.     for (i=0 ; i<Math.round(theArray.length)/2 ; i++) {
  122.         colors.push("#FF"+decimalToHex(50+i*step)+"00")
  123.     }
  124.     step = Math.round(256 / (theArray.length-1))
  125.     for (i=0 ; i<Math.round(theArray.length)/2 ; i++) {
  126.         colors.push("#"+decimalToHex(256-i*step)+"FF00")
  127.     }
  128.     colors.push("#00FF00")
  129.    
  130. //  GM_log(JSON.stringify(colors))
  131.    
  132.     for (i=0 ; i<theArray.length; i++) {
  133.         newStyle = "background-color:"+colors[i]
  134.         if (theArray[i].element.getAttribute("style") != newStyle) {
  135.             theArray[i].element.setAttribute("style", newStyle)
  136.         }
  137.     }
  138. }
  139.  
  140. function computeAndShowCost() {
  141.     buildLabels("clickers", ["Costs ", "/batch"], ["; Is worth ", "/s"])
  142.     buildLabels("sellers", ["Costs ", "/sold batch"], ["; Yields ", "/s"])
  143.     buildLabels("banks", ["Costs ", "/laundered $"])
  144. }
  145.  
  146. setInterval(computeAndShowCost, 1000)
  147.  
  148. function addCss(cssString) {
  149.     var head = document.getElementsByTagName('head')[0];
  150.     if (head) {
  151.         var newCss = document.createElement('style');
  152.         newCss.type = "text/css";
  153.         newCss.innerHTML = cssString;
  154.         head.appendChild(newCss);
  155.     }
  156. }
  157. addCss ('.grey { color: black ! important; }');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement