2020-09-27 18:07:18 +00:00
|
|
|
var worker = new Worker("./powworker.js")
|
|
|
|
|
2020-09-28 01:02:48 +00:00
|
|
|
var startTime = 0;
|
|
|
|
|
|
|
|
function getEpoch(){
|
|
|
|
return Math.floor((new Date).getTime()/1000)
|
|
|
|
}
|
|
|
|
|
2020-09-27 18:07:18 +00:00
|
|
|
document.getElementById('generate').onclick = function(){
|
2020-09-28 01:02:48 +00:00
|
|
|
document.getElementById('generate').setAttribute("disabled", true)
|
2020-09-27 18:07:18 +00:00
|
|
|
document.getElementById('output').value = "computing..."
|
2020-09-28 08:24:00 +00:00
|
|
|
document.getElementById('timeResult').value = ""
|
|
|
|
document.getElementById('hashResult').value = ""
|
2020-09-27 18:07:18 +00:00
|
|
|
var metadata = {
|
2020-09-28 08:24:00 +00:00
|
|
|
"meta": JSON.stringify({
|
2020-09-28 01:02:48 +00:00
|
|
|
"type": document.getElementById("type").value
|
2020-09-28 08:24:00 +00:00
|
|
|
}),
|
2020-09-28 01:02:48 +00:00
|
|
|
"time": getEpoch()
|
2020-09-27 18:07:18 +00:00
|
|
|
}
|
|
|
|
// todo web workers
|
|
|
|
var data = document.getElementById('message').value
|
|
|
|
var postData = {
|
|
|
|
"data": data,
|
|
|
|
"metadata": metadata,
|
2020-09-28 01:02:48 +00:00
|
|
|
"difficulty": parseInt(document.getElementById("difficulty").value)
|
2020-09-27 18:07:18 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 01:02:48 +00:00
|
|
|
startTime = getEpoch()
|
2020-09-27 18:07:18 +00:00
|
|
|
worker.postMessage(JSON.stringify(postData))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
worker.addEventListener('message', function(e) {
|
2020-09-28 01:02:48 +00:00
|
|
|
var finishTime = getEpoch() - startTime
|
|
|
|
document.getElementById('generate').removeAttribute("disabled")
|
2020-09-28 08:24:00 +00:00
|
|
|
document.getElementById('hashResult').value = doHashHex(e.data)
|
2020-09-28 01:02:48 +00:00
|
|
|
document.getElementById('timeResult').value = finishTime + "s"
|
2020-09-28 08:24:00 +00:00
|
|
|
document.getElementById('output').value = new TextDecoder("utf-8").decode(e.data)
|
|
|
|
|
|
|
|
let a = document.getElementById('download')
|
|
|
|
var file = new Blob([e.data], {type: type})
|
|
|
|
a.href = URL.createObjectURL(file)
|
|
|
|
a.download = document.getElementById('hashResult').value + ".onionr"
|
2020-09-27 18:07:18 +00:00
|
|
|
})
|
2020-09-28 08:24:00 +00:00
|
|
|
|