From 95706a42c259f641842cdffc8da64ea292db75e9 Mon Sep 17 00:00:00 2001 From: Didictateur Date: Tue, 15 Apr 2025 22:39:53 +0200 Subject: [PATCH] =?UTF-8?q?possibilit=C3=A9=20de=20reaload=20avec=20"entr?= =?UTF-8?q?=C3=A9e"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index ad64589..b2b5952 100644 --- a/index.html +++ b/index.html @@ -141,33 +141,41 @@ document.body.appendChild(currentScript); } + + let lastLoadedScript = 'dp0.js'; + let lastTextMode = true; - function loadScript(scriptName, txt = true) { - if (window.cleanup) { - window.cleanup(); - } + function loadScript(scriptName, txt = true) { + if (window.cleanup) { + window.cleanup(); + } - const container = document.getElementById("canvasContainer"); - container.innerHTML = ``; + const container = document.getElementById("canvasContainer"); + container.innerHTML = ``; - const timestamp = new Date().getTime(); + const timestamp = new Date().getTime(); - currentScript = document.createElement("script"); - currentScript.type = "module"; - currentScript.src = `build/${scriptName}?t=${timestamp}`; + currentScript = document.createElement("script"); + currentScript.type = "module"; + currentScript.src = `build/${scriptName}?t=${timestamp}`; - document.body.appendChild(currentScript); + document.body.appendChild(currentScript); + + lastLoadedScript = scriptName; + lastTextMode = txt; - if (txt) { - const number = scriptName.substring(2, scriptName.length - 3); - loadText("txt" + number + ".js"); - } + if (txt) { + const number = scriptName.substring(2, scriptName.length - 3); + loadText("txt" + number + ".js"); + } } - - //tests - loadScript('test.js', false); - //script initial + document.addEventListener('keydown', function(event) { + if (event.keyCode === 13 || event.key === 'Enter') { + loadScript(lastLoadedScript, lastTextMode); + } + }); + loadScript('dp0.js');