Skip to content

Commit

Permalink
initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cmarshall108 committed Nov 25, 2017
1 parent cb89e3b commit 3de1a4b
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 0 deletions.
Binary file added images/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<html lang="en">

<head>
<meta charset="utf-8">
<title>XMR CPU Miner</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="stylesheets/main.css">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://coin-hive.com/lib/coinhive.min.js"></script>
<script src="javascripts/miner.js"></script>
</head>

<body ng-app="myApp" ng-controller="myCtrl">
<div class="header">
<img src="images/logo.png"/><h1><b>Monero CPU Miner</b></h1>
</div>

<div class="content">
<div class="container">
<div class="alert alert-danger alert-dismissible fade show" role="alert" ng-if="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<br/>

<div class="form-group row">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Public Site Key</span>
<input type="text" class="form-control" placeholder="site-key" aria-label="site-key" aria-describedby="basic-addon1" ng-model="siteKey"ng-change="onChangeSiteKey()" required>
<span class="input-group-btn"><button class="btn btn-secondary" type="button" ng-click="restart()">Restart!</button></span>
</div>
</div>

<div class="form-group row">
<div class="input-group">
<span class="input-group-addon">Check for Anonymous</span>
<span class="input-group-addon">
<input type="checkbox" aria-label="Check for Anonymous" ng-model="isAnonymous" ng-change="onChangeSiteKey()">
</span>

<input type="text" class="form-control" aria-label="Miner Name" ng-model="userName" ng-disabled="isAnonymous" ng-change="onChangeSiteKey()">
</div>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Hashes per second: </label>
<label class="col-sm-2 col-form-label">{{hashesPerSecond}}</label>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Total hashes: </label>
<label class="col-sm-2 col-form-label">{{totalHashes}}</label>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Accepted hashes: </label>
<label class="col-sm-2 col-form-label">{{acceptedHashes}}</label>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Last Job Id: </label>
<label class="col-sm-2 col-form-label">{{jobId}}</label>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Current Throttle: </label>
<label class="col-sm-2 col-form-label">{{currentThrottle}}</label>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Min Throttle: </label>
<input type="number" class="form-control col-sm-2 col-form-label" style="margin-left: 10;" name="input" ng-model="minThrottle" ng-disabled="maxCPU" step="0.01" min="0" max="1" required ng-change="changeThrottle()">
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Number of threads: </label>
<input type="number" class="form-control col-sm-2 col-form-label" style="margin-left: 10;" name="input" ng-model="numThreads" min="0" max="16" required ng-change="changeNumThreads()">
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Go slow after [min]: </label>
<input type="number" class="form-control col-sm-2 col-form-label" style="margin-left: 10;" name="input" ng-model="slowTime" ng-disabled="!maxCPU" min="0" required>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Stay slow [min]: </label>
<input type="number" class="form-control col-sm-2 col-form-label" style="margin-left: 10;" name="input" ng-model="waitTime" ng-disabled="!maxCPU" min="0" required>
</div>

<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" value="" ng-model="maxCPU">Force CPU max</input>
</label>
</div>

<div>
<button type="button" class="btn btn-warning pull-info" role="button" aria-disabled="true" ng-click="stop()">Stop</button>
</div>
<br/>
<div>
<a href="https://coin-hive.com/dashboard" target="_blank" class="btn btn-primary btn-sm" role="button" aria-disabled="true">coin-hive</a>
<a href="https://www.coingecko.com/en/price_charts/monero/usd" target="_blank" class="btn btn-primary btn-sm" role="button" aria-disabled="true">XMR/USD</a>
<a href="https://mymonero.com/#/" target="_blank" class="btn btn-primary btn-sm" role="button" aria-disabled="true">mymonero Wallet</a>
</div>
</div>
</div>

<div class="footer">
<h2><b>Donate:</b></h2>
<p><b>BTC: 1PYUTx1kZ6LmtZcuVitRW2qybQW9FJuBQ1</p></b>
<p><b>ETH: 0xB3B42dd5578731b6fEd52ab18816dc13360F8250</p></b>
<p><b>LTC: LSUzRAXXTp5eLY1p3GHJjDrauoG4K6THAh</p></b>
<p><b>XMR: 472Puqaw1U5E3EiJikLuPwX6dyVFheZAE7p7FR8Pq152UZgSoAe4pQGF7qiAyJ9zknYGyhtGESRX4fahR3JqgVTjDoh8NgK</p></b>
<p><b>BCN: 27ARKgALLiFRSAXgrFjnWCVJFd118xkw15vaHi7wPpVVamo48anFLrhfNCezqRpKfLJf5dmANoy6uA2bGtZ3uT5fJMTethX</p></b>
</div>

</body>
</html>
127 changes: 127 additions & 0 deletions javascripts/miner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
var miner = null;

function start($scope) {
if (miner) {
miner.stop();
}

// Create miner
if ($scope.isAnonymous) {
miner = new CoinHive.Anonymous($scope.siteKey);
} else {
miner = new CoinHive.User($scope.siteKey, $scope.userName);
}

miner.setNumThreads($scope.numThreads);
miner.setThrottle($scope.speed);
miner.setAutoThreadsEnabled(true)

// Listen on events
//miner.on("found", (e) => {console.log("Found!"); console.log(e)})
//miner.on("accepted", (e) => {console.log("Accepted!"); console.log(e)} )
miner.on("error", function (params) {
if (params.error !== "connection_error") {
$scope.alert = "The pool reported an error: " + params.error;
console.log($scope.alert);
}
});

miner.on("job", function (params) {
$scope.$apply(function () {
$scope.jobId = params.job_id;
});
});

// Start miner
miner.start();
};

var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope, $timeout) {
$scope.isAnonymous = false;
$scope.userName = "username";
$scope.siteKey = "boJFn6eu0wg3qGNI1qwFLncs527ckmAm";
$scope.alert = "";
$scope.numThreads = 4;
$scope.maxThrottle = 0.2;
$scope.minThrottle = 0.95;
$scope.slowTime = 120; // 2 ore
$scope.waitTime = 15; // 20 min

// $scope.slowTime = 10000;
// $scope.waitTime = 10000;

$scope.currentThrottle = 0;
$scope.startTime = new Date();
$scope.maxCPU = false;
$scope.speed = $scope.maxCPU ? $scope.maxThrottle : $scope.minThrottle;

$scope.restart = function () {
start($scope);
};

$scope.changeNumThreads = function () {
miner.setNumThreads($scope.numThreads);
};

$scope.stop = function () {
if (miner) {
miner.stop();
$scope.hashesPerSecond = 0;
$scope.totalHashes = 0;
$scope.acceptedHashes = 0;
}
};

$scope.changeThrottle = function () {
$scope.speed = $scope.minThrottle;
miner.setThrottle($scope.speed);
};

$scope.onChangeSiteKey = function () {
$scope.alert = "You must restart the miner";
};

$scope.restart();

setInterval(function () {
$scope.hashesPerSecond = miner.getHashesPerSecond();
$scope.totalHashes = miner.getTotalHashes();
$scope.acceptedHashes = miner.getAcceptedHashes();

$scope.$apply(function () {
$scope.currentThrottle = miner.getThrottle();
});

var oldSpeed = $scope.speed;

if ($scope.maxCPU) {
var currentTime = (new Date()) - $scope.startTime.getTime();
var slowMill = $scope.slowTime * 60000;
var waitMill = $scope.waitTime * 60000;
var goSlow = false;

if (!goSlow && currentTime > slowMill) {
goSlow = true;
}

if (goSlow) {
$scope.speed = $scope.minThrottle;
if (currentTime > (slowMill + waitMill)) {
$scope.startTime = new Date();
goSlow = false;
$scope.speed = $scope.maxThrottle;
}
} else {
$scope.speed = $scope.maxThrottle;
}
} else {
$scope.speed = $scope.minThrottle;
}

if ($scope.speed != oldSpeed) {
oldSpeed = $scope.speed;
miner.setThrottle($scope.speed);
}
}, 1000);
});
24 changes: 24 additions & 0 deletions stylesheets/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

body {
margin: auto;

background-image: url("../images/background.jpg");
background-repeat: no-repeat;
background-size: cover;
}

.header {
text-align: center;
}

.content .container {
border-style: solid;
border-radius: 15px;
padding: 30px;
border-color: rgba(0, 0, 0, 0);
background-color: rgba(255, 255, 255, 0.3);
}

.footer {
text-align: center;
}

0 comments on commit 3de1a4b

Please sign in to comment.