-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
99 lines (92 loc) · 3.79 KB
/
index.html
File metadata and controls
99 lines (92 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Duino Miner</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="code-effect">
<h1>Duino Miner</h1>
<label for="username">Username:</label>
<input type="text" id="username" value="Ashlad">
<br>
<label for="key">Key:</label>
<input type="text" id="key" value="None">
<br>
<div id="startStopButtons">
<button id="startButton" onclick="mine()">Start Mining</button>
<button id="stopButton" onclick="stopMine()" style="display: none">Stop Mining</button>
</div>
<br>
<label for="currenthash">Current Hash:</label>
<span id="currenthash"></span>
<br>
<label for="expectedhash">Expected Hash:</label>
<span id="expectedhash"></span>
<br>
<label for="difficulty">Difficulty:</label>
<span id="difficulty"></span>
<br>
<label for="status">Current status:</label>
<span id="status"></span>
<br>
<br>
<b>- Last job info -</b>
<br>
<label for="feedback">Feedback:</label>
<span id="feedback"></span>
<br>
<label for="validated">Final Status:</label>
<span id="validated"></span>
</div>
<script>
let worker = new Worker('miner-worker.js');
let currentuseragent = navigator.userAgent;
const username_ = document.getElementById("username");
const key_ = document.getElementById("key");
const currenthash = document.getElementById("currenthash");
const currentstatus = document.getElementById("status");
const expectedhash = document.getElementById("expectedhash");
const difficulty = document.getElementById("difficulty");
const validated = document.getElementById("validated");
const feedback = document.getElementById("feedback");
let miningStarted = false;
function mine() {
console.log(username_.value);
console.log(key_.value);
worker.postMessage({ username: username_.value, key: key_.value, userAgent: currentuseragent, action: "mine" });
startButton.style.display = "none";
stopButton.style.display = "inline-block";
miningStarted = true;
}
function stopMine() {
worker.postMessage({ username: username_.value, key: key_.value, userAgent: currentuseragent, action: "stop" });
startButton.style.display = "inline-block";
stopButton.style.display = "none";
currentstatus.innerHTML = "Stopped - (refresh to mine again)";
miningStarted = false;
worker.terminate();
}
worker.onmessage = function (message) {
let data = message.data.data
if (message.data.type == "progress") {
currenthash.innerHTML = data.lastHash;
currentstatus.innerHTML = data.status;
expectedhash.innerHTML = data.expected;
difficulty.innerHTML = data.diff
} else if (message.data.type == "result") {
validated.innerHTML = data.validated;
feedback.innerHTML = data.resp;
if (!miningStarted) {
startButton.style.display = "inline-block";
stopButton.style.display = "none";
}
} else if (message.data.type == "done") {
worker.postMessage({ username: username_.value, key: key_.value, action: "mine" });
} else if (message.data.type == "error") {
feedback.innerHTML = data.message;
}
}
</script>
</body>
</html>