-
-
Notifications
You must be signed in to change notification settings - Fork 771
/
web3alert.js
45 lines (37 loc) · 1.28 KB
/
web3alert.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
var _alert = function(msg, addClassName) {
var existing_alerts = document.getElementsByClassName('alert_msg');
for (var i = 0; i < existing_alerts.length; i++) {
var top = parseInt(existing_alerts[i].style.top.replace('px', ''));
if (isNaN(top)) {
top = 0;
}
existing_alerts[i].style.top = top + 25 + 'px';
}
var para = document.createElement('p');
para.className = 'alert_msg ' + addClassName;
var element = document.body;
element.appendChild(para);
para.innerHTML = msg['message'];
var callback = function() {
para.parentNode.removeChild(para);
};
setTimeout(callback, 5000);
};
var metaMaskWarning = function() {
if (typeof web3 == 'undefined' || !web3.currentProvider || !web3.currentProvider.isMetaMask) {
if (typeof document.suppressweb3alert != 'undefined') {
_alert({ message: gettext('You must install <a href=https://metamask.io/>Metamask</a> to use this tool.') }, 'info');
}
return true;
} else if (web3.eth.accounts.length == 0) {
_alert({ message: gettext('Please unlock Metamask.') }, 'info');
return true;
}
return false;
};
setTimeout(metaMaskWarning, 1000);
var metaMaskWarningRecurr = function() {
metaMaskWarning();
setTimeout(metaMaskWarningRecurr, 5000);
};
setTimeout(metaMaskWarningRecurr, 6000);