Skip to content

Instantly share code, notes, and snippets.

@fodi
Last active September 10, 2024 10:30
Show Gist options
  • Save fodi/7383be96b95e97d3fff065c58d2d7e9c to your computer and use it in GitHub Desktop.
Save fodi/7383be96b95e97d3fff065c58d2d7e9c to your computer and use it in GitHub Desktop.
const startExport = () => {
console.info("Starting export...");
let pte_export = [];
document.querySelectorAll("#tetris tr").forEach((elRow) => {
let row = [];
elRow.querySelectorAll("td").forEach((elCell) => {
let borders = "";
borders += elCell?.style?.borderLeftColor === "rgb(0, 0, 0)" ? "L" : "";
borders += elCell?.style?.borderRightColor === "rgb(0, 0, 0)" ? "R" : "";
borders += elCell?.style?.borderTopColor === "rgb(0, 0, 0)" ? "T" : "";
borders += elCell?.style?.borderBottomColor === "rgb(0, 0, 0)" ? "B" : "";
row.push(borders);
});
pte_export.push(row);
});
console.log("Export is ready, dumping data...");
console.log(pte_export);
navigator.clipboard.writeText(JSON.stringify(pte_export));
//console.log(JSON.stringify(pte_export));
};
// rig go button
document.getElementById("go_button").addEventListener("click", () => {
console.info("Waiting for tiler...");
const waitInterval = setInterval(() => {
if(document.getElementById("pause_button")?.style?.display === "none") {
clearInterval(waitInterval);
startExport();
}
}, 200);
});
const exportButton = document.createElement("div");
exportButton.innerHTML = '<button type="button" onclick="startExport()">Export JSON</button>';
document.getElementById("go_button").after(exportButton.firstElementChild);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment