-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathninja.misc.js
145 lines (127 loc) · 4.54 KB
/
ninja.misc.js
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
(function (ninja) {
var status = ninja.status = function() {
var cryptoCase = "";
if (window.crypto && window.crypto.getRandomValues) {
document.getElementById("statuscrypto").innerHTML = "✔"; //✔
cryptoCase = "good";
}
else {
document.getElementById("statuscrypto").innerHTML = "×"; //×
cryptoCase = "bad";
}
var protocolCase = "";
switch (window.location.protocol) {
case 'file:':
document.getElementById("statusprotocol").innerHTML = "✔"; //✔
protocolCase = "good";
break;
case 'http:':
case 'https:':
document.getElementById("statusprotocol").innerHTML = "⚠"; //⚠
protocolCase = "bad";
break;
default:
}
var unitTestsCase = "";
var unitTests = function () {
var result = ninja.unitTests.runSynchronousTests();
if (result.passCount == result.testCount) {
document.getElementById("statusunittests").innerHTML = "✔"; //✔
unitTestsCase = "good";
}
else {
document.getElementById("statusunittests").innerHTML = "×"; //×
unitTestsCase = "bad";
}
};
var showCrypto = function () {
document.getElementById('statuscrypto' + cryptoCase).style.display = 'block';
};
var showProtocol = function () {
document.getElementById('statusprotocol' + protocolCase).style.display = 'block';
};
var showUnitTests = function () {
if(unitTestsCase != "") document.getElementById('statusunittests' + unitTestsCase).style.display = 'block';
};
var showKeyPool = function () {
document.getElementById('statuskeypoolgood').style.display = 'block';
document.getElementById("keypooltextarea").value = Bitcoin.KeyPool.toString();
};
return {
unitTests: unitTests, showCrypto: showCrypto, showProtocol: showProtocol,
showUnitTests: showUnitTests, showKeyPool: showKeyPool
};
}();
})(ninja);
ninja.tab = {
select: function (walletTab) {
// detect type: normally an HtmlElement/object but when string then get the element
if (typeof walletTab === 'string') {
walletTab = document.getElementById(walletTab);
}
var walletType = walletTab.getAttribute("id");
if (walletTab.className.indexOf("selected") == -1) {
// unselect all tabs
for (var wType in ninja.wallets) {
document.getElementById(wType).className = "tab";
ninja.wallets[wType].close();
}
// don't open tab if entropy still being collected
// exceptions: brainwallet detailwallet
if (ninja.seeder.isStillSeeding == false || walletType == "brainwallet" || walletType == "detailwallet") {
walletTab.className += " selected";
document.getElementById("generate").style.display = "none";
ninja.wallets[walletTab.getAttribute("id")].open();
}
else if (ninja.seeder.isStillSeeding == true && !(walletType == "brainwallet" || walletType == "detailwallet")) {
document.getElementById("generate").style.display = "block";
}
}
},
whichIsOpen: function () {
var isOpen;
for (var wType in ninja.wallets) {
isOpen = ninja.wallets[wType].isOpen();
if (isOpen) {
return wType;
}
}
return null;
}
};
ninja.getQueryString = function () {
var result = {}, queryString = location.search.substring(1), re = /([^&=]+)=([^&]*)/g, m;
while (m = re.exec(queryString)) {
result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
return result;
};
// use when passing an Array of Functions
ninja.runSerialized = function (functions, onComplete) {
onComplete = onComplete || function () { };
if (functions.length === 0) onComplete();
else {
// run the first function, and make it call this
// function when finished with the rest of the list
var f = functions.shift();
f(function () { ninja.runSerialized(functions, onComplete); });
}
};
ninja.forSerialized = function (initial, max, whatToDo, onComplete) {
onComplete = onComplete || function () { };
if (initial === max) { onComplete(); }
else {
// same idea as runSerialized
whatToDo(initial, function () { ninja.forSerialized(++initial, max, whatToDo, onComplete); });
}
};
// use when passing an Object (dictionary) of Functions
ninja.foreachSerialized = function (collection, whatToDo, onComplete) {
var keys = [];
for (var name in collection) {
keys.push(name);
}
ninja.forSerialized(0, keys.length, function (i, callback) {
whatToDo(keys[i], callback);
}, onComplete);
};