From ee955c9b79228ee7addbca4b58e6e8a2075cb472 Mon Sep 17 00:00:00 2001 From: gononono64 <96976330+gononono64@users.noreply.github.com> Date: Sat, 24 May 2025 18:31:36 -0500 Subject: [PATCH] copy to clipboard enhancement If clipboard is a table it converts the json string to lua table format --- web/dist/index.html | 30 +++++++++++------------------- web/index.html | 28 ++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/web/dist/index.html b/web/dist/index.html index e6532bf..b6a3bd9 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -15,22 +15,8 @@ function isTableJSON(jsonString) { try { - const parsed = JSON.parse(jsonString); - if (!Array.isArray(parsed)) { - return false; - } - if (parsed.length > 0) { - const firstKeys = Object.keys(parsed[0]); - for (let i = 0; i < parsed.length; i++) { - if (typeof parsed[i] !== 'object' || parsed[i] === null || Array.isArray(parsed[i])) { - return false; - } - if (Object.keys(parsed[i]).length !== firstKeys.length || !Object.keys(parsed[i]).every(key => firstKeys.includes(key))) { - return false - } - } - } - return true; + const parsed = JSON.parse(jsonString); + return parsed; } catch (e) { return false; } @@ -47,9 +33,15 @@ window.addEventListener("message", (event) => { if (event?.data?.type === "copytoclipboard") { var str = event.data.text; - // if (isTableJSON(str)) { - // str = JSON.stringify(JSON.parse(str), null, 2); - // } + // str = JSON.parse(str); + if (isTableJSON(str)) { + str = str.replace(/\[/g, '{'); + str = str.replace(/\]/g, '}'); + // replace : with = + str = str.replace(/:/g, '='); + // I need all indexes with quotes to be replaced with nothing but not affect any string values + str = str.replace(/"([^"]+)"=/g, '$1='); + } copyToClipboard(str); } diff --git a/web/index.html b/web/index.html index f29c970..d427a2b 100644 --- a/web/index.html +++ b/web/index.html @@ -9,12 +9,21 @@
-