lycan/js/main.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

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)
}
document.getElementById('generate').onclick = function(){
2020-09-28 01:02:48 +00:00
document.getElementById('generate').setAttribute("disabled", true)
document.getElementById('output').value = "computing..."
2020-09-28 08:24:00 +00:00
document.getElementById('timeResult').value = ""
document.getElementById('hashResult').value = ""
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()
}
// 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-28 01:02:48 +00:00
startTime = getEpoch()
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-28 08:24:00 +00:00