Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (46 loc) · 1.38 KB
/
Copy pathscript.js
File metadata and controls
54 lines (46 loc) · 1.38 KB
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
45
46
47
48
49
50
51
52
53
const dataInput = document.getElementById("dataInput");
const posInputs = [
document.getElementById("x"),
document.getElementById("y"),
document.getElementById("z")
];
const output = document.getElementById("output");
const copyButton = document.getElementById("copyButton");
let baseData = [];
let shift = [0, 0, 0];
let data = [];
dataInput.addEventListener("input", () => {
if (/[0-9a-f]{24}$/.test(dataInput.value)) {
fetch(`https://cdn.dashcraft.io/v2/prod/track/${dataInput.value.slice(-24)}.json`)
.then(response => response.json())
.then(json => {
baseData = json.trackPieces;
updateData();
});
} else {
try {
baseData = JSON.parse(dataInput.value);
updateData();
} catch {
return;
}
}
});
for (let i = 0; i < posInputs.length; i++) {
posInputs[i].addEventListener("input", () => {
shift[i] = parseInt(posInputs[i].value) || 0;
updateData();
});
}
function updateData() {
data = [];
for (let i = 0; i < baseData.length; i++) {
let item = structuredClone(baseData[i]);
item.p = item.p.map((p, j) => p + shift[j]);
data.push(item);
}
output.innerText = JSON.stringify(data);
}
copyButton.addEventListener("click", () => {
navigator.clipboard.writeText(output.innerText);
});