forked from blockchain/unused-My-Wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firefox.js
111 lines (80 loc) · 3.1 KB
/
firefox.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
min = false;
isExtension = true;
APP_NAME = 'javascript_firefox';
var superSetLanguage = MyWallet.setLanguage;
MyWallet.setLanguage = function(language) {
if (MyWallet.getLanguage()) {
superSetLanguage(language);
MyWallet.makeNotice('success', 'misc-success', 'Changing Language ' + language + '. Please Wait...');
setTimeout(function() {
window.location.href = '/blockchain/data/index.html';
}, 1000);
} else {
superSetLanguage(language);
}
}
var initd = false;
var requests = {};
$.ajax = function(obj) {
function sendRequest(obj) {
var customEvent = document.createEvent('Event');
customEvent.initEvent('ajax_request', true, true);
if (Object.keys(requests).length == 0) {
$(document).trigger("ajaxStart");
}
var request_id = ''+Math.floor((Math.random()*10000)+1);
requests[request_id] = obj;
obj.request_id = request_id;
console.log('Send Request ID : ' + obj.request_id);
document.body.setAttribute('data-ajax-request', JSON.stringify(obj));
document.body.dispatchEvent(customEvent);
}
if (!initd) {
initd = true;
$(document.body).on('ajax_response', function() {
console.log(document.body.getAttribute('data-ajax-response'));
var obj = JSON.parse(document.body.getAttribute('data-ajax-response'));
console.log('Got Request ID : ' + obj.request_id);
try {
var request = requests[obj.request_id];
if (request == null) {
throw 'Unknown Request ID ' + obj.request_id;
}
if (obj.status == 200) {
if (obj.dataType == 'json') {
try {
request.success(JSON.parse(obj.response));
} catch (e) {
request.error({responseText : e.toString(), status : obj.status});
}
} else {
request.success(obj.response);
}
} else {
request.error({responseText : obj.response, status : obj.status});
}
delete requests[obj.request_id];
} catch (e) {
console.log(e);
}
if (Object.keys(requests).length == 0) {
$(document).trigger("ajaxStop");
}
});
}
sendRequest(obj);
};
$(document).ready(function() {
var body = $(document.body);
var data_root = body.data('root');
if (data_root)
root = data_root;
var data_resource = body.data('resource');
if (data_resource) {
var path = document.location.pathname;
var index = path.lastIndexOf("/") + 1;
var filename = path.substr(0, index);
resource = filename + data_resource;
}
$('head').append('<style type="text/css">.external { background: url('+resource+'external.png); }\n span.qrcodeicon span { background: url("'+resource+'qrcode.png"); };</style>');
});