From 4dd1cf209b27d420999e4cf9d1e9804c7fc1bca5 Mon Sep 17 00:00:00 2001 From: Raine Date: Sun, 24 Dec 2023 03:17:39 +0100 Subject: [PATCH] fix: locale bug; didn't reverse on remove --- modules/copy.js | 2 ++ modules/locale.js | 6 +++--- test.html | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/copy.js b/modules/copy.js index 83526da..c4514cb 100644 --- a/modules/copy.js +++ b/modules/copy.js @@ -1,6 +1,8 @@ // [x-copy-query=""] // [x-inner-text] - will use innerText (() => { + + // TODO: make copy work with checksums because not uuid will not always cut it. function updateCopy() { document.querySelectorAll("[x-copy-query]:not([x1-copy-uuid])") .forEach(e => { diff --git a/modules/locale.js b/modules/locale.js index 238be21..43fc5b2 100644 --- a/modules/locale.js +++ b/modules/locale.js @@ -11,9 +11,9 @@ function updateLocale() { document.querySelectorAll("[x-locale-key]:not([x1-locale-uuid])") .forEach(e => { - let uuid = new Date().getTime().toString(36); + let uuid = (Math.random() + new Date().getTime()).toString(36); e.setAttribute("x1-locale-uuid", uuid); - backupElements[uuid] = e.cloneNode(); + backupElements[uuid] = e.outerHTML; e.innerHTML = getValueFromPath(locale, e.getAttribute("x-locale-key")); }) } @@ -28,7 +28,7 @@ window.x0?.registerModuleRemoveHook("locale", (s) => { Object.keys(s) .forEach(uuid => { - document.querySelector(`[x1-locale-uuid="${uuid}"]`).outerHTML = s[uuid].outerHTML; + document.querySelector(`[x1-locale-uuid="${uuid}"]`).outerHTML = s[uuid]; }) }) })() \ No newline at end of file diff --git a/test.html b/test.html index 7982a4b..dc6a44c 100644 --- a/test.html +++ b/test.html @@ -7,7 +7,10 @@ > - + + + +

@@ -19,9 +22,8 @@

-
+        
     
-