Merge branch 'master' of git.inpt.fr:tocard-inc/enseeiht/projet-web

This commit is contained in:
Laureηt 2022-05-13 13:36:41 +02:00
commit 54d679bc97
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
2 changed files with 33 additions and 1 deletions

View file

@ -83,7 +83,7 @@
</div> </div>
</div> </div>
<div class="pixel-container"> <div class="pixel-container">
<table> <table id="pixelTable">
<tr> <tr>
<td class="pixel" id="r0c0"> <td class="pixel" id="r0c0">
<div class="info-pixel"> <div class="info-pixel">
@ -806,6 +806,7 @@
</tr> </tr>
</table> </table>
</div> </div>
<script type="text/javascript" src="pixels.js"></script>
</body> </body>
</html> </html>

31
src/front/pixels.js Normal file
View file

@ -0,0 +1,31 @@
debugger;
function readTextFile(file)
{
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var allText = rawFile.responseText;
alert(allText);
}
}
}
rawFile.send(null);
}
// fetch("https://URL/file").then((r)=>{r.text().then((d)=>{let json = d})})
const json = readTextFile("test.json");
const obj = JSON.parse(json);
var table = document.getElementById("pixelTable");
var num_columns = table.rows[0].cells.length;
for (pixel in obj) {
var cell = table.rows[Math.floor(pixel.id / num_columns)].cells[pixel.id % num_columns];
cell.style.background = "#f00";
}