forked from emn178/solidity-optimize-name
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (43 loc) · 1.18 KB
/
app.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
(function ($) {
function parseSignature(signature) {
if (signature.charAt(signature.length - 1) != ')' || signature.indexOf(' ') !== -1) {
return false;
}
var parts = signature.split('(');
if (parts.length == 2) {
return {
name: parts[0],
args: '(' + parts[1]
};
} else {
return false;
}
}
$(document).ready(function () {
if (!window.Worker) {
$('#error').html("your browser does not support workers")
$('#error').show();
return
}
const worker = new Worker("worker.js");
$('#optimize').click(function () {
var input = $('#input').val().replaceAll(" ", "");
var after = $('#after').val();
var data = parseSignature(input);
if (!data) {
$('#error').show();
return;
}
$('#error').hide();
$('#optimize').prop("disabled", true);
$('#loader').show();
worker.postMessage([data, after])
});
worker.onmessage = function (e) {
$('#after').val(e.data[1])
$('#output').append('<p>' + e.data[0] + ': 0x' + e.data[1] + '</p>')
$('#loader').hide();
$('#optimize').prop("disabled", false);
}
});
})(jQuery);