Last active
October 17, 2016 22:42
-
-
Save Manbearpixel/b394d29799c12f5452cd60b60e63ebe6 to your computer and use it in GitHub Desktop.
Bookmarklet for showing BTC worth of altcoin on Poloniex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Show Poloniex BTC USD Value</h3> | |
<p>Drag and drop the link below to your bookmark toolbar in order to use this bookmark to show the USD worth (in BTC) for altcoins on Poloniex Exchange.</p> | |
<p>The source has been added to give complete transparency to how this works and to ensure nothing is being stolen</p> | |
<hr/> | |
<p><a id="OutputHref" ng-attr-href="{{ output }}" href="javascript:(function(){if(1==window.__superAwesomeThingy)return%20console.warn(%22--%20SuperAwesomeThingy%20BTC%20shower%20is%20already%20active!%22),console.info(%22--%20Disabling%20SuperAwesomeThingy%20BTC%20shower!%22),clearInterval(window.__superAwesomeThingID),window.__superAwesomeThingID=null,window.__superAwesomeThingy=!1,!1;window.__superAwesomeThingy=!0;var%20runSwitch=function(currentBTC){console.info(%22--%20adjusting%20BTC%20value%20--%22),jQuery(%22%23marketBTC%20%3E%20tbody%20%20%3E%20tr%22).each(function(){var%20currentRow=jQuery(this),currentPriceCol=currentRow.find(%22.price%22);if(-1!=currentPriceCol.text().indexOf(%22;;%22))var%20splitter=currentPriceCol.text().split(%22;;%22),parsedPrice=parseFloat(splitter[0]).toFixed(8);else%20var%20parsedPrice=parseFloat(currentPriceCol.text()).toFixed(8);var%20calculatedBTC=(parsedPrice*currentBTC).toFixed(8),newPriceText=parsedPrice+%22;;\n($%22+calculatedBTC+%22%20btc)%22;return%20currentPriceCol.text(newPriceText),!0})},fetchBTCOrder=function(){jQuery.get(%22https://public.poloniex.com/%3Fcommand=returnTradeHistory%26currencyPair=USDT_BTC%22,function(r){var%20recentOrders=r,recentBuy=recentOrders[100],currentBTCRate=parseFloat(recentBuy.rate).toFixed(2);runSwitch(currentBTCRate)})};fetchBTCOrder(),window.__superAwesomeThingID=setInterval(fetchBTCOrder,1e4),console.info(%22--%20Poloniex%20BTC%20price%20shower-thingy%20by%20Polo%20User%20%40PkMnRed%20--%22)})();">Show BTC Value | Poloniex</a></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
if (window.__superAwesomeThingy == true) { | |
console.warn('-- SuperAwesomeThingy BTC shower is already active!'); | |
console.info('-- Disabling SuperAwesomeThingy BTC shower!'); | |
clearInterval(window.__superAwesomeThingID); | |
window.__superAwesomeThingID = null; | |
window.__superAwesomeThingy = false; | |
return false; | |
} | |
else { | |
window.__superAwesomeThingy = true; | |
var runSwitch = function(currentBTC) { | |
console.info('-- adjusting BTC value --'); | |
// Loop through each tablerow (tr) and adjust BTC value | |
jQuery('#marketBTC > tbody > tr').each(function(){ | |
var currentRow = jQuery(this); | |
var currentPriceCol = currentRow.find('.price'); | |
// Check if we have already manipulated this row... | |
if (currentPriceCol.text().indexOf(';;') != -1) { | |
var splitter = currentPriceCol.text().split(';;'); | |
var parsedPrice = parseFloat(splitter[0]).toFixed(8); | |
} | |
else { | |
var parsedPrice = parseFloat(currentPriceCol.text()).toFixed(8); | |
} | |
var calculatedBTC = (parsedPrice * currentBTC).toFixed(8); | |
var newPriceText = parsedPrice + ';;\n($'+ calculatedBTC +' btc)'; | |
currentPriceCol.text(newPriceText); | |
return true; | |
}); | |
}; | |
var fetchBTCOrder = function() { | |
// Make XHR GET request to polo trade history for USD/BTC | |
jQuery.get('https://public.poloniex.com/?command=returnTradeHistory¤cyPair=USDT_BTC', function(r){ | |
var recentOrders = r; | |
var recentBuy = recentOrders[100]; // Grab most recent BTC BUY order | |
var currentBTCRate = parseFloat(recentBuy.rate).toFixed(2); | |
// shove that rate to all current BTC rows | |
runSwitch(currentBTCRate); | |
}); | |
}; | |
// Fetch every 10 seconds (1000 milliseconds per 1 second) | |
// Best to keep this low, don't need to make too many calls | |
// Save the ID to cancel calls if it is necessary | |
fetchBTCOrder(); | |
window.__superAwesomeThingID = setInterval(fetchBTCOrder, 1000 * 10); | |
console.info('-- Poloniex BTC price shower-thingy by Polo User @PkMnRed --'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To save this as a Bookmark, drag the following Link to your Bookmark Toolbar! Then you can click the bookmark while on Poloniex to show the BTC USD value of altcoins! If you click the bookmark again, it will turn this feature off. It will refresh every 10 seconds. During that time if the alt coin value changes on Polo, the USD BTC value will disappear, but will reappear after it refreshes!
[SHOW POLO $BTC]
[SHOW POLO $BTC]
[Hello](javascript:function my_bookmarklet(){alert('Hello World');}my_bookmarklet();)