Advertisement
joric

Bitcoin userscript for Mt.Gox (MtGoxFeeCalculator.user.js)

Jan 5th, 2012
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          MtGoxFeeCalculator
  3. // @description   Shows final Mt.Gox value (including fee) as you type.
  4. // @screenshot    http://img707.imageshack.us/img707/4795/screenshot2012010614181.png
  5. // @namespace     http://pastebin.com/Zzqncbrb
  6. // @version       1.0.1
  7. // @include       https://mtgox.com/*
  8. // @installation  chrome-compatible (just open *.user.js in a browser)
  9. // ==/UserScript==
  10.  
  11. (function(window, undefined ) {
  12.     var w;
  13.     if (typeof unsafeWindow != undefined) {
  14.         w = unsafeWindow
  15.     } else {
  16.         w = window;
  17.     }
  18.     if (w.self != w.top) {
  19.         return;
  20.     }
  21.  
  22.     function getElementsByClassName(classname, node)  {
  23.         if(!node) node = document.getElementsByTagName("body")[0];
  24.         var a = [];
  25.         var re = new RegExp('\\b' + classname + '\\b');
  26.         var els = node.getElementsByTagName("*");
  27.         for(var i=0,j=els.length; i<j; i++)
  28.             if(re.test(els[i].className))a.push(els[i]);
  29.         return a;
  30.     }
  31.  
  32.     function update_fee(edit, label, fee) {
  33.         var amount = parseFloat(document.getElementById(edit).value);
  34.         if (isNaN(amount))
  35.             amount = 0.0;
  36.         result = amount * (1 - fee * 0.01);
  37.         result = Math.round(result * 100000000) / 100000000;
  38.         document.getElementById(label).innerHTML = 'Total (-' + fee + '%): ' + result;
  39.     }
  40.  
  41.     function update() {
  42.         var elements = document.getElementsByClassName('progressStart');
  43.         var fee = parseFloat(elements[0].innerHTML);
  44.         update_fee('buyAmount','totalBuyAmount', fee);
  45.         update_fee('sellCost','totalSellCost', fee);
  46.     }
  47.  
  48.     function add_label(parent, id) {
  49.         var div = document.createElement('div');
  50.         div.setAttribute('id', id);
  51.         div.style.position = 'relative';
  52.         div.style.lineHeight = '0';
  53.         div.style.color = '#aaa';
  54.         div.style.top = '10px';
  55.         div.style.fontSize = '11px';
  56.         document.getElementById(parent).parentNode.appendChild(div);
  57.     }
  58.  
  59.     if (/https:\/\/mtgox.com/.test(w.location.href)) {
  60.         add_label('buyAmount', 'totalBuyAmount');
  61.         add_label('sellCost', 'totalSellCost');
  62.         window.setInterval(update, 1000);
  63.         update();
  64.     }
  65.  
  66. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement