|
1 | 1 |
|
2 | 2 |
|
| 3 | +document.addEventListener('DOMContentLoaded', function () { |
| 4 | + // get key from search params |
| 5 | + var urlParams = new URLSearchParams(window.location.search); |
| 6 | + var key = urlParams.get('key'); |
| 7 | + var last = urlParams.get('last'); |
| 8 | + if (!last) |
| 9 | + last = 1; |
| 10 | + setValue(last); |
3 | 11 |
|
4 | | -// get key from search params |
5 | | -var urlParams = new URLSearchParams(window.location.search); |
6 | | -var key = urlParams.get('key'); |
7 | | -var last = urlParams.get('last'); |
8 | | -if (!last) |
9 | | - last = 1; |
10 | | -setValue(last); |
| 12 | + var minKey = ''; |
| 13 | + var maxKey = ''; |
| 14 | + for (var i = 0; i < 128; i++) { |
| 15 | + minKey += "0"; |
| 16 | + maxKey += "f"; |
| 17 | + } |
| 18 | + if (key == null) { |
| 19 | + key = minKey; |
| 20 | + } |
| 21 | + else { |
| 22 | + key = key.replace(/[^a-f0-9]/gi, ''); |
11 | 23 |
|
12 | | -var minKey = ''; |
13 | | -var maxKey = ''; |
14 | | -for (var i = 0; i < 128; i++) { |
15 | | - minKey += "0"; |
16 | | - maxKey += "f"; |
17 | | -} |
18 | | -if (key == null) { |
19 | | - key = minKey; |
20 | | -} |
21 | | -else { |
22 | | - key = key.replace(/[^a-f0-9]/gi, ''); |
| 24 | + key = key.padStart(128, '0'); |
| 25 | + } |
23 | 26 |
|
24 | | - key = key.padStart(128, '0'); |
25 | | -} |
| 27 | + document.getElementById('sprite-id').value = key; |
26 | 28 |
|
27 | 29 |
|
28 | | -function getRandom() { |
29 | | - // make a random 128-digit hex number |
30 | | - var r = ""; |
31 | | - for (var i = 0; i < 128; i++) { |
32 | | - r += Math.floor(Math.random() * 16).toString(16); |
| 30 | + |
| 31 | + |
| 32 | + function getRandom() { |
| 33 | + // make a random 128-digit hex number |
| 34 | + var r = ""; |
| 35 | + for (var i = 0; i < 128; i++) { |
| 36 | + r += Math.floor(Math.random() * 16).toString(16); |
| 37 | + } |
| 38 | + return r; |
33 | 39 | } |
34 | | - return r; |
35 | | -} |
36 | | -var uniqueID = BigInt('0x' + key).toString(36); |
| 40 | + var uniqueID = BigInt('0x' + key).toString(36); |
37 | 41 |
|
38 | | -function setValue(Value) { |
39 | | - document.getElementById("numAdjust").value = Value; |
40 | | -} |
| 42 | + function setValue(Value) { |
| 43 | + document.getElementById("numAdjust").value = Value; |
| 44 | + } |
41 | 45 |
|
42 | | -document.getElementById("btnRand").setAttribute("href", "?key=" + getRandom()); |
43 | | -document.getElementById("btnMinus").onclick = function () { |
| 46 | + document.getElementById("btnRand").setAttribute("href", "?key=" + getRandom()); |
| 47 | + document.getElementById("btnMinus").onclick = function () { |
44 | 48 |
|
45 | | - var numAdjust = parseInt(document.getElementById("numAdjust").value); |
46 | | - var numKey = BigInt("0x" + key); |
47 | | - numKey -= BigInt(numAdjust); |
48 | | - if (numKey < BigInt("0x" + minKey)) { |
49 | | - numKey += maxKey; |
| 49 | + var numAdjust = parseInt(document.getElementById("numAdjust").value); |
| 50 | + var numKey = BigInt("0x" + key); |
| 51 | + numKey -= BigInt(numAdjust); |
| 52 | + if (numKey < BigInt("0x" + minKey)) { |
| 53 | + numKey += maxKey; |
| 54 | + } |
| 55 | + key = numKey.toString(16); |
| 56 | + window.location.href = "?key=" + key.padStart(128, '0') + "&last=" + numAdjust; |
50 | 57 | } |
51 | | - key = numKey.toString(16); |
52 | | - window.location.href = "?key=" + key.padStart(128, '0') + "&last=" + numAdjust; |
53 | | -} |
54 | | -document.getElementById("btnPlus").onclick = function () { |
| 58 | + document.getElementById("btnPlus").onclick = function () { |
55 | 59 |
|
56 | | - var numAdjust = parseInt(document.getElementById("numAdjust").value); |
57 | | - var numKey = BigInt("0x" + key); |
58 | | - numKey += BigInt(numAdjust); |
59 | | - if (numKey > BigInt("0x" + maxKey)) { |
60 | | - numKey -= maxKey; |
| 60 | + var numAdjust = parseInt(document.getElementById("numAdjust").value); |
| 61 | + var numKey = BigInt("0x" + key); |
| 62 | + numKey += BigInt(numAdjust); |
| 63 | + if (numKey > BigInt("0x" + maxKey)) { |
| 64 | + numKey -= maxKey; |
| 65 | + } |
| 66 | + key = numKey.toString(16); |
| 67 | + window.location.href = "?key=" + key.padStart(128, '0') + "&last=" + numAdjust; |
61 | 68 | } |
62 | | - key = numKey.toString(16); |
63 | | - window.location.href = "?key=" + key.padStart(128, '0') + "&last=" + numAdjust; |
64 | | -} |
| 69 | + |
| 70 | + |
| 71 | +}); |
0 commit comments