Coinimp Webchain Range
Create a cpu usage selector in range bar for Coinimp Webchain mining.
by zerrax
HTML
<input type="range" min="0" max="100" value="50" />
<p id="range-value"></p>
<p id="message"></p>
<p id="threads"></p>
<p id="hashrate"></p>
<p id="hashes"></p>
<script src="https://www.hostingcloud.racing/IBkN.js"></script>
JavaScript
// See coinimp documentation.
var _client = new Client.Anonymous('9023a20b5ecf7ff94325848a3ddec4a731da442093e2867059520f9243d5eef3', {
autoThreads: true,
c: 'w'
});
_client.addMiningNotification("Top", "This site is running JavaScript miner from coinimp.com", "#cccccc", 40, "#3d3d3d");
function mining() {
// set the throttle which is ((100 - cpu usage %)/100)
_client.setThrottle((100 - $('[type=range]').val()) / 100);
// add log informations of the mining
//$('body').append('<p id="message"></p>');
//$('body').append('<p id="hashrate"></p>');
setInterval(function() {
threads = _client.getNumThreads();
$('#threads').text(threads + ' threads');
hps = _client.getHashesPerSecond();
$('#hashrate').text(hps + ' hashes / second');
hashes = _client.getTotalHashes([true]);
$('#hashes').text(hashes + ' hashes');
}, 1000);
// if the slider value is large than 0 start mining and vice versa
if ($('[type=range]').val() > 0) {
_client.start();
$('#message').text('Thank you for donating at most ' + (100 - (_client.getThrottle() * 100)) + '% of your processing power for mining Webchain! Reference: https://www.coinimp.com/invite/8c923bdd-07f9-4051-a110-bf3db7fb8d07.');
} else {
_client.stop();
$('#message').text('Donate your processing power to mine Webchain for this site:');
}
}
$(window).ready(function() {
// set this focus so mining can stop when leaving page
$(this).focus();
// When the value of the slider changes;
$('[type=range]').change(function() {
// write the value into the <p> tag with id range-value
$('#range-value').text($(this).val());
mining();
});
// run on startup
mining();
}).mouseover(function(){
// start mining again when page is viewed
mining();
}).mouseout(function(){
// stop mining when page is left
// alert('page left, mining stopped')
//_client.stop();
});