-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
241 lines (193 loc) · 9.36 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DigiDigger</title>
</head>
<body>
<link rel="stylesheet" type="text/css" href="chartist.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" media="screen and (min-width: 822px)" href="style_big.css">
<link rel="stylesheet" type="text/css" media="screen and (max-width: 821px)" href="style_small.css">
<div id="top">DigiDigger - Pot: <span id="pot">Loading</span>**</div>
<button id="openMenu">Menu</button>
<img id="search" src="dig.png">
<div id="fund">
<button id="closeMenu">Play Game</button>
<h3>Guesses Left:</h3>
<span id="guess">0</span> <button id="addFunds">Buy</button><br>
<h3>Winnings:</h3>
<span id="win">0.00000000</span>DGB<br>
<h3>Payout Wallet:</h3>
<input type="text" id="wallet" value=""><br>
<h3>Instructions:</h3>
Enter a DigiByte address in the payout box. Add some funds to the game and then start guessing where in the picture the funds are hidden. If you find any they will be sent to the address provided.<br>When you add funds they are randomly scatered over the image. Every minute funds move to new locations.
<h3>Notes:</h3>
*Warning closing app will lose outstanding guesses if you don't know recovery phrase.<br>
**Pot total updated every 5min.
</div>
<div id="info">
<div class="infoPart oddsLink">Odds: <span id="infoOdds">Loading</span></div>
<div class="infoPart">Pot: <span id="infoPot">Loading</span></div>
<div class="infoPart">Jackpot: <span id="infoBig">Loading</span></div>
<div id="infoWinner">Winnings: <span id="infoWin">0.00000000 DGB</span></div>
</div>
</div>
<div id="shadow"></div>
<div id="window_loading" class="window">
Loading
</div>
<div id="window_setWallet" class="window">
Please set payout wallet address.<br>
<button class="close">Close</button><br>
</div>
<div id="window_buy" class="window">
<h1>Send DigiByte to:</h1>
Recovery Phrase: <input id="recovery" type="text"><br>
<img id="fundAddress"><br>
<span id="payAddress"></span><br>
You will receive 1 dig per DigiByte sent.<br>
<div id="buyOddsLink" class="oddsLink">Click for Odds of Winning</div>
<button class="close">Close(Will auto close when funds received)</button><br>
</div>
<div id="window_graph" class="window">
<h1>Odds of Winning:</h1>
<div id="oddsGraph"></div>
<button class="close">Close</button><br>
</div>
<div id="window_error" class="window">
<h1>Error:</h1>
<div id="errorMessage"></div>
<input id="errorClose" type="button" class="close" value="OK">
</div>
<script src="libraries.min.js?v1.1"></script>
<script src="DigiDigger.js"></script>
<script>
//Window System
var domShadow=document['getElementById']('shadow');
var closeWindows=function(shadow) {
var windows=document['getElementsByClassName']('window'); //get all windows
for (var i=0; i<windows['length']; i++) { //go through each window
windows[i]['style']['display']='none'; //make window invisible
}
if (shadow===true) domShadow['style']['display']='none'; //close shadow if set
fundF=false;
}
var openWindow=function(windowType) {
closeWindows(); //close all windows
document['getElementById']("window_"+windowType)['style']['display']='block'; //open the window associated with button pressed
domShadow['style']['display']='block'; //open shadow
}
var domClose=document.getElementsByClassName("close"); //get all dom items using class next
for (var i=0; i<domClose.length; i++) { //go through each dom element with class "next"
domClose[i].addEventListener('click', function() {closeWindows(true)}, false); //attach click listener to execute closeWindows function
}
var error=function(message){ //error handling function
document.getElementById('errorMessage').innerHTML=message; //set error message
openWindow('error'); //show error window
};
//Handle fund adding
var brainString="",
domQR=document.getElementById('fundAddress');
for (var i=0;i<3;i++) {
var part=bip39.english[Math.floor(Math.random()*2048)]; //pick a random word from list
brainString+=part.charAt(0).toUpperCase()+part.slice(1); //make first letter upper case and add to string
}
brainString+=Math.floor(Math.random()*999); //add up to 3 random digits to initial brain string
var domRecovery=document.getElementById('recovery'); //get recovery phrase input dom item
domRecovery.value=brainString; //set recovery phrase
var changePhrase=function() {
DigiDigger.setUserPhrase(domRecovery.value);
var fundA=DigiDigger.getUserAddress();
domQR.src=DigiQR.request(fundA,1,240,6,1); //generate qr code
document.getElementById('payAddress').innerHTML=fundA; //show address
}
changePhrase();
domRecovery.addEventListener('change',function() { //wait for change in recovery phrase
document.getElementById('payAddress').innerHTML='Please Wait'; //show message to let others know qr is bad
setTimeout(changePhrase,10); //short delay so ui can catch up then make brain wallet
});
var recoveryDelay=setTimeout(changePhrase,10); //prevents an error
domRecovery.addEventListener('keyup',function() { //wait for key to be released
document.getElementById('payAddress').innerHTML='Please Wait'; //show message to let others know qr is bad
clearInterval(recoveryDelay); //stop the last timer
recoveryDelay=setTimeout(changePhrase,500); //start timer so we dont kill processor while user is typing
});
domQR.addEventListener('click',function() { //wait for qr code clicks
window.open('digibyte:'+DigiDigger.getUserAddress()); //open users wallet
});
document.getElementById('addFunds').addEventListener('click',function(){
openWindow('buy');
}); //add click listener to buy button
//Handle user address and menu interactions
var domOpenMenu=document.getElementById('openMenu');
var domCloseMenu=document.getElementById('closeMenu');
var domMenu=document.getElementById('fund');
var smallScreen=(window.getComputedStyle(domOpenMenu).display!="none"); //Check if small css file
domOpenMenu.style.display="none"; //hide open menu button
var domWallet=document.getElementById('wallet');
domWallet.addEventListener('change',function() { //watch for changes to payout wallet
var newAddress=domWallet.value.trim(); //remove any white space from address
try {
DigiDigger.setUserPayout(newAddress);
if (smallScreen) domCloseMenu.style.display="block"; //if small screen make close menu button visible
domWallet.style.backgroundColor="#ffffff"; //set input field background to white
} catch(e) {
domCloseMenu.display="none"; //hide close menu
domWallet.style.backgroundColor="#ff3333"; //set input fields background to light red
}
});
domCloseMenu.addEventListener('click',function() { //listen for close menu click
domMenu.style.display="none"; //hide menu
domOpenMenu.style.display="block"; //show open menu button
});
domOpenMenu.addEventListener('click',function() { //listen for open menu click
domMenu.style.display="block"; //show menu
domOpenMenu.style.display="none"; //hide open menu button
});
//handle clicks on oddsLink class items
var oddsLinkObjects=document.getElementsByClassName('oddsLink'); //make list of all objects with class oddsLink
for (var i=0;i<oddsLinkObjects.length;i++) { //go through each .oddsLink object
oddsLinkObjects[i].addEventListener('click',function(){ //add click listener
if (DigiDigger.getPot()!=false) { //see if stats have been downloaded
openWindow('graph'); //show graph
DigiDigger.drawChart('oddsGraph'); //redraw graph
} else {
error('Odd of winning stats not yet loaded'); //show error message since we don't have stats yet
}
});
}
//Handle update of winnings when dig ends
DigiDigger.bindDigEnd(function(x,y,won){
var winnings=DigiDigger.getWins().toFixed(8)+" DGB";
document.getElementById('infoWin').innerHTML=winnings;
document.getElementById('win').innerHTML=winnings;
});
//Handle update of balance
DigiDigger.bindBalanceChange(function(balance){
document.getElementById('guess').innerHTML=Math.floor(balance)+" DGB";
closeWindows(true);
});
//Handle DigiDigger Errors
DigiDigger.bindDigError(function(errorStr){
if (errorStr=="No Funds") {
openWindow('buy');
} else if (errorStr=="No Payout Address") {
openWindow('setWallet');
} else {
error(errorStr);
}
});
//Handle odds update
DigiDigger.bindOddsUpdate(function(odds,pot,jackpot){
document.getElementById('infoOdds').innerHTML=odds.toFixed(1)+"%";
document.getElementById('infoPot').innerHTML=pot.toFixed(2)+" DGB";
document.getElementById('pot').innerHTML=pot.toFixed(2)+" DGB";
document.getElementById('infoBig').innerHTML=jackpot.toFixed(2)+" DGB";
});
//start the game
DigiDigger.startGame('search');
//open fund window
openWindow('buy');
</script>
</body>
</html>