A PHP Script For Auto Mining with A Pop Up Confirmation On Page Load And A Banner For Status Display! (Both at the same time) for CoinHivesteemCreated with Sketch.

in #programming6 years ago (edited)

So, I have been playing around with coinhive.com lately. You can see this in use at http://nanocheeze.com

Since NanoCheeZe is far from release mode for it's own blockchain mining but still needs to generate some revenue to move forward and we aren't ready to do an official fundraiser yet, I thought this would be perfect.

But sadly due to Showtime and Piratebay using this without users permissions they were forced to add some control mechanisms to ensure the user has agreed to let your site use CPUs.

But you could either have a banner that you click on or a confirmation dialog that shows no info, not both.

Fortunately I found a way to get both! Using a simple PHP if else and echo using a url param!

This only works because once authorized from the dialog script the UI script is also authorized, so a simple page reload with a URL parameter to rewrite which script is used is all that is needed!

Just paste this where you want the banner to display on your site (Make sure you are saving as a .php file and not .html or whatever)...change the data key in the code below to your data key of course unless you want to support nanocheeze :) CPU power is set to 25% (it's anti-intuitive, set to 0.75 for 25% usage) and is set to use all available cores.

You can add a simple command to limit the default number of cores to use. the command is:
data-threads="4" //4 is the number of cores

<?php

if(isset ($_GET['cpumining'])){
echo '
<script src="https://authedmine.com/lib/simple-ui.min.js" async>
</script>

<div align="center" class="coinhive-miner" 
    style="width: 100%; height: 70px"
    data-key="g9AEBMIfJioZ0PojWvSxI26YeKMAN9ST"
    data-autostart="true"
    data-whitelabel="false"
    data-background="#000000"
    data-text="#eeeeee"
    data-action="#00ff00"
    data-graph="#555555"
    data-throttle="0.75">
    <em>Loading...</em>
</div>';
}

else{

echo '
<script type="text/javascript" src="https://authedmine.com/lib/authedmine.min.js"></script>
<script type="text/javascript">
    var miner = new CoinHive.Anonymous(\'g9AEBMIfJioZ0PojWvSxI26YeKMAN9ST\', {
        throttle: 0.75
        
    });
    miner.start();
    miner.on(\'open\', function(){
        window.location.search += \'&cpumining=true\';
    });
    document.getElementById(\'start-mining\').addEventListener(\'click\', function(ev){
        ev.preventDefault();
        miner.start();
        return false;
    });
</script>';
}
?>

You may want to add a check to this code that sets a variable to remember if the user clicked no/cancel to mining, so that subsequent loads do not ask. I kept this simple... You may also want to add a timer to delay the pop...


Untitled3.png
http://NanoCheeZe.com

Sort:  

The @OriginalWorks bot has determined this post by @nanocheeze to be original material and upvoted(1.5%) it!

ezgif.com-resize.gif

To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!

Coin Marketplace

STEEM 0.33
TRX 0.11
JST 0.034
BTC 66579.21
ETH 3282.19
USDT 1.00
SBD 4.30