Last active
August 29, 2015 13:56
-
-
Save keslerm/9173480 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name CoinMine.pw Enhancements | |
// @namespace http://www.dasbiersec.com | |
// @version 0.5 | |
// @description Add some enhancements to CoinMine.pw | |
// @include http://*coinmine.pw/account.php | |
// @copyright 2012+, You | |
// ==/UserScript== | |
// a function that loads jQuery and calls a callback function when jQuery has finished loading | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
// the guts of this userscript | |
function main() | |
{ | |
// Cookie helper functions, stolen from W3C page | |
function getCookie(cname) | |
{ | |
var name = cname + "="; | |
var ca = document.cookie.split(';'); | |
for(var i=0; i<ca.length; i++) | |
{ | |
var c = ca[i].trim(); | |
if (c.indexOf(name)==0) return c.substring(name.length,c.length); | |
} | |
return ""; | |
} | |
function setCookie(cname,cvalue,minutes) | |
{ | |
var d = new Date(); | |
d.setTime(d.getTime()+(minutes*60*1000)); | |
var expires = "expires="+d.toGMTString(); | |
document.cookie = cname + "=" + cvalue + "; " + expires; | |
} | |
// Main UI building method | |
function buildUI(cryptsyPrice) | |
{ | |
// Resize account list page to be wider | |
jQ('body div:nth-child(3) div').first().css('width', '1200px'); | |
// Move LTC/USD estimates out from tooltip | |
jQ('input[value=payaccounts]').parent().find('table').each(function (index, element) { | |
jQ(this).attr('width', '99%'); | |
var details = jQ(this).find('td:nth-child(2)').find("b > a").attr('title').split("\n"); | |
var confirmedBalance = parseFloat(jQ(this).find('td:nth-child(2)').find("b > a").text()); | |
var coinName = jQ(this).find('td:first-child').find('b').text(); | |
// big of regex to get min payout amounts | |
var minPayoutAmount = parseFloat(jQ(this).find('small').text().match(/([\d.]+)/)[0]); | |
// Highlight any balances over the min amount | |
if (confirmedBalance >= minPayoutAmount) | |
{ | |
console.log('Coin: ' + coinName + ' Confirmed: ' + confirmedBalance + ' Min Payout: ' + minPayoutAmount); | |
jQ(this).parent("div").css('background-color', '#ADEBAD'); | |
} | |
// Move tooltip price details out to a column and add in LTC/BTC prices | |
var html = '<td style="width: 440px" valign="top">'; | |
for (var i = 0; i < details.length; i++) | |
{ | |
html = html + details[i] + "<br />"; | |
// BTC price | |
if (i == details.length - 1) | |
{ | |
var data = details[i].split(" "); | |
var price = 0; | |
if (parseFloat(data[1]) > 0) | |
{ | |
price = (parseFloat(data[1]) * cryptsyPrice).toFixed(8); | |
} | |
html = html + "BTC: " + price + "<br />"; | |
} | |
} | |
jQ(this).find('tr').append(html); | |
}); | |
// Find auto payouts > 0 and add a Enable Payout/Disable Payout button that auto sets min amount | |
jQ('.coinpayout').each(function (index, element) { | |
var poField = jQ(this).attr("name"); | |
if (jQ(this).val() > 0) | |
{ | |
jQ(this).parent().append('<br /><button class="disablepayout" style="background-color: green; color: white;" pofield="' + poField + '">Disable Payout</button>'); | |
} | |
else | |
{ | |
// add quick toggle button | |
jQ(this).parent().append('<br /><button class="enablepayout" pofield="' + poField + '">Enable Payout</button>'); | |
} | |
}); | |
jQ('.disablepayout').on('click', function (event) { | |
var poField = jQ(this).attr("pofield"); | |
jQ("input[name='" + poField + "']").val("0"); | |
jQ(this).css('background-color', '').css('color', '').text('Disabled!!').attr('disabled', 'disabled'); | |
event.preventDefault(); | |
}); | |
jQ('.enablepayout').on('click', function (event) { | |
var poField = jQ(this).attr("pofield"); | |
jQ("input[name='" + poField + "']").val("0.1"); | |
jQ(this).css('background-color', 'green').css('color', 'white').text('Enabled!!').attr('disabled', 'disabled'); | |
event.preventDefault(); | |
}); | |
} | |
// Get BTC price details, cache BTC price in cookie for 5 minutes so that we don't have to reach out to cryptsy every time. | |
if (getCookie("cryptsyPrice") != "") | |
{ | |
console.log("Setting BTC price from cookie"); | |
var cryptsyPrice = getCookie("cryptsyPrice"); | |
buildUI(cryptsyPrice); | |
} | |
else | |
{ | |
console.log("Fetching BTC price from Cryptsy"); | |
jQ.get('http://jsonp.jit.su/?url=http%3A%2F%2Fpubapi.cryptsy.com%2Fapi.php%3Fmethod%3Dsinglemarketdata%26marketid%3D3', function (data) { | |
console.log(data.return.markets.LTC.lasttradeprice); | |
var cryptsyPrice = data.return.markets.LTC.lasttradeprice; | |
setCookie("cryptsyPrice", cryptsyPrice, 5); | |
buildUI(cryptsyPrice); | |
}) | |
.fail(function () { | |
alert("Problem loading cryptsy data... (shocker)"); | |
return false; | |
}); | |
} | |
} | |
// load jQuery and execute the main function | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment