Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ultraviolet
GitHub Repository: ultraviolet/bitaddress.org
Path: blob/master/src/ninja.misc.js
248 views
1
(function (ninja) {
2
var status = ninja.status = function() {
3
var cryptoCase = "";
4
if (window.crypto && window.crypto.getRandomValues) {
5
document.getElementById("statuscrypto").innerHTML = "✔"; //✔
6
cryptoCase = "good";
7
}
8
else {
9
document.getElementById("statuscrypto").innerHTML = "×"; //×
10
cryptoCase = "bad";
11
}
12
13
var protocolCase = "";
14
switch (window.location.protocol) {
15
case 'file:':
16
document.getElementById("statusprotocol").innerHTML = "✔"; //✔
17
protocolCase = "good";
18
break;
19
case 'http:':
20
case 'https:':
21
document.getElementById("statusprotocol").innerHTML = "⚠"; //⚠
22
protocolCase = "bad";
23
break;
24
default:
25
}
26
27
var unitTestsCase = "";
28
var unitTests = function () {
29
var result = ninja.unitTests.runSynchronousTests();
30
if (result.passCount == result.testCount) {
31
document.getElementById("statusunittests").innerHTML = "✔"; //✔
32
unitTestsCase = "good";
33
}
34
else {
35
document.getElementById("statusunittests").innerHTML = "×"; //×
36
unitTestsCase = "bad";
37
}
38
};
39
40
var showCrypto = function () {
41
document.getElementById('statuscrypto' + cryptoCase).style.display = 'block';
42
};
43
44
var showProtocol = function () {
45
document.getElementById('statusprotocol' + protocolCase).style.display = 'block';
46
};
47
48
var showUnitTests = function () {
49
if(unitTestsCase != "") document.getElementById('statusunittests' + unitTestsCase).style.display = 'block';
50
};
51
52
var showKeyPool = function () {
53
document.getElementById('statuskeypoolgood').style.display = 'block';
54
document.getElementById("keypooltextarea").value = Bitcoin.KeyPool.toString();
55
};
56
57
return {
58
unitTests: unitTests, showCrypto: showCrypto, showProtocol: showProtocol,
59
showUnitTests: showUnitTests, showKeyPool: showKeyPool
60
};
61
}();
62
})(ninja);
63
64
ninja.tab = {
65
select: function (walletTab) {
66
// detect type: normally an HtmlElement/object but when string then get the element
67
if (typeof walletTab === 'string') {
68
walletTab = document.getElementById(walletTab);
69
}
70
var walletType = walletTab.getAttribute("id");
71
72
if (walletTab.className.indexOf("selected") == -1) {
73
// unselect all tabs
74
for (var wType in ninja.wallets) {
75
document.getElementById(wType).className = "tab";
76
ninja.wallets[wType].close();
77
}
78
79
// don't open tab if entropy still being collected
80
// exceptions: brainwallet detailwallet
81
if (ninja.seeder.isStillSeeding == false || walletType == "brainwallet" || walletType == "detailwallet") {
82
walletTab.className += " selected";
83
document.getElementById("generate").style.display = "none";
84
ninja.wallets[walletTab.getAttribute("id")].open();
85
}
86
else if (ninja.seeder.isStillSeeding == true && !(walletType == "brainwallet" || walletType == "detailwallet")) {
87
document.getElementById("generate").style.display = "block";
88
}
89
}
90
},
91
92
whichIsOpen: function () {
93
var isOpen;
94
for (var wType in ninja.wallets) {
95
isOpen = ninja.wallets[wType].isOpen();
96
if (isOpen) {
97
return wType;
98
}
99
}
100
return null;
101
}
102
103
};
104
105
ninja.getQueryString = function () {
106
var result = {}, queryString = location.search.substring(1), re = /([^&=]+)=([^&]*)/g, m;
107
while (m = re.exec(queryString)) {
108
result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
109
}
110
return result;
111
};
112
113
// use when passing an Array of Functions
114
ninja.runSerialized = function (functions, onComplete) {
115
onComplete = onComplete || function () { };
116
117
if (functions.length === 0) onComplete();
118
else {
119
// run the first function, and make it call this
120
// function when finished with the rest of the list
121
var f = functions.shift();
122
f(function () { ninja.runSerialized(functions, onComplete); });
123
}
124
};
125
126
ninja.forSerialized = function (initial, max, whatToDo, onComplete) {
127
onComplete = onComplete || function () { };
128
129
if (initial === max) { onComplete(); }
130
else {
131
// same idea as runSerialized
132
whatToDo(initial, function () { ninja.forSerialized(++initial, max, whatToDo, onComplete); });
133
}
134
};
135
136
// use when passing an Object (dictionary) of Functions
137
ninja.foreachSerialized = function (collection, whatToDo, onComplete) {
138
var keys = [];
139
for (var name in collection) {
140
keys.push(name);
141
}
142
ninja.forSerialized(0, keys.length, function (i, callback) {
143
whatToDo(keys[i], callback);
144
}, onComplete);
145
};
146