// ==UserScript== // @name Bitcoinica Helper // @version 0.9.1 var version="0.9.1"; // @description Adds new functionality to Bitcoinica website // @include https://bitcoinica.com/trading* // @author m_r // @license MIT // ==/UserScript== // Emulate unsafe window // https://gist.github.com/1143845 window.unsafeWindow || ( unsafeWindow = (function() { var el = document.createElement('p'); el.setAttribute('onclick', 'return window;'); return el.onclick(); }()) ); console.log(unsafeWindow); // Initalize script function USER_Init($, unsafeWindow) { // Account data global variables var bid, ask, usd, btc, margin, leverage, min_percent; // Possible leverage levels var leverageLevels = [1, 2.5, 5, 10]; // Percentage levels for forced liquidation var liquidationLevels = [0.06, 0.16, 0.36, 0.96]; // Parse string with currency to its float value function USER_ParseCurrency(value) { var search = value.match(/[0-9,.]+/); return parseFloat(search[0].replace(/,/, "")); } // Parse string with leverage function USER_ParseLeverage(value) { return parseFloat(value.substring(0, value.indexOf(":") - 1)); } function USER_Update() { bid = USER_ParseCurrency($('#buying-btcusd')[0].innerHTML); ask = USER_ParseCurrency($('#selling-btcusd')[0].innerHTML); // ACCOUNT OVERVIEW // Get HTML of account overview var account_overview = $('div#account_overview'); var account_data = account_overview.find('table.data').find('td'); // Exit if we're not on right page if (!account_overview[0]) return; // Parse the HTML to get the details usd = USER_ParseCurrency(account_data[1].innerHTML); btc = USER_ParseCurrency(account_data[3].innerHTML); margin = USER_ParseCurrency(account_data[5].innerHTML); leverage = USER_ParseLeverage(account_data[9].innerHTML); net_value = USER_ParseCurrency(account_data[13].innerHTML); maintenance = USER_ParseCurrency(account_data[15].innerHTML); // Get level for forced liquidation based on leverage min_percent; for(var i = 0; i < leverageLevels.length; i++) { if (leverage == leverageLevels[i]) min_percent = liquidationLevels[i]; } // POSITIONS // Check for Min. price header cell var positionsHeaderCheck = $('th#min_price_header'); if (!positionsHeaderCheck[0]) $($('table#positions thead').find('th')[2]).after('