possibilité de reaload avec "entrée"

This commit is contained in:
Didictateur 2025-04-15 22:39:53 +02:00
parent 4c65bb0a65
commit 95706a42c2

View file

@ -142,32 +142,40 @@
document.body.appendChild(currentScript); document.body.appendChild(currentScript);
} }
function loadScript(scriptName, txt = true) { let lastLoadedScript = 'dp0.js';
if (window.cleanup) { let lastTextMode = true;
window.cleanup();
}
const container = document.getElementById("canvasContainer"); function loadScript(scriptName, txt = true) {
container.innerHTML = `<canvas id="myCanvas" width="1000" height="1000"></canvas>`; if (window.cleanup) {
window.cleanup();
}
const timestamp = new Date().getTime(); const container = document.getElementById("canvasContainer");
container.innerHTML = `<canvas id="myCanvas" width="1000" height="1000"></canvas>`;
currentScript = document.createElement("script"); const timestamp = new Date().getTime();
currentScript.type = "module";
currentScript.src = `build/${scriptName}?t=${timestamp}`;
document.body.appendChild(currentScript); currentScript = document.createElement("script");
currentScript.type = "module";
currentScript.src = `build/${scriptName}?t=${timestamp}`;
if (txt) { document.body.appendChild(currentScript);
const number = scriptName.substring(2, scriptName.length - 3);
loadText("txt" + number + ".js"); lastLoadedScript = scriptName;
} lastTextMode = txt;
if (txt) {
const number = scriptName.substring(2, scriptName.length - 3);
loadText("txt" + number + ".js");
}
} }
//tests document.addEventListener('keydown', function(event) {
loadScript('test.js', false); if (event.keyCode === 13 || event.key === 'Enter') {
loadScript(lastLoadedScript, lastTextMode);
}
});
//script initial
loadScript('dp0.js'); loadScript('dp0.js');
</script> </script>
</body> </body>