1(function () { 2 async function sha256(input) { 3 const buffer = await crypto.subtle.digest( 4 "SHA-256", 5 new TextEncoder().encode(input) 6 ); 7 8 return Array.from(new Uint8Array(buffer), byte => 9 byte.toString(16).padStart(2, "0") 10 ).join(""); 11 } 12 13 async function sha256Nested(input, rounds = 64) { 14 let hash = input; 15 16 for (let i = 0; i < rounds; i++) { 17 hash = await sha256(hash); 18 } 19 20 return hash; 21 } 22 23 function loadToken(input, onDone, silent) { 24 var done = function () { if (onDone) { onDone(); onDone = null; } }; 25 if (!silent) input.value = "init"; 26 var url = input.getAttribute("data-token-url"); 27 if (!url) { 28 done(); 29 return; 30 } 31 32 if (!silent) input.value = "loading"; 33 34 fetch(url) 35 .then(function (r) { 36 return r.json(); 37 }) 38 .then(async function (d) { 39 if (d && d.token) { 40 if (!silent) input.value = d.token + "-loaded"; 41 let mined = 0; 42 let hash = ""; 43 let tokenWithMined = ""; 44 do { 45 tokenWithMined = d.token + "-" + mined++; 46 hash = await sha256Nested(tokenWithMined); 47 if (mined % 64 === 0) { 48 if (!silent) input.value = tokenWithMined + "-mining"; 49 // yield to browser to frevent GUI freeze 50 await new Promise(function (r) { setTimeout(r, 0); }); 51 } 52 } while (!hash.startsWith("00") && mined <= 10000000); 53 54 if (hash.startsWith("0")) { 55 input.value = tokenWithMined; 56 } else { 57 if (!silent) input.value = d.token + "failed"; 58 console.error("Proof of work failed: max attempts reached"); 59 } 60 } 61 }) 62 .catch(function (e) { 63 if (!silent) input.value = "ERR: " + e; 64 console.error(e); 65 }) 66 .finally(done); 67 } 68 69 function init() { 70 var inputs = document.querySelectorAll("input[data-token-url]"); 71 if (!inputs.length) { 72 return; 73 } 74 75 var pendingByForm = new Map(); 76 Array.prototype.forEach.call(inputs, function (input) { 77 var form = input.closest("form"); 78 if (!form) return; 79 pendingByForm.set(form, (pendingByForm.get(form) || 0) + 1); 80 form.classList.add("form-token-loading"); 81 }); 82 83 function done(input) { 84 var form = input.closest("form"); 85 if (!form) return; 86 var remaining = (pendingByForm.get(form) || 1) - 1; 87 if (remaining <= 0) { 88 pendingByForm.delete(form); 89 form.classList.remove("form-token-loading"); 90 } else { 91 pendingByForm.set(form, remaining); 92 } 93 } 94 95 setTimeout(function () { 96 Array.prototype.forEach.call(inputs, function (input) { 97 loadToken(input, function () { 98 done(input); 99 function scheduleReload() { 100 setTimeout(function () { 101 if (!input.isConnected) return; 102 loadToken(input, scheduleReload, true); 103 }, 10 * 60 * 1000); 104 } 105 scheduleReload(); 106 }); 107 }); 108 }, 1000); 109 } 110 111 if (document.readyState === "loading") { 112 document.addEventListener("DOMContentLoaded", init); 113 } else { 114 init(); 115 } 116})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.